-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.go
74 lines (69 loc) · 2.79 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package redis
//go:generate mockgen -source=redis.go -destination=mock/redis_mock.go -package redismock
import (
"context"
"errors"
)
// error list
var (
ErrResponseNotOK = errors.New("redis: response is not ok")
)
// Redis interface
type Redis interface {
Close() error
IsErrNil(err error) bool
IsResponseOK(result string) bool
Set(ctx context.Context, key string, value interface{}) (string, error)
SetNX(ctx context.Context, key string, value interface{}, expire int) (int, error)
SetEX(ctx context.Context, key string, value interface{}, expire int) (string, error)
Get(ctx context.Context, key string) (string, error)
Delete(ctx context.Context, key string) (int, error)
Increment(ctx context.Context, key string) (int, error)
IncrementBy(ctx context.Context, key string, amount int) (int, error)
Expire(ctx context.Context, key string, duration int) (int, error)
MSet(ctx context.Context, pairs ...interface{}) (string, error)
MGet(ctx context.Context, keys ...string) ([]string, error)
HSet(ctx context.Context, key, field string, value interface{}) (int, error)
HSetEX(ctx context.Context, key, field string, value interface{}, expire int) (int, error)
HGet(ctx context.Context, key, field string) (string, error)
HGetAll(ctx context.Context, key string) (map[string]string, error)
HMSet(ctx context.Context, key string, kv map[string]interface{}) (string, error)
HMGet(ctx context.Context, key string, fields ...string) ([]string, error)
HDel(ctx context.Context, key string, fields ...string) (int, error)
LLen(ctx context.Context, key string) (int, error)
LIndex(ctx context.Context, key string, index int) (string, error)
LSet(ctx context.Context, key, value string, index int) (int, error)
LPush(ctx context.Context, key string, values ...interface{}) (int, error)
LPushX(ctx context.Context, key string, values ...interface{}) (int, error)
LPop(ctx context.Context, key string) (string, error)
LRem(ctx context.Context, key, value string, count int) (int, error)
LTrim(ctd context.Context, key string, start, stop int) (string, error)
}
// list of redis command
const (
CommandPing = "PING"
CommandExpire = "EXPIRE"
CommandSet = "SET"
CommandGet = "GET"
CommandDelete = "DEL"
CommandIncrement = "INCR"
CommandIncrementBy = "INCRBY"
CommandSetNX = "SETNX"
CommandSetEX = "SETEX"
CommandMSet = "MSET"
CommandMGet = "MGET"
CommandHSet = "HSET"
CommandHGet = "HGET"
CommandHGetAll = "HGETALL"
CommandHMSet = "HMSET"
CommandHMGet = "HMGET"
CommandHDel = "HDEL"
CommandLLen = "LLEN"
CommandLIndex = "LINDEX"
CommandLSET = "LSET"
CommandLPush = "LPUSH"
CommandLPushX = "LPUSHX"
CommandLPop = "LPOP"
CommandLRem = "LREM"
CommandLTrim = "LTRIM"
)