-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis.go
48 lines (40 loc) · 1.01 KB
/
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
46
47
48
package main
import (
"time"
"github.com/garyburd/redigo/redis"
)
func newPoolFromURL(URL string, maxActive int) *redis.Pool {
return &redis.Pool{
MaxActive: maxActive,
MaxIdle: maxActive,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) { return redis.DialURL(URL) },
}
}
type redisSummary struct {
Version string
Keys int
OpsPerSecond int
UsedMemoryHuman string
}
func fetchSummary(c redis.Conn) (*redisSummary, error) {
return &redisSummary{}, nil
}
func dumpKey(c redis.Conn, key string) (*redisKey, error) {
value, err := redis.String(c.Do("DUMP", key))
if err != nil {
return nil, err
}
return &redisKey{key, value, 0}, nil
}
func restoreKey(c redis.Conn, rk *redisKey, replace bool) error {
if replace {
_, err := c.Do("RESTORE", rk.Key, rk.TTL, rk.Value, "REPLACE")
return err
}
_, err := c.Do("RESTORE", rk.Key, rk.TTL, rk.Value)
return err
}
func getTTL(c redis.Conn, key string) (int, error) {
return redis.Int(c.Do("PTTL", key))
}