-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.v
51 lines (42 loc) · 1.27 KB
/
script.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
module vredis
pub fn (mut r Redis) eval(script string, num_keys int, keys_and_args ...string) !string {
if keys_and_args.len < num_keys {
return error('keys_and_args.len != ${num_keys}')
}
mut args := [CmdArg(script), CmdArg(num_keys)]
for it in keys_and_args {
args << it
}
return r.send('EVAL', ...args)!.bytestr().trim_right(crlf)
}
pub fn (mut r Redis) evalsha(sha1 string, num_keys int, keys_and_args ...string) !string {
if keys_and_args.len < num_keys {
return error('keys_and_args.len != ${num_keys}')
}
mut args := [CmdArg(sha1), CmdArg(num_keys)]
for it in keys_and_args {
args << it
}
return r.send('EVALSHA', ...args)!.bytestr()
}
pub fn (mut r Redis) script_load(script string) !string {
return r.send('SCRIPT', 'LOAD', script)!.bytestr()
}
pub fn (mut r Redis) script_kill() !bool {
return r.send('SCRIPT', 'KILL')!.ok()
}
pub fn (mut r Redis) script_flush() !bool {
return r.send('SCRIPT', ' FLUSH')!.ok()
}
pub fn (mut r Redis) script_exists(sha string, shas ...string) !map[string]bool {
mut args := [CmdArg('EXISTS'), CmdArg(sha)]
for it in shas {
args << it
}
res_arr := r.send('SCRIPT', ...args)!.strings()
mut result := map[string]bool{}
for i := 1; i < args.len; i++ {
result[args[i] as string] = res_arr[i].u8() == 1
}
return result
}