Skip to content
This repository was archived by the owner on Apr 20, 2020. It is now read-only.

Commit c674489

Browse files
authored
fix #48 return poped element on arr_pop (#52)
* fix #48 return poped element on arr_pop
1 parent a42d385 commit c674489

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,9 @@ fn json_arr_pop(ctx: &Context, args: Vec<String>) -> RedisResult {
529529
.ok_or_else(RedisError::nonexistent_key)
530530
.and_then(|doc| {
531531
doc.value_op(&path, |value| do_json_arr_pop(index, &mut res, value))
532-
.map(|v| v.to_string().into())
533532
.map_err(|e| e.into())
534-
})
533+
})?;
534+
Ok(RedisJSON::serialize(&res, Format::JSON)?.into())
535535
}
536536

537537
fn do_json_arr_pop(mut index: i64, res: &mut Value, value: &Value) -> Result<Value, Error> {

src/redisjson.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ impl RedisJSON {
155155

156156
pub fn to_string(&self, path: &str, format: Format) -> Result<String, Error> {
157157
let results = self.get_doc(path)?;
158+
Self::serialize(results, format)
159+
}
160+
161+
pub fn serialize(results: &Value, format: Format) -> Result<String, Error> {
158162
let res = match format {
159-
Format::JSON => serde_json::to_string(&results)?,
163+
Format::JSON => serde_json::to_string(results)?,
160164
Format::BSON => return Err("Soon to come...".into()), //results.into() as Bson,
161165
};
162166
Ok(res)

0 commit comments

Comments
 (0)