-
Notifications
You must be signed in to change notification settings - Fork 0
Redis Repository
samithiwat edited this page Feb 13, 2023
·
2 revisions
Redis repository is the repository interface for using redis work on-top of go-redis
Redis repository can be initialized by NewRedisRepository method
repo := gosdk.NewRedisRepository(*RedisClient)
name | description |
---|---|
Redis Client | the client of the redis for calling an API |
name | description | example |
---|---|---|
repo | the redis repository instance |
if err := repo.SaveCache(key, value, ttl); err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"key" |
value | value of cache (any type) | "value", 1, &struct{}{} |
ttl | expiration time of cache | 3600 |
if err := repo.SaveHashCache(key, field, value, ttl); err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"user" |
field | field of hash cache (must be string ) |
"name" |
value | value of hash cache (must be string ) |
"alice" |
ttl | expiration time of cache | 3600 |
if err := repo.SaveAllHashCache(key, value, ttl); err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"user" |
value | map of hash cache (must be map[string]string ) |
map[string]string{"name": "alice"} |
ttl | expiration time of cache | 3600 |
type User struct{
name string
}
result := User{}
if err := repo.GetCache(key, &result); err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"user" |
result | the result point struct{} for receive the cache |
value ,err := repo.GetHashCache(key, field)
if err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"user" |
field | field of hash cache (must be string ) |
"name" |
name | description | example |
---|---|---|
value | value of cache in string
|
"alice" |
values ,err := repo.GetAllHashCache(key, field)
if err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"user" |
field | field of hash cache (must be string ) |
"name" |
name | description | example |
---|---|---|
values | values of cache in map[string]string
|
map[string]string{"name":"alice"} |
if err := repo.RemoveCache(key); err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"key" |
if err := repo.SetExpire(key, ttl); err != nil{
// handle error
}
name | description | example |
---|---|---|
key | key of cache (must be string ) |
"key" |
ttl | expiration time of cache | 3600 |