forked from ssdb/gossdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmd_hash.go
179 lines (145 loc) · 6.24 KB
/
cmd_hash.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package ssdb
// HSet Set the string value in argument as value of the key of a hashmap.
func (c *Client) HSet(name, key string, value Value) (bool, error) {
return c.doBool("hset", name, key, value)
}
// HGet Get the value related to the specified key of a hashmap
func (c *Client) HGet(name, key string) (Value, error) {
return c.doValue("hget", name, key)
}
// HDel Delete specified key of a hashmap. To delete the whole hashmap, use hclear.
func (c *Client) HDel(name, key string) (bool, error) {
return c.doBool("hdel", name, key)
}
// HIncr Since 1.7.0.1, *incr methods return error if value cannot be converted to integer.
// Increment the number stored at key in a hashmap by num. The num argument could be a negative integer.
// The old number is first converted to an integer before increment, assuming it was stored as literal integer.
func (c *Client) HIncr(name, key string, num int64) (int64, error) {
return c.doInt("hincr", name, key, num)
}
// HExists Verify if the specified key exists in a hashmap.
func (c *Client) HExists(name, key string) (bool, error) {
return c.doBool("hexists", name, key)
}
// HSize Return the number of key-value pairs in the hashmap.
func (c *Client) HSize(name string) (int64, error) {
return c.doInt("hsize", name)
}
// HList List hashmap names in range (nameStart, nameEnd].
// ("", ""] means no range limit.
// Refer to scan command for more information about how it work.
func (c *Client) HList(nameStart, nameEnd string, limit int64) ([]string, error) {
return c.doStrings("hlist", nameStart, nameEnd, limit)
}
// HListRangeAll Like hlist, The whole range
func (c *Client) HListRangeAll(nameStart, nameEnd string, limit int64, cb func(string) error) error {
return c.doCDString(cb, 1, limit, "hlist", nameStart, nameEnd, limit)
}
// HRList Like hlist, but in reverse order.
func (c *Client) HRList(nameStart, nameEnd string, limit int64) ([]string, error) {
return c.doStrings("hrlist", nameStart, nameEnd, limit)
}
// HRListRangeAll Like hrlist, The whole range
func (c *Client) HRListRangeAll(nameStart, nameEnd string, limit int64, cb func(string) error) error {
return c.doCDString(cb, 1, limit, "hrlist", nameStart, nameEnd, limit)
}
// HKeys List keys of a hashmap in range (keyStart, keyEnd].
// ("", ""] means no range limit.
func (c *Client) HKeys(name, keyStart, keyEnd string, limit int64) ([]string, error) {
return c.doStrings("hkeys", name, keyStart, keyEnd, limit)
}
// HKeysRangeAll Like hkeys, The whole range
func (c *Client) HKeysRangeAll(name, keyStart, keyEnd string, limit int64, cb func(string) error) error {
return c.doCDString(cb, 2, limit, "hkeys", name, keyStart, keyEnd, limit)
}
// HGetAll Returns the whole hash, as an array of strings indexed by strings.
func (c *Client) HGetAll(name string) (map[string]Value, error) {
return c.doMapStringValue("hgetall", name)
}
// HGetAllPairs Returns the whole hash, as an array of strings indexed by strings.
func (c *Client) HGetAllPairs(name string) (Pairs, error) {
return c.doPairs("hgetall", name)
}
// HScan List key-value pairs of a hashmap with keys in range (keyStart, keyEnd].
// ("", ""] means no range limit.
// Refer to scan command for more information about how it work.
func (c *Client) HScan(name string, keyStart, keyEnd string, limit int64) (map[string]Value, error) {
return c.doMapStringValue("hscan", name, keyStart, keyEnd, limit)
}
// HScanPairs List key-value pairs of a hashmap with keys in range (keyStart, keyEnd].
// ("", ""] means no range limit.
// Refer to scan command for more information about how it work.
func (c *Client) HScanPairs(name string, keyStart, keyEnd string, limit int64) (Pairs, error) {
return c.doPairs("hscan", name, keyStart, keyEnd, limit)
}
// HScanRangeAll Like hscan, The whole range
func (c *Client) HScanRangeAll(name string, keyStart, keyEnd string, limit int64, cb func(string, Value) error) error {
return c.doCDStringValue(cb, 2, limit, "hscan", name, keyStart, keyEnd, limit)
}
// HRScan Like hscan, but in reverse order.
func (c *Client) HRScan(name string, keyStart, keyEnd string, limit int64) (map[string]Value, error) {
return c.doMapStringValue("hrscan", name, keyStart, keyEnd, limit)
}
// HRScanPairs Like hscan, but in reverse order.
func (c *Client) HRScanPairs(name string, keyStart, keyEnd string, limit int64) (Pairs, error) {
return c.doPairs("hrscan", name, keyStart, keyEnd, limit)
}
// HRScanRangeAll Like hrscan, The whole range
func (c *Client) HRScanRangeAll(name string, keyStart, keyEnd string, limit int64, cb func(string, Value) error) error {
return c.doCDStringValue(cb, 2, limit, "hrscan", name, keyStart, keyEnd, limit)
}
// HClear Delete all keys in a hashmap.
func (c *Client) HClear(name string) error {
return c.doNil("hclear", name)
}
// MultiHSet Set multiple key-value pairs(kvs) of a hashmap in one method call.
func (c *Client) MultiHSet(name string, kvs map[string]Value) error {
args := []interface{}{"multi_hset", name}
for k, v := range kvs {
args = append(args, k)
args = append(args, v)
}
return c.doNil(args...)
}
// MultiHSetPairs Set multiple key-value pairs(kvs) of a hashmap in one method call.
func (c *Client) MultiHSetPairs(name string, kvs Pairs) error {
args := []interface{}{"multi_hset", name}
for _, kv := range kvs {
args = append(args, kv.Key)
args = append(args, kv.Value)
}
return c.doNil(args...)
}
// MultiHGet Get the values related to the specified multiple keys of a hashmap.
func (c *Client) MultiHGet(name string, key ...string) (map[string]Value, error) {
if len(key) == 0 {
return map[string]Value{}, nil
}
args := []interface{}{"multi_hget", name}
for _, v := range key {
args = append(args, v)
}
return c.doMapStringValue(args...)
}
// MultiHGetPairs Get the values related to the specified multiple keys of a hashmap.
func (c *Client) MultiHGetPairs(name string, key ...string) (Pairs, error) {
if len(key) == 0 {
return Pairs{}, nil
}
args := []interface{}{"multi_hget", name}
for _, v := range key {
args = append(args, v)
}
return c.doPairs(args...)
}
// MultiHDel Delete specified multiple keys in a hashmap.
func (c *Client) MultiHDel(name string, key ...string) error {
if len(key) == 0 {
return nil
}
args := []interface{}{"multi_hdel", name}
for _, v := range key {
args = append(args, v)
}
return c.doNil(args...)
}