-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.v
98 lines (78 loc) · 2.54 KB
/
list.v
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
module vredis
pub struct BPopReply {
pub:
key string
value string
}
fn (mut r Redis) push(cmd string, key string, value string, values []string) !int {
mut args := [CmdArg(key), CmdArg(value)]
for val in values {
args << val
}
return r.send(cmd, ...args)!.int()
}
pub fn (mut r Redis) lpush(key string, value string, values ...string) !int {
return r.push('LPUSH', key, value, values)!
}
pub fn (mut r Redis) rpush(key string, value string, values ...string) !int {
return r.push('RPUSH', key, value, values)!
}
pub fn (mut r Redis) lpop(key string) !string {
return r.send('LPOP', key)!.bytestr()
}
pub fn (mut r Redis) rpop(key string) !string {
return r.send('RPOP', key)!.bytestr()
}
pub fn (mut r Redis) lset(key string, index i64, value string) !bool {
return r.send('LSET', key, index, value)!.ok()
}
pub fn (mut r Redis) llen(key string) !int {
return r.send('LLEN', key)!.int()
}
pub fn (mut r Redis) lindex(key string, index int) !string {
return r.send('LINDEX', key, index)!.bytestr()
}
pub fn (mut r Redis) lrem(key string, count int, value string) !int {
return r.send('LREM', key, count, value)!.int()
}
pub fn (mut r Redis) ltrim(key string, start int, stop int) !bool {
return r.send('LTRIM', key, start, stop)!.ok()
}
pub fn (mut r Redis) rpoplpush(source string, destination string) !string {
return r.send('RPOPLPUSH', source, destination)!.bytestr()
}
pub fn (mut r Redis) rpushx(key string, value string, values ...string) !int {
return r.push('RPUSHX', key, value, values)!
}
pub fn (mut r Redis) linsert(key string, pos string, pivot string, value string) !int {
if pos.to_upper() !in ['BEFORE', 'AFTER'] {
return error('pos failed: BEFORE|AFTER')
}
return r.send('LINSERT', key, pos, pivot, value)!.int()
}
pub fn (mut r Redis) lrange(key string, start int, stop int) ![]string {
return r.send('LRANGE', key, start, stop)!.strings()
}
fn (mut r Redis) bpop(command string, key string, timeout int, keys ...string) !BPopReply {
mut args := [CmdArg(key)]
args << keys
for it in keys {
args << it
}
args << timeout
ret := r.send('BLPOP', ...args)!.data().bytestr()
if ret == '(nil)' {
return error('block has timeout!')
}
lk, value := ret.split_once(crlf) or { return error('parse reply content failed') }
return BPopReply{
key: lk
value: value
}
}
pub fn (mut r Redis) brpop(key string, timeout int, keys ...string) !BPopReply {
return r.bpop('BRPOP', key, timeout, ...keys)!
}
pub fn (mut r Redis) blpop(key string, timeout int, keys ...string) !BPopReply {
return r.bpop('BLPOP', key, timeout, ...keys)!
}