Commit 91aaac14 authored by Pushkaraj Sane's avatar Pushkaraj Sane
Browse files

authentication for redis added

parent 0f15c531
Branches ps_redisOtpAndAuth
Tags
4 merge requests!302merge devbranch into staging,!299Devbranch,!296merge devbranch to staging.,!295#31 Authentication functionality for redis & functionality to store and retreive otp from respective cache.
Showing with 16 additions and 5 deletions
......@@ -40,16 +40,18 @@ type RedisCache struct {
addPrefix bool //
connected bool // will be enabled if redis client connects to server
Addr string // redis server address, default "127.0.0.1:6379"
DB int // redis DB on provided server, default 0
Addr string // redis server address, default "127.0.0.1:6379"
DB int // redis DB on provided server, default 0
Username string
Password string //
Expiration time.Duration // this duration will be used for Set() method
Prefix string // this will be used for storing keys for provided project
}
type configRedis struct {
addr string // redis server address, default "127.0.0.1:6379"
db int // redis DB on provided server, default 0
addr string // redis server address, default "127.0.0.1:6379"
db int // redis DB on provided server, default 0
username string
password string //
expiration time.Duration // this duration will be used for Set() method
prefix string // this will be used for storing keys for provided project
......@@ -82,9 +84,14 @@ func RedisWithExpiration(exp time.Duration) redisOption {
cfg.expiration = exp
}
}
func RedisWithUsername(username string) redisOption {
return func(cfg *configRedis) {
cfg.username = username
}
}
// Setup initializes redis cache for application. Must be called only once.
func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Duration) {
func (rc *RedisCache) Setup(addr, username, password, prefix string, db int, exp time.Duration) {
if rc == nil {
rc = new(RedisCache)
......@@ -92,6 +99,7 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
rc.Addr = addr
rc.Password = password
rc.Username = username
rc.DB = db
rc.Expiration = exp
rc.Prefix = prefix
......@@ -99,6 +107,7 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
Addr: addr,
Password: password,
DB: db,
Username: username,
}
rc.opt = &opt
......@@ -132,6 +141,7 @@ func SetupRedisCache(opts ...redisOption) (*RedisCache, error) {
rc.Addr = cfg.addr
rc.Password = cfg.password
rc.Username = cfg.username
rc.DB = cfg.db
rc.Expiration = cfg.expiration
rc.Prefix = cfg.prefix
......@@ -140,6 +150,7 @@ func SetupRedisCache(opts ...redisOption) (*RedisCache, error) {
Addr: cfg.addr,
Password: cfg.password,
DB: cfg.db,
Username: cfg.username,
}
rc.cli = redis.NewClient(rc.opt)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment