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

Commit 95ed035

Browse files
authored
add support for STRAPPEND, ARRAPPEND, ARRINSERT, ARRPOP, ARRINDEX, ARRTRIM, OBJKEYS (#33)
1. json_del: backward fix on json_del to support full key delete 2. json_set: error on creation of key with path!=root 3. mark commands as "write" and open keys with open_key() on readonly 4. set_value: add support for root set and returns error when path not found 5. get_doc: return error on wrong path 6. redisjson.rs: turn num_op into a generic value_op 7. lib.rs: add support for STRAPPEND, ARRAPPEND, ARRINSERT, ARRPOP 8. Add support for JSON.ARRINDEX 9. Add support for JSON.ARRTRIM & fix ARRINSERT to accept negative index 10. Add support for JSON.OBJKEYS 11. add special handling for path=$ (root), can't call replace_with 12. Return poped value on arrpop and fix error handle on replace with wrong path 13. fix path backward on ARRPOP * Fix commands for backward: 1. STRAPPEND & ARRAPPNED return the len after update 2. MGET returns nil when path not found for a key * json.arrinsert inserts items in original order (and not reversed) * Verify we have no superfluous command args
1 parent e0363dc commit 95ed035

File tree

7 files changed

+947
-533
lines changed

7 files changed

+947
-533
lines changed

.circleci/config.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
jobs:
44
build:
55
docker:
6-
- image: circleci/rust
6+
- image: circleci/rust:buster
77

88
steps:
99
- checkout
@@ -12,7 +12,10 @@ jobs:
1212

1313
- run:
1414
name: Install prerequisite
15-
command: sudo apt-get install -y clang
15+
command: |
16+
sudo apt-get install -y software-properties-common
17+
sudo add-apt-repository -y ppa:chris-lea/redis-server
18+
sudo apt-get install -y clang python-pip redis-server
1619
1720
- run:
1821
name: Version information
@@ -45,9 +48,11 @@ jobs:
4548
# rustup run stable rustc --version --verbose
4649
# rustup run stable cargo --version --verbose
4750
# rustup run stable cargo build
48-
# - run:
49-
# name: Test
50-
# command: rustup run stable cargo test
51+
- run:
52+
name: Test
53+
command: |
54+
pip install -r ./test/pytest/requirements.txt
55+
python ./test/pytest/test.py
5156
# - run:
5257
# name: Upload Coverage
5358
# command: ./scripts/codecov.sh
@@ -57,6 +62,6 @@ jobs:
5762
- "~/.cargo"
5863
- "./target"
5964

60-
- run:
61-
name: Run all tests
62-
command: cargo test --all
65+
# - run:
66+
# name: Run all tests
67+
# command: cargo test --all

.gitmodules

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[submodule "redismodule-rs"]
2-
path = redismodule-rs
3-
url = https://github.com/RedisLabsModules/redismodule-rs
2+
path = redismodule-rs
3+
url = https://github.com/RedisLabsModules/redismodule-rs
4+
branch = cryptorelay-picks

src/index.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
pub(crate) trait Index {
2+
fn normalize(self, len: i64) -> usize;
3+
}
4+
5+
impl Index for i64 {
6+
fn normalize(self, len: i64) -> usize {
7+
let index = if self < 0 {
8+
len - len.min(-self)
9+
} else {
10+
(len - 1).min(self)
11+
};
12+
index as usize
13+
}
14+
}
15+
16+
#[cfg(test)]
17+
mod tests {
18+
use super::*;
19+
20+
#[test]
21+
fn test_index() {
22+
// [0,1,2,3,4]
23+
assert_eq!((-6).normalize(5), 0);
24+
assert_eq!((-5).normalize(5), 0);
25+
assert_eq!((-2).normalize(5), 3);
26+
assert_eq!((-1).normalize(5), 4);
27+
assert_eq!(0.normalize(5), 0);
28+
assert_eq!(1.normalize(5), 1);
29+
assert_eq!(4.normalize(5), 4);
30+
assert_eq!(5.normalize(5), 4);
31+
assert_eq!(6.normalize(5), 4);
32+
}
33+
}

0 commit comments

Comments
 (0)