-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_string.go
More file actions
41 lines (32 loc) · 924 Bytes
/
client_string.go
File metadata and controls
41 lines (32 loc) · 924 Bytes
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
package redis
import (
`context`
`github.com/go-redis/redis/v8`
)
func (c *Client) Set(ctx context.Context, key string, value interface{}, opts ...putOption) (err error) {
_options := defaultPutOptions()
for _, opt := range opts {
opt.applyPut(_options)
}
if value, err = c.marshal(value, _options.label, _options.serializer); nil != err {
return
}
err = c.getClient(_options.options).Set(ctx, key, value, _options.expiration).Err()
return
}
func (c *Client) Get(ctx context.Context, key string, value interface{}, opts ...option) (exist bool, err error) {
_options := defaultOptions()
for _, opt := range opts {
opt.apply(_options)
}
var cmd *redis.StringCmd
defer func() {
exist = redis.Nil != cmd.Err()
}()
if cmd = c.getClient(_options).Get(ctx, key); nil != cmd.Err() {
err = cmd.Err()
} else {
err = c.unmarshal(cmd.Val(), value, _options.label, _options.serializer)
}
return
}