-
Notifications
You must be signed in to change notification settings - Fork 3
/
redis.go
42 lines (34 loc) · 869 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 cache
import (
"time"
"github.com/go-redis/redis"
)
type Redis struct {
Client *redis.Client
}
func NewRedis(options *redis.Options) *Redis {
var _options *redis.Options
if options != nil {
_options = options
} else {
_options = &redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
}
}
client := redis.NewClient(_options)
return &Redis{client}
}
func (self *Redis) Get(key string) ([]byte, error) {
return self.Client.Get(key).Bytes()
}
func (self *Redis) Set(key string, value string, expire time.Duration) error {
return self.Client.Set(key, value, expire).Err()
}
func (self *Redis) Remove(key string) error {
return self.Client.Del(key).Err()
}
func (self *Redis) Update(key string, value string, expire time.Duration) error {
return self.Set(key, value, expire)
}