Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
91aaac14
Commit
91aaac14
authored
5 months ago
by
Pushkaraj Sane
Browse files
Options
Downloads
Patches
Plain Diff
authentication for redis added
parent
0f15c531
Branches
ps_redisOtpAndAuth
Branches containing commit
Tags
Tags containing commit
4 merge requests
!302
merge devbranch into staging
,
!299
Devbranch
,
!296
merge devbranch to staging.
,
!295
#31 Authentication functionality for redis & functionality to store and retreive otp from respective cache.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cachemdl/cache_redis.go
+16
-5
cachemdl/cache_redis.go
with
16 additions
and
5 deletions
cachemdl/cache_redis.go
+
16
−
5
View file @
91aaac14
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets