blob: de207a53e3e55591a2cee69d76643b20d882bf34 (
plain) (
blame)
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 storage
import "github.com/go-redis/redis/v7"
var _ CHR = &Redis{}
// Redis storage engine
type Redis redis.Client
// Create an entry in redis
func (r *Redis) Create(key, value string, checkcollision bool) error {
if !r.Healthy() {
return Unhealthy
}
if checkcollision {
col, err := r.Exists(key).Result()
if err != nil {
return Unhealthy
}
if col > 0 {
return Collision
}
}
_, err := r.Set(key, value, 0).Result()
return err
}
func (r *Redis) Read(key string) (string, error) {
if !r.Healthy() {
return "", Unhealthy
}
return r.Get(key).Result()
}
// Healthy determines whether redis is responding to pings
func (r *Redis) Healthy() bool {
_, err := r.Ping().Result()
if err != nil {
return false
}
return true
}
|