-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands_string.v
More file actions
202 lines (177 loc) · 5.18 KB
/
Copy pathcommands_string.v
File metadata and controls
202 lines (177 loc) · 5.18 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
module redict
import time
// https://redict.io/docs/commands/#string
interface StringCmdable {
append(key string, value string) &IntCmd
decr(key string) &IntCmd
decrby(key string, decrement i64) &IntCmd
get(key string) &StringCmd
getdel(key string) &StringCmd
getex(key string, expiration time.Duration) &StringCmd
getrange(key string, start i64, end i64) &StringCmd
getset(key string, value Value) &StringCmd
incr(key string) &IntCmd
incrby(key string, value i64) &IntCmd
incrbyfloat(key string, value f64) &FloatCmd
// lcs(q &LCSQuery) &LCSCmd
// mget(keys ...string) &SliceCmd
mset(values ...Value) &StatusCmd
msetnx(values ...Value) &BoolCmd
psetex(key string, expiration time.Duration, value Value) &StatusCmd
set(key string, value Value, expiration time.Duration) &StatusCmd
setex(key string, value Value, expiration time.Duration) &StatusCmd
setnx(key string, value Value, expiration time.Duration) &BoolCmd
setrange(key string, offset i64, value string) &IntCmd
strlen(key string) &IntCmd
substr(key string, start i64, end i64) &StringCmd
}
pub fn (c CmdableFn) append(key string, value string) &IntCmd {
mut cmd := new_int_cmd('append', key, value)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) decr(key string) &IntCmd {
mut cmd := new_int_cmd('decr', key)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) decrby(key string, decrement i64) &IntCmd {
mut cmd := new_int_cmd('decrby', key, decrement)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) get(key string) &StringCmd {
mut cmd := new_string_cmd('get', key)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) getdel(key string) &StringCmd {
mut cmd := new_string_cmd('getdel', key)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) getex(key string, expiration time.Duration) &StringCmd {
mut args := []Value{len: 0, cap: 4, init: Empty{}}
args << 'getex'
args << key
if expiration > 0 {
if use_precise(expiration) {
args << 'px'
args << format_ms(expiration)
} else {
args << 'ex'
args << format_sec(expiration)
}
} else if expiration == 0 {
args << 'persist'
}
mut cmd := new_string_cmd(...args)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) getrange(key string, start i64, end i64) &StringCmd {
mut cmd := new_string_cmd('getrange', key, start, end)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) getset(key string, value Value) &StringCmd {
mut cmd := new_string_cmd('getset', key, value)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) incr(key string) &IntCmd {
mut cmd := new_int_cmd('incr', key)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) incrby(key string, value i64) &IntCmd {
mut cmd := new_int_cmd('incrby', key, value)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) incrbyfloat(key string, value f64) &FloatCmd {
mut cmd := new_float_cmd('incrbyfloat', key, value)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) mset(key string, values ...Value) &StatusCmd {
mut args := []Value{len: 0, cap: values.len + 1, init: Empty{}}
args << 'mset'
args << values
mut cmd := new_status_cmd(...args)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) msetnx(key string, values ...Value) &BoolCmd {
mut args := []Value{len: 0, cap: values.len + 1, init: Empty{}}
args << 'msetnx'
args << values
mut cmd := new_bool_cmd(...args)
c(mut cmd) or {}
return cmd
}
// deprecated since 2.16.12, equivalent to set with px
pub fn (c CmdableFn) psetex(key string, expiration time.Duration, value Value) &StatusCmd {
return c.set(key, value, expiration)
}
// set issues a `SET key value [expiration]` command.
// Zero expiration means the key has no expiration time.
pub fn (c CmdableFn) set(key string, value Value, expiration time.Duration) &StatusCmd {
mut args := []Value{len: 0, cap: 3, init: Empty{}}
args << 'set'
args << key
args << value
if expiration > 0 {
if use_precise(expiration) {
args << 'px'
args << format_ms(expiration)
} else {
args << 'ex'
args << format_sec(expiration)
}
} else if expiration == keep_ttl {
args << 'keepttl'
}
mut cmd := new_status_cmd(...args)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) setex(key string, value Value, expiration time.Duration) &StatusCmd {
mut cmd := new_status_cmd('setex', key, format_sec(expiration))
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) setnx(key string, value Value, expiration time.Duration) &BoolCmd {
mut cmd := &BoolCmd{}
match expiration {
0 {
cmd = new_bool_cmd('setnx', key, value)
}
keep_ttl {
cmd = new_bool_cmd('set', key, value, 'keepttl', 'nx')
}
else {
if use_precise(expiration) {
cmd = new_bool_cmd('set', key, value, 'px', format_ms(expiration), 'nx')
} else {
cmd = new_bool_cmd('set', key, value, format_sec(expiration), 'nx')
}
}
}
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) setrange(key string, offset i64, value string) &IntCmd {
mut cmd := new_int_cmd('setrange', key, offset, value)
c(mut cmd) or {}
return cmd
}
pub fn (c CmdableFn) strlen(key string) &IntCmd {
mut cmd := new_int_cmd('setrange', key)
c(mut cmd) or {}
return cmd
}
// deprecated since 2.0.0, equivalent to getrange
pub fn (c CmdableFn) substr(key string, start i64, end i64) &StringCmd {
return c.getrange(key, start, end)
}