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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#[cfg(test)]
#[path = "./commands_test.rs"]
mod commands_test;
use crate::client::Client;
use crate::types::{RedisArg, RedisBoolResult, RedisEmptyResult, RedisResult, RedisStringResult};
use std::collections::HashMap;
use std::str::FromStr;
impl Client {
pub fn auth(&mut self, password: &str) -> RedisEmptyResult {
self.run_command_empty_response("AUTH", vec![password])
}
pub fn echo(&mut self, value: &str) -> RedisStringResult {
self.run_command_string_response("ECHO", vec![value])
}
pub fn publish(&mut self, channel: &str, message: &str) -> RedisEmptyResult {
self.run_command_empty_response("PUBLISH", vec![channel, message])
}
pub fn get<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T> {
self.run_command_from_string_response("GET", vec![key])
}
pub fn get_string(self: &mut Client, key: &str) -> RedisStringResult {
self.run_command_string_response("GET", vec![key])
}
pub fn set<T: RedisArg>(self: &mut Client, key: &str, value: T) -> RedisEmptyResult {
self.run_command_empty_response("SET", vec![key, &value.to_string()])
}
pub fn setex<T: RedisArg>(&mut self, key: &str, value: T, seconds: usize) -> RedisEmptyResult {
self.run_command_empty_response(
"SETEX",
vec![key, &*seconds.to_string(), &value.to_string()],
)
}
pub fn setnx<T: RedisArg>(&mut self, key: &str, value: T) -> RedisEmptyResult {
self.run_command_empty_response("SETNX", vec![key, &value.to_string()])
}
pub fn getset<T: RedisArg, V: FromStr>(&mut self, key: &str, value: T) -> RedisResult<V> {
self.run_command_from_string_response::<V>("GETSET", vec![key, &value.to_string()])
}
pub fn getset_string<T: RedisArg>(&mut self, key: &str, value: T) -> RedisStringResult {
self.run_command_string_response("GETSET", vec![key, &value.to_string()])
}
pub fn del(&mut self, key: &str) -> RedisEmptyResult {
self.run_command_empty_response("DEL", vec![key])
}
pub fn exists(&mut self, key: &str) -> RedisBoolResult {
self.run_command_bool_response("EXISTS", vec![key])
}
pub fn expire(&mut self, key: &str, seconds: usize) -> RedisEmptyResult {
self.run_command_empty_response("EXPIRE", vec![key, &*seconds.to_string()])
}
pub fn pexpire(&mut self, key: &str, millies: usize) -> RedisEmptyResult {
self.run_command_empty_response("PEXPIRE", vec![key, &*millies.to_string()])
}
pub fn persist(&mut self, key: &str) -> RedisEmptyResult {
self.run_command_empty_response("PERSIST", vec![key])
}
pub fn rename(&mut self, key: &str, new_key: &str) -> RedisEmptyResult {
self.run_command_empty_response("RENAME", vec![key, new_key])
}
pub fn renamenx(&mut self, key: &str, new_key: &str) -> RedisEmptyResult {
self.run_command_empty_response("RENAMENX", vec![key, new_key])
}
pub fn append(&mut self, key: &str, value: &str) -> RedisEmptyResult {
self.run_command_empty_response("APPEND", vec![key, value])
}
pub fn incr(&mut self, key: &str) -> RedisResult<i64> {
self.run_command::<i64>("INCR", vec![key])
}
pub fn incrby<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<i64> {
self.run_command::<i64>("INCRBY", vec![key, &*value.to_string()])
}
pub fn incrbyfloat<T: RedisArg>(&mut self, key: &str, value: T) -> RedisResult<f64> {
self.run_command::<f64>("INCRBYFLOAT", vec![key, &*value.to_string()])
}
pub fn strlen(&mut self, key: &str) -> RedisResult<i32> {
self.run_command::<i32>("STRLEN", vec![key])
}
pub fn keys(&mut self, pattern: &str) -> RedisResult<Vec<String>> {
self.run_command::<Vec<String>>("KEYS", vec![pattern])
}
pub fn hget<T: FromStr>(self: &mut Client, key: &str, field: &str) -> RedisResult<T> {
self.run_command_from_string_response("HGET", vec![key, field])
}
pub fn hget_string(self: &mut Client, key: &str, field: &str) -> RedisStringResult {
self.run_command_string_response("HGET", vec![key, field])
}
pub fn hgetall(self: &mut Client, key: &str) -> RedisResult<HashMap<String, String>> {
self.run_command::<HashMap<String, String>>("HGETALL", vec![key])
}
pub fn hset<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T,
) -> RedisEmptyResult {
self.run_command_empty_response("HSET", vec![key, field, &value.to_string()])
}
pub fn hsetnx<T: RedisArg>(
self: &mut Client,
key: &str,
field: &str,
value: T,
) -> RedisEmptyResult {
self.run_command_empty_response("HSETNX", vec![key, field, &value.to_string()])
}
pub fn hdel(self: &mut Client, key: &str, field: &str) -> RedisEmptyResult {
self.run_command_empty_response("HDEL", vec![key, field])
}
pub fn hexists(self: &mut Client, key: &str, field: &str) -> RedisBoolResult {
self.run_command_bool_response("HEXISTS", vec![key, field])
}
pub fn hkeys(&mut self, key: &str) -> RedisResult<Vec<String>> {
self.run_command::<Vec<String>>("HKEYS", vec![key])
}
pub fn hvals(&mut self, key: &str) -> RedisResult<Vec<String>> {
self.run_command::<Vec<String>>("HVALS", vec![key])
}
pub fn lset<T: RedisArg>(
self: &mut Client,
key: &str,
index: isize,
value: T,
) -> RedisEmptyResult {
self.run_command_empty_response("LSET", vec![key, &index.to_string(), &value.to_string()])
}
pub fn lindex<T: FromStr>(self: &mut Client, key: &str, index: isize) -> RedisResult<T> {
self.run_command_from_string_response("LINDEX", vec![key, &index.to_string()])
}
pub fn lindex_string(self: &mut Client, key: &str, index: isize) -> RedisStringResult {
self.run_command_string_response("LINDEX", vec![key, &index.to_string()])
}
pub fn llen(self: &mut Client, key: &str) -> RedisResult<i32> {
self.run_command::<i32>("LLEN", vec![key])
}
pub fn lpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T> {
self.run_command_from_string_response("LPOP", vec![key])
}
pub fn lpush<T: RedisArg>(self: &mut Client, key: &str, value: T) -> RedisEmptyResult {
self.run_command_empty_response("LPUSH", vec![key, &value.to_string()])
}
pub fn lpushx<T: RedisArg>(self: &mut Client, key: &str, value: T) -> RedisEmptyResult {
self.run_command_empty_response("LPUSHX", vec![key, &value.to_string()])
}
pub fn lrange(
self: &mut Client,
key: &str,
start: isize,
stop: isize,
) -> RedisResult<Vec<String>> {
self.run_command::<Vec<String>>("LRANGE", vec![key, &start.to_string(), &stop.to_string()])
}
pub fn lrem<T: RedisArg>(
self: &mut Client,
key: &str,
count: isize,
value: T,
) -> RedisEmptyResult {
self.run_command_empty_response("LREM", vec![key, &count.to_string(), &value.to_string()])
}
pub fn ltrim(self: &mut Client, key: &str, start: isize, stop: isize) -> RedisEmptyResult {
self.run_command_empty_response("LTRIM", vec![key, &start.to_string(), &stop.to_string()])
}
pub fn rpop<T: FromStr>(self: &mut Client, key: &str) -> RedisResult<T> {
self.run_command_from_string_response("RPOP", vec![key])
}
pub fn rpush<T: RedisArg>(self: &mut Client, key: &str, value: T) -> RedisEmptyResult {
self.run_command_empty_response("RPUSH", vec![key, &value.to_string()])
}
pub fn rpushx<T: RedisArg>(self: &mut Client, key: &str, value: T) -> RedisEmptyResult {
self.run_command_empty_response("RPUSHX", vec![key, &value.to_string()])
}
pub fn sadd(self: &mut Client, key: &str, member: &str) -> RedisResult<i32> {
self.run_command::<i32>("SADD", vec![key, member])
}
pub fn scard(self: &mut Client, key: &str) -> RedisResult<i32> {
self.run_command::<i32>("SCARD", vec![key])
}
pub fn sdiff(self: &mut Client, keys: Vec<&str>) -> RedisResult<Vec<String>> {
self.run_command::<Vec<String>>("SDIFF", keys)
}
pub fn sismember(self: &mut Client, key: &str, member: &str) -> RedisBoolResult {
self.run_command("SISMEMBER", vec![key, member])
}
pub fn smembers(self: &mut Client, key: &str) -> RedisResult<Vec<String>> {
self.run_command::<Vec<String>>("SMEMBERS", vec![key])
}
pub fn smove(
self: &mut Client,
source_key: &str,
destination_key: &str,
member: &str,
) -> RedisEmptyResult {
self.run_command("SMOVE", vec![source_key, destination_key, member])
}
pub fn srem(self: &mut Client, key: &str, member: &str) -> RedisEmptyResult {
self.run_command("SREM", vec![key, member])
}
pub fn zadd(self: &mut Client, key: &str, score: isize, member: &str) -> RedisResult<i32> {
self.run_command("ZADD", vec![key, &score.to_string(), member])
}
pub fn zrange(
self: &mut Client,
key: &str,
start: isize,
stop: isize,
) -> RedisResult<Vec<String>> {
self.run_command::<Vec<String>>("ZRANGE", vec![key, &start.to_string(), &stop.to_string()])
}
}