forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redisutils.go
45 lines (36 loc) · 848 Bytes
/
redisutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package common
import (
"encoding/json"
"github.com/mediocregopher/radix/v3"
)
// GetRedisJson executes a get redis command and unmarshals the value into out
func GetRedisJson(key string, out interface{}) error {
var resp []byte
err := RedisPool.Do(radix.Cmd(&resp, "GET", key))
if err != nil {
return err
}
if len(resp) == 0 {
return nil
}
err = json.Unmarshal(resp, out)
return err
}
// SetRedisJson marshals the value and runs a set redis command for key
func SetRedisJson(key string, value interface{}) error {
serialized, err := json.Marshal(value)
if err != nil {
return err
}
err = RedisPool.Do(radix.Cmd(nil, "SET", key, string(serialized)))
return err
}
func MultipleCmds(cmds ...radix.CmdAction) error {
for _, v := range cmds {
err := RedisPool.Do(v)
if err != nil {
return err
}
}
return nil
}