Skip to content

Commit 60d55f8

Browse files
authored
add StringBuffer(Vec<u8>) support for RedisValue (#161)
* add StringBuffer(Vec<u8>) support for RedisValue
1 parent 23cb18b commit 60d55f8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/context/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ impl Context {
169169
raw::RedisModule_ReplyWithString.unwrap()(self.ctx, s.inner).into()
170170
},
171171

172+
Ok(RedisValue::StringBuffer(s)) => unsafe {
173+
raw::RedisModule_ReplyWithStringBuffer.unwrap()(
174+
self.ctx,
175+
s.as_ptr() as *const i8,
176+
s.len() as usize,
177+
)
178+
.into()
179+
},
180+
172181
Ok(RedisValue::Array(array)) => {
173182
unsafe {
174183
// According to the Redis source code this always succeeds,

src/redisvalue.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub enum RedisValue {
66
SimpleString(String),
77
BulkString(String),
88
BulkRedisString(RedisString),
9+
StringBuffer(Vec<u8>),
910
Integer(i64),
1011
Float(f64),
1112
Array(Vec<RedisValue>),
@@ -49,6 +50,12 @@ impl From<RedisString> for RedisValue {
4950
}
5051
}
5152

53+
impl From<Vec<u8>> for RedisValue {
54+
fn from(s: Vec<u8>) -> Self {
55+
RedisValue::StringBuffer(s)
56+
}
57+
}
58+
5259
impl From<&RedisString> for RedisValue {
5360
fn from(s: &RedisString) -> Self {
5461
s.to_owned().into()
@@ -120,6 +127,15 @@ mod tests {
120127
);
121128
}
122129

130+
#[test]
131+
fn from_vec() {
132+
let v : Vec<u8> = vec![0,3,5,21,255];
133+
assert_eq!(
134+
RedisValue::from(v),
135+
RedisValue::StringBuffer(vec![0,3,5,21,255])
136+
);
137+
}
138+
123139
#[test]
124140
fn from_option_none() {
125141
assert_eq!(RedisValue::from(None::<()>), RedisValue::Null,);

0 commit comments

Comments
 (0)