-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis.go
45 lines (36 loc) · 918 Bytes
/
redis.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 main
import (
"context"
"time"
"github.com/go-redis/redis/v8"
"github.com/rabbull/dsf"
)
type GoRedisClient struct {
Ctx context.Context
Client *redis.Client
}
func (c *GoRedisClient) Context(ctx context.Context) dsf.RedisClient {
c.Ctx = ctx
return c
}
func (c *GoRedisClient) Nil() interface{} {
return redis.Nil
}
func (c *GoRedisClient) Get(key string) ([]byte, error) {
value, err := c.Client.Get(c.Ctx, key).Result()
if err != nil {
return nil, err
}
return []byte(value), nil
}
func (c *GoRedisClient) Set(key string, value []byte, exp time.Duration) error {
return c.Client.Set(c.Ctx, key, string(value), exp).Err()
}
func (c *GoRedisClient) Del(key string) error {
return c.Client.Del(c.Ctx, key).Err()
}
func (c *GoRedisClient) Eval(
script string, keys []string, args ...interface{},
) (interface{}, error) {
return c.Client.Eval(c.Ctx, script, keys, args).Result()
}