Skip to content

Commit 78db486

Browse files
committed
Add support for RedisModule_IsKeysPositionRequest
1 parent 754ad78 commit 78db486

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/context.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::ffi::CString;
2-
use std::os::raw::c_long;
2+
use std::os::raw::{c_long, c_int};
33
use std::ptr;
44

55
use crate::key::{RedisKey, RedisKeyWritable};
@@ -56,6 +56,22 @@ impl Context {
5656
}
5757
}
5858

59+
pub fn is_keys_position_request(&self) -> bool {
60+
let result = unsafe {
61+
raw::RedisModule_IsKeysPositionRequest.unwrap()(self.ctx)
62+
};
63+
64+
result != 0
65+
}
66+
67+
pub fn key_at_pos(&self, pos: i32) {
68+
// TODO: This will crash redis if `pos` is out of range.
69+
// Think of a way to make this safe by checking the range.
70+
unsafe {
71+
raw::RedisModule_KeyAtPos.unwrap()(self.ctx, pos as c_int);
72+
}
73+
}
74+
5975
pub fn call(&self, command: &str, args: &[&str]) -> RedisResult {
6076
let terminated_args: Vec<RedisString> = args
6177
.iter()
@@ -149,8 +165,15 @@ impl Context {
149165
raw::RedisModule_ReplyWithNull.unwrap()(self.ctx).into()
150166
},
151167

168+
Ok(RedisValue::NoReply) => raw::Status::Ok,
169+
152170
Err(RedisError::WrongArity) => unsafe {
153-
raw::RedisModule_WrongArity.unwrap()(self.ctx).into()
171+
if self.is_keys_position_request() {
172+
// We can't return a result since we don't have a client
173+
raw::Status::Err
174+
} else {
175+
raw::RedisModule_WrongArity.unwrap()(self.ctx).into()
176+
}
154177
},
155178

156179
Err(RedisError::String(s)) => unsafe {

src/redisvalue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub enum RedisValue {
77
Float(f64),
88
Array(Vec<RedisValue>),
99
Null,
10+
NoReply, // No reply at all (as opposed to a Null reply)
1011
}
1112

1213
impl From<()> for RedisValue {

0 commit comments

Comments
 (0)