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
014f5741
Commit
014f5741
authored
10 months ago
by
Pushkaraj Sane
Browse files
Options
Downloads
Patches
Plain Diff
redis authentication. added username functionality in cache_redis.go
parent
5c31ae9e
Branches
Branches containing commit
No related merge requests found
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 @
014f5741
...
@@ -40,16 +40,18 @@ type RedisCache struct {
...
@@ -40,16 +40,18 @@ type RedisCache struct {
addPrefix
bool
//
addPrefix
bool
//
connected
bool
// will be enabled if redis client connects to server
connected
bool
// will be enabled if redis client connects to server
Addr
string
// redis server address, default "127.0.0.1:6379"
Addr
string
// redis server address, default "127.0.0.1:6379"
DB
int
// redis DB on provided server, default 0
DB
int
// redis DB on provided server, default 0
Username
string
Password
string
//
Password
string
//
Expiration
time
.
Duration
// this duration will be used for Set() method
Expiration
time
.
Duration
// this duration will be used for Set() method
Prefix
string
// this will be used for storing keys for provided project
Prefix
string
// this will be used for storing keys for provided project
}
}
type
configRedis
struct
{
type
configRedis
struct
{
addr
string
// redis server address, default "127.0.0.1:6379"
addr
string
// redis server address, default "127.0.0.1:6379"
db
int
// redis DB on provided server, default 0
db
int
// redis DB on provided server, default 0
username
string
password
string
//
password
string
//
expiration
time
.
Duration
// this duration will be used for Set() method
expiration
time
.
Duration
// this duration will be used for Set() method
prefix
string
// this will be used for storing keys for provided project
prefix
string
// this will be used for storing keys for provided project
...
@@ -82,9 +84,14 @@ func RedisWithExpiration(exp time.Duration) redisOption {
...
@@ -82,9 +84,14 @@ func RedisWithExpiration(exp time.Duration) redisOption {
cfg
.
expiration
=
exp
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.
// 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
{
if
rc
==
nil
{
rc
=
new
(
RedisCache
)
rc
=
new
(
RedisCache
)
...
@@ -92,6 +99,7 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
...
@@ -92,6 +99,7 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
rc
.
Addr
=
addr
rc
.
Addr
=
addr
rc
.
Password
=
password
rc
.
Password
=
password
rc
.
Username
=
username
rc
.
DB
=
db
rc
.
DB
=
db
rc
.
Expiration
=
exp
rc
.
Expiration
=
exp
rc
.
Prefix
=
prefix
rc
.
Prefix
=
prefix
...
@@ -99,6 +107,7 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
...
@@ -99,6 +107,7 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
Addr
:
addr
,
Addr
:
addr
,
Password
:
password
,
Password
:
password
,
DB
:
db
,
DB
:
db
,
Username
:
username
,
}
}
rc
.
opt
=
&
opt
rc
.
opt
=
&
opt
...
@@ -132,6 +141,7 @@ func SetupRedisCache(opts ...redisOption) (*RedisCache, error) {
...
@@ -132,6 +141,7 @@ func SetupRedisCache(opts ...redisOption) (*RedisCache, error) {
rc
.
Addr
=
cfg
.
addr
rc
.
Addr
=
cfg
.
addr
rc
.
Password
=
cfg
.
password
rc
.
Password
=
cfg
.
password
rc
.
Username
=
cfg
.
username
rc
.
DB
=
cfg
.
db
rc
.
DB
=
cfg
.
db
rc
.
Expiration
=
cfg
.
expiration
rc
.
Expiration
=
cfg
.
expiration
rc
.
Prefix
=
cfg
.
prefix
rc
.
Prefix
=
cfg
.
prefix
...
@@ -140,6 +150,7 @@ func SetupRedisCache(opts ...redisOption) (*RedisCache, error) {
...
@@ -140,6 +150,7 @@ func SetupRedisCache(opts ...redisOption) (*RedisCache, error) {
Addr
:
cfg
.
addr
,
Addr
:
cfg
.
addr
,
Password
:
cfg
.
password
,
Password
:
cfg
.
password
,
DB
:
cfg
.
db
,
DB
:
cfg
.
db
,
Username
:
cfg
.
username
,
}
}
rc
.
cli
=
redis
.
NewClient
(
rc
.
opt
)
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