/
redis.go
42 lines (33 loc) · 802 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
package redis
import (
"time"
rs "github.com/go-redis/redis"
)
// Redis deals with Redis data stuff
type Redis interface {
Get(key string) (string, error)
Del(key string) error
Set(key string, value interface{}, expiration time.Duration) error
Close() error
}
type redis struct {
client *rs.Client
}
func (r *redis) Get(key string) (string, error) {
return r.client.Get(key).Result()
}
func (r *redis) Set(key string, value interface{}, expiration time.Duration) error {
return r.client.Set(key, value, expiration).Err()
}
func (r *redis) Del(key string) error {
return r.client.Del(key).Err()
}
func (r *redis) Close() error {
return r.client.Close()
}
// New creates an instance of Redis
func New(options *rs.Options) Redis {
return &redis{
client: rs.NewClient(options),
}
}