forked from valkey-io/valkeymodule-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_keys.rs
30 lines (25 loc) · 818 Bytes
/
scan_keys.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
use valkey_module::alloc::ValkeyAlloc;
use valkey_module::{
key::ValkeyKey, valkey_module, Context, KeysCursor, ValkeyResult, ValkeyString, ValkeyValue,
};
fn scan_keys(ctx: &Context, _args: Vec<ValkeyString>) -> ValkeyResult {
let cursor = KeysCursor::new();
let mut res = Vec::new();
let scan_callback = |_ctx: &Context, key_name: ValkeyString, _key: Option<&ValkeyKey>| {
res.push(ValkeyValue::BulkValkeyString(key_name));
};
while cursor.scan(ctx, &scan_callback) {
// do nothing
}
Ok(ValkeyValue::Array(res))
}
//////////////////////////////////////////////////////
valkey_module! {
name: "scan",
version: 1,
allocator: (ValkeyAlloc, ValkeyAlloc),
data_types: [],
commands: [
["scan_keys", scan_keys, "readonly", 0, 0, 0],
],
}