-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcommand_info_manager.rs
137 lines (128 loc) · 3.96 KB
/
command_info_manager.rs
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
use crate::{
client::IntoConfig,
commands::{
GenericCommands, MigrateOptions, SortOptions, SortOrder, SortedSetCommands, StreamCommands,
StringCommands, XReadGroupOptions, XReadOptions, ZAggregate,
},
network::StandaloneConnection,
tests::{get_default_addr, get_default_host, get_default_port, get_test_client},
CommandInfoManager, Result,
};
use serial_test::serial;
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn extract_keys() -> Result<()> {
let client = get_test_client().await?;
let mut connection = StandaloneConnection::connect(
&get_default_host(),
get_default_port(),
&get_default_addr().into_config()?,
)
.await?;
let command_info_manager = CommandInfoManager::initialize(&mut connection).await?;
// SET
let keys = command_info_manager
.extract_keys(client.set("key", "value").command(), &mut connection)
.await?;
assert_eq!(1, keys.len());
assert_eq!("key", keys[0]);
// MSET
let keys = command_info_manager
.extract_keys(
client
.mset([("key1", "value1"), ("key2", "value2")])
.command(),
&mut connection,
)
.await?;
assert_eq!(2, keys.len());
assert_eq!("key1", keys[0]);
assert_eq!("key2", keys[1]);
// XREAD
let keys = command_info_manager
.extract_keys(
client
.xread::<_, _, _, _, String, Vec<(_, _)>>(
XReadOptions::default().count(2),
["mystream", "writers"],
["1526999352406-0", "1526985685298-0"],
)
.command(),
&mut connection,
)
.await?;
assert_eq!(2, keys.len());
assert_eq!("mystream", keys[0]);
assert_eq!("writers", keys[1]);
// XREADGROUP
let keys = command_info_manager
.extract_keys(
client
.xreadgroup::<_, _, _, _, _, _, String, Vec<(_, _)>>(
"mygroup",
"myconsumer",
XReadGroupOptions::default().count(2),
["mystream", "writers"],
["1526999352406-0", "1526985685298-0"],
)
.command(),
&mut connection,
)
.await?;
assert_eq!(2, keys.len(), "unexpected keys: {:?}", keys);
assert_eq!("mystream", keys[0]);
assert_eq!("writers", keys[1]);
// MIGRATE
let keys = command_info_manager
.extract_keys(
client
.migrate(
"192.168.1.34",
6379,
"",
0,
5000,
MigrateOptions::default().keys(["key1", "key2", "key3"]),
)
.command(),
&mut connection,
)
.await?;
assert_eq!(3, keys.len());
assert_eq!("key1", keys[0]);
assert_eq!("key2", keys[1]);
assert_eq!("key3", keys[2]);
// ZUNION
let keys = command_info_manager
.extract_keys(
client
.zunion::<_, _, _, String>(["zset1", "zset2"], Some([1.5, 2.5]), ZAggregate::Max)
.command(),
&mut connection,
)
.await?;
assert_eq!(2, keys.len());
assert_eq!("zset1", keys[0]);
assert_eq!("zset2", keys[1]);
// SORT
let keys = command_info_manager
.extract_keys(
client
.sort_and_store(
"src",
"dst",
SortOptions::default()
.limit(0, 5)
.alpha()
.order(SortOrder::Desc),
)
.command(),
&mut connection,
)
.await?;
assert_eq!(2, keys.len());
assert_eq!("src", keys[0]);
assert_eq!("dst", keys[1]);
Ok(())
}