summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaixintao <laixintaoo@gmail.com>2021-11-22 23:46:02 +0800
committerlaixintao <laixintaoo@gmail.com>2022-06-22 23:32:48 +0800
commit0292919c2a73826a38b9475a6084b4f245d0668c (patch)
tree970cdc2f55dba1c2051ba2623dd595d1d151df8c
parentd548818b25ef361d77dbc0f5b79ee2ddd1b90a5c (diff)
support BLMOVE command.
-rw-r--r--CHANGELOG.md1
-rw-r--r--iredis/data/command_syntax.csv1
-rw-r--r--iredis/redis_grammar.py7
-rw-r--r--tests/unittests/command_parse/test_base_token.py12
-rw-r--r--tests/unittests/command_parse/test_list_parse.py29
5 files changed, 50 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f5797b..4ec29b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@
- Support new command in Redis:
- `ACL GETUSER`
- `ACL HELP`
+ - `BLMOVE`
### 1.9.4
diff --git a/iredis/data/command_syntax.csv b/iredis/data/command_syntax.csv
index f07a05f..a7d8cfb 100644
--- a/iredis/data/command_syntax.csv
+++ b/iredis/data/command_syntax.csv
@@ -88,6 +88,7 @@ hash,HVALS,command_key,render_list
hyperloglog,PFADD,command_key_values,render_int
hyperloglog,PFCOUNT,command_keys,render_int
hyperloglog,PFMERGE,command_newkey_keys,render_simple_string
+list,BLMOVE,command_key_key_lr_lr_timeout, render_bulk_string
list,BLPOP,command_keys_timeout,render_list_or_string
list,BRPOP,command_keys_timeout,render_list_or_string
list,BRPOPLPUSH,command_key_newkey_timeout,render_bulk_string
diff --git a/iredis/redis_grammar.py b/iredis/redis_grammar.py
index 9c56ee4..db2aa6b 100644
--- a/iredis/redis_grammar.py
+++ b/iredis/redis_grammar.py
@@ -130,6 +130,7 @@ CONST = {
"withmatchlen_const": "WITHMATCHLEN",
"strings_const": "STRINGS",
"rank_const": "RANK",
+ "lr_const": "LEFT RIGHT",
}
@@ -340,6 +341,8 @@ WITHMATCHLEN_CONST = rf"(?P<withmatchlen_const>{c('withmatchlen_const')})"
STRINGS_CONST = rf"(?P<strings_const>{c('strings_const')})"
RANK_CONST = rf"(?P<rank_const>{c('rank_const')})"
+LR_CONST = fr"(?P<lr_const>{c('lr_const')})"
+
command_grammar = compile(COMMAND)
# Here are the core grammars, those are tokens after ``command``.
@@ -618,6 +621,10 @@ GRAMMAR = {
(\s+ {MAXLEN} \s+ {LEN})
)*
\s*""",
+ "command_key_key_lr_lr_timeout": fr"""
+ \s+ {KEY} \s+ {KEY}
+ \s+ {LR_CONST} \s+ {LR_CONST}
+ \s+ {TIMEOUT} \s*""",
}
pipeline = r"(?P<shellcommand>\|.*)?"
diff --git a/tests/unittests/command_parse/test_base_token.py b/tests/unittests/command_parse/test_base_token.py
index 6a233cb..545bc92 100644
--- a/tests/unittests/command_parse/test_base_token.py
+++ b/tests/unittests/command_parse/test_base_token.py
@@ -66,3 +66,15 @@ def test_timeout(token_should_match, token_should_not_match):
token_should_not_match(TIMEOUT, "1.")
token_should_not_match(TIMEOUT, ".")
token_should_not_match(TIMEOUT, ".a")
+
+
+def test_lr_const(token_should_match, token_should_not_match):
+ from iredis.redis_grammar import LR_CONST
+
+ token_should_match(LR_CONST, "left")
+ token_should_match(LR_CONST, "right")
+ token_should_match(LR_CONST, "LEFT")
+ token_should_match(LR_CONST, "RIGHT")
+ token_should_not_match(LR_CONST, "righ")
+ token_should_not_match(LR_CONST, "ab")
+ token_should_not_match(LR_CONST, "123")
diff --git a/tests/unittests/command_parse/test_list_parse.py b/tests/unittests/command_parse/test_list_parse.py
index d062abf..8ed3890 100644
--- a/tests/unittests/command_parse/test_list_parse.py
+++ b/tests/unittests/command_parse/test_list_parse.py
@@ -118,3 +118,32 @@ def test_lpos(judge_command):
"rank": "-1",
},
)
+
+
+def test_blmove(judge_command):
+ judge_command(
+ "blmove list1 list2 left right 1.2",
+ {
+ "command": "blmove",
+ "key": ["list1", "list2"],
+ "lr_const": ["left", "right"],
+ "timeout": "1.2",
+ },
+ )
+ judge_command(
+ "blmove list1 list2 right right .2",
+ {
+ "command": "blmove",
+ "key": ["list1", "list2"],
+ "lr_const": ["right", "right"],
+ "timeout": ".2",
+ },
+ )
+ judge_command(
+ "blmove list1 list2 right right",
+ None
+ )
+ judge_command(
+ "blmove list1 right right 1",
+ None
+ )