/
red.go
90 lines (72 loc) · 1.41 KB
/
red.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package red
import (
"math"
"time"
"github.com/alxarch/red/resp"
)
// MaxDBIndex is the max db index allowed by redis.
const MaxDBIndex = 16
// DBIndexValid checks if a DBIndex is valid
func DBIndexValid(index int) bool {
return 0 <= index && index < MaxDBIndex
}
// KeepTTL sets the SET command's KEEPTTL flag in redis 6
const KeepTTL time.Duration = math.MinInt64
// StatusOK is the default success status
const StatusOK = resp.SimpleString("OK")
// StatusQueued is the status of a command in a MULTI/EXEC transaction
const StatusQueued = resp.SimpleString("QUEUED")
type noCopy struct{} //nolint:unused
func (*noCopy) Lock() {}
func (*noCopy) Unlock() {}
// Mode defines command modes NX/XX
type Mode uint
// Execution modes
const (
_ Mode = iota << 1
NX
XX
CH
INCR
EX
PX
// MK
)
// XX checks if mode is XX
func (m Mode) XX() bool {
return m&XX == XX
}
// NX checks if mode is NX
func (m Mode) NX() bool {
return m&NX == NX
}
// INCR checks if mode is INCR
func (m Mode) INCR() bool {
return m&INCR == INCR
}
// CH checks if mode is CH
func (m Mode) CH() bool {
return m&CH == CH
}
// EX checks if mode is EX
func (m Mode) EX() bool {
return m&EX == EX
}
// PX checks if mode is PX
func (m Mode) PX() bool {
return m&PX == PX
}
func (m Mode) String() string {
switch m {
case NX:
return "NX"
case XX:
return "XX"
case CH:
return "CH"
case INCR:
return "INCR"
default:
return ""
}
}