-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands_hash.v
More file actions
43 lines (36 loc) · 968 Bytes
/
commands_hash.v
File metadata and controls
43 lines (36 loc) · 968 Bytes
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
module redict
// https://redict.io/docs/commands/#hash
interface HashCmdable {
hdel(key string, fields ...string) &IntCmd
hget(key string, index string) &StringCmd
hset(key string, values []Value) &IntCmd
}
pub fn (c CmdableFn) hdel(key string, fields ...string) &IntCmd {
mut args := []Value{len: 2 + fields.len, init: Value('')}
args[0] = 'hdel'
args[1] = key
for i := 0; i < fields.len; i++ {
field := fields[i]
args[2 + i] = field
}
mut cmd := new_int_cmd(...args)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) hget(key string, index string) &StringCmd {
mut cmd := new_string_cmd('hget', key, index)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) hset(key string, values ...Value) &IntCmd {
mut args := []Value{len: 2 + values.len, init: Value('')}
args[0] = 'hset'
args[1] = key
for i := 0; i < values.len; i++ {
value := values[i]
args[2 + i] = value
}
mut cmd := new_int_cmd(...args)
c(mut cmd) or {}
return cmd
}