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
use std::ops::{Deref, DerefMut};
use redis::{FromRedisValue, RedisResult, ToRedisArgs};
use crate::ConnectionWrapper;
pub struct Cmd {
pub(crate) cmd: redis::Cmd,
}
impl Cmd {
pub fn new() -> Self {
Self {
cmd: redis::Cmd::new(),
}
}
pub fn arg<T: ToRedisArgs>(&mut self, arg: T) -> &mut Cmd {
self.cmd.arg(arg);
self
}
pub fn cursor_arg(&mut self, cursor: u64) -> &mut Cmd {
self.cmd.cursor_arg(cursor);
self
}
pub async fn query_async<T: FromRedisValue + Send>(
&self,
conn: &mut ConnectionWrapper,
) -> RedisResult<T> {
self.cmd.query_async(DerefMut::deref_mut(conn)).await
}
pub async fn execute_async(&self, con: &mut ConnectionWrapper) -> RedisResult<()> {
self.query_async::<redis::Value>(con).await?;
Ok(())
}
}
impl Deref for Cmd {
type Target = redis::Cmd;
fn deref(&self) -> &redis::Cmd {
&self.cmd
}
}
impl DerefMut for Cmd {
fn deref_mut(&mut self) -> &mut redis::Cmd {
&mut self.cmd
}
}
impl From<redis::Cmd> for Cmd {
fn from(cmd: redis::Cmd) -> Self {
Cmd { cmd }
}
}
impl Into<redis::Cmd> for Cmd {
fn into(self) -> redis::Cmd {
self.cmd
}
}
pub fn cmd(name: &str) -> Cmd {
let mut cmd = Cmd::new();
cmd.arg(name);
cmd
}