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
4e0bc266
Commit
4e0bc266
authored
4 years ago
by
Akshay Bharambe
Browse files
Options
Downloads
Patches
Plain Diff
Add: GetAll for redis cache
parent
aae0de39
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!210
Staging mepdeployment05072020
,
!206
Add: Enable users to view data present in session manager
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cachemdl/cache_redis.go
+29
-0
cachemdl/cache_redis.go
cachemdl/cache_redis_test.go
+33
-0
cachemdl/cache_redis_test.go
with
62 additions
and
0 deletions
cachemdl/cache_redis.go
+
29
−
0
View file @
4e0bc266
...
...
@@ -284,3 +284,32 @@ func (rc *RedisCache) key(key string) string {
func
(
rc
*
RedisCache
)
Type
()
int
{
return
TypeRedisCache
}
// GetAll returns all keys with values present in redis server. Excludes the keys which does not have specified prefix. If prefix is empty, then returns all keys.
//
// **This is not intended for production use. May hamper performance**
func
(
rc
*
RedisCache
)
GetAll
()
map
[
string
]
interface
{}
{
pattern
:=
rc
.
Prefix
+
"*"
keys
,
err
:=
rc
.
cli
.
Keys
(
pattern
)
.
Result
()
if
err
!=
nil
{
loggermdl
.
LogError
(
"error getting keys for "
,
pattern
,
" error: "
,
err
)
return
nil
}
result
:=
make
(
map
[
string
]
interface
{},
len
(
keys
))
for
i
:=
range
keys
{
ba
,
err
:=
rc
.
cli
.
Get
(
keys
[
i
])
.
Bytes
()
if
err
!=
nil
{
loggermdl
.
LogError
(
"error getting key"
,
keys
[
i
],
"from redis cache with error:"
,
err
)
continue
}
var
val
interface
{}
_
=
json
.
Unmarshal
(
ba
,
&
val
)
// accessing [1] won't panic as we have all keys with matching regex
result
[
strings
.
Split
(
keys
[
i
],
keySplitter
)[
1
]]
=
val
}
return
result
}
This diff is collapsed.
Click to expand it.
cachemdl/cache_redis_test.go
+
33
−
0
View file @
4e0bc266
...
...
@@ -405,3 +405,36 @@ func BenchmarkMarshalWithTypeCheckStruct(b *testing.B) {
_
,
_
=
marshalWithTypeCheck
(
s
)
}
}
func
TestRedisCache_GetAll
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
rc
*
RedisCache
want
map
[
string
]
interface
{}
init
func
(
rc
*
RedisCache
)
}{
{
name
:
"Get All Items"
,
rc
:
&
RedisCache
{},
want
:
map
[
string
]
interface
{}{
"a"
:
1.24
,
"b"
:
1.25
,
},
init
:
func
(
rc
*
RedisCache
)
{
rc
.
Setup
(
"127.0.0.1:6379"
,
""
,
"tests"
,
0
,
time
.
Second
*
60
)
rc
.
flushDB
()
rc
.
Set
(
"a"
,
1.24
)
rc
.
Set
(
"b"
,
1.25
)
},
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
tt
.
init
(
tt
.
rc
)
if
got
:=
tt
.
rc
.
GetAll
();
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"RedisCache.GetAll() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
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