|
1 | 1 | use std::ffi::CString; |
2 | | -use std::os::raw::c_long; |
| 2 | +use std::os::raw::{c_long, c_int}; |
3 | 3 | use std::ptr; |
4 | 4 |
|
5 | 5 | use crate::key::{RedisKey, RedisKeyWritable}; |
@@ -56,6 +56,22 @@ impl Context { |
56 | 56 | } |
57 | 57 | } |
58 | 58 |
|
| 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 | + |
59 | 75 | pub fn call(&self, command: &str, args: &[&str]) -> RedisResult { |
60 | 76 | let terminated_args: Vec<RedisString> = args |
61 | 77 | .iter() |
@@ -149,8 +165,15 @@ impl Context { |
149 | 165 | raw::RedisModule_ReplyWithNull.unwrap()(self.ctx).into() |
150 | 166 | }, |
151 | 167 |
|
| 168 | + Ok(RedisValue::NoReply) => raw::Status::Ok, |
| 169 | + |
152 | 170 | 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 | + } |
154 | 177 | }, |
155 | 178 |
|
156 | 179 | Err(RedisError::String(s)) => unsafe { |
|
0 commit comments