Skip to content

Commit

Permalink
MOD: sirange(sirevrange) syntax opti , add cursor keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
karelrooted committed Sep 3, 2019
1 parent 1a62f28 commit cf0b630
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions docs/support-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@

| Command | Supported OR Not | Desc |
| ------------ | ---------------- | ---- |
| sicard || like scard |
| siadd || like sadd, but member is int |
| sirem || like srem, but member is int |
| sirange || sirange key offset count since_id |
| sirevrange || sirevrange key offset count max_id |
| sicard || like scard |
| siadd || like sadd, but member is int |
| sirem || like srem, but member is int |
| sirange || sirange key offset count cursor since_id |
| sirevrange || sirevrange key offset count cursor max_id |

## Administrator Commands

Expand Down
7 changes: 5 additions & 2 deletions src/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2522,8 +2522,11 @@ class CommandSortedintRange : public Commander {
try {
offset_ = std::stoi(args[2]);
limit_ = std::stoi(args[3]);
if (args.size() == 5) {
cursor_id_ = std::stoull(args[4]);
if (args.size() == 6) {
if (args[4] != "cursor") {
return Status(Status::RedisParseErr, "syntax error");
}
cursor_id_ = std::stoull(args[5]);
}
} catch (const std::exception &e) {
return Status(Status::RedisParseErr, kValueNotInterger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_sicard():
def test_sirange():
conn = get_redis_conn()
key = "test_sirange"
ret = conn.delete(key)
ret = conn.execute_command("siadd", key, 1, 2, 3, 4, 60, 231, 9999)
assert (ret == 7)
ret = conn.execute_command("sirange", key, 0, 20)
Expand All @@ -45,7 +46,7 @@ def test_sirange():
assert (ret == ['1', '2'])
ret = conn.execute_command("sirange", key, 3, 2)
assert (ret == ['4', '60'])
ret = conn.execute_command("sirange", key, 0, 2, 3)
ret = conn.execute_command("sirange", key, 0, 2, "cursor", 3)
assert (ret == ['4', '60'])

ret = conn.delete(key)
Expand All @@ -55,6 +56,7 @@ def test_sirange():
def test_sirevrange():
conn = get_redis_conn()
key = "test_sirevrange"
ret = conn.delete(key)
ret = conn.execute_command("siadd", key, 1, 2, 3, 4, 60, 231, 9999)
assert (ret == 7)
ret = conn.execute_command("sirevrange", key, 0, 20)
Expand All @@ -63,7 +65,7 @@ def test_sirevrange():
assert (ret == ['9999', '231'])
ret = conn.execute_command("sirevrange", key, 3, 2)
assert (ret == ['4', '3'])
ret = conn.execute_command("sirevrange", key, 0, 2, 3)
ret = conn.execute_command("sirevrange", key, 0, 2, "cursor", 3)
assert (ret == ['2', '1'])

ret = conn.delete(key)
Expand Down

0 comments on commit cf0b630

Please sign in to comment.