-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathopen_key_with_flags.rs
68 lines (60 loc) · 1.76 KB
/
open_key_with_flags.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
use valkey_module::alloc::ValkeyAlloc;
use valkey_module::{
key::KeyFlags, valkey_module, Context, NextArg, ValkeyError, ValkeyResult, ValkeyString,
ValkeyValue,
};
use valkey_module_macros::command;
#[command(
{
name: "open_key_with_flags.read",
flags: [Write, DenyOOM],
arity: 2,
key_spec: [
{
flags: [ReadOnly, Access],
begin_search: Index({ index : 1 }),
find_keys: Range({ last_key : 1, steps : 1, limit : 1}),
}
]
}
)]
fn read(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
if args.len() < 2 {
return Err(ValkeyError::WrongArity);
}
let mut args = args.into_iter().skip(1);
let key_name = args.next_arg()?;
let _ = ctx.open_key_with_flags(&key_name, KeyFlags::NOEFFECTS);
Ok(ValkeyValue::SimpleStringStatic("OK"))
}
#[command(
{
name: "open_key_with_flags.write",
flags: [Write, DenyOOM],
arity: 2,
key_spec: [
{
flags: [ReadWrite, Access],
begin_search: Index({ index : 1 }),
find_keys: Range({ last_key : 1, steps : 1, limit : 1}),
}
]
}
)]
fn write(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
if args.len() < 2 {
return Err(ValkeyError::WrongArity);
}
let mut args = args.into_iter().skip(1);
let key_name = args.next_arg()?;
let _ = ctx.open_key_writable_with_flags(&key_name, KeyFlags::NOEFFECTS);
Ok(ValkeyValue::SimpleStringStatic("OK"))
}
//////////////////////////////////////////////////////
valkey_module! {
name: "open_key_with_flags",
version: 1,
allocator: (ValkeyAlloc, ValkeyAlloc),
data_types: [],
commands: [],
}