diff options
author | laixintao <laixintaoo@gmail.com> | 2022-06-23 15:45:19 +0800 |
---|---|---|
committer | laixintao <laixintaoo@gmail.com> | 2022-06-23 15:45:19 +0800 |
commit | 27d6c5e1f54a73d42c121812525fcd87346751db (patch) | |
tree | 5afdc1095c24fb357d43e900d030f2154218ca4c | |
parent | fe75d532a21c3b5b3f1dfeba807cc2cde874ff67 (diff) |
support failover.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | iredis/data/command_syntax.csv | 1 | ||||
-rw-r--r-- | iredis/redis_grammar.py | 19 | ||||
-rw-r--r-- | tests/unittests/command_parse/test_server.py | 45 |
4 files changed, 58 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 79d5177..5152532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Feature: support new command: `COPY`. - Feature: support new command: `EVAL_RO` and `EVALSHA_RO`. - Feature: support new command: `EXPIRETIME`. +- Feature: support new command: `FAILOVER`. ## 1.11.1 diff --git a/iredis/data/command_syntax.csv b/iredis/data/command_syntax.csv index 06d9cd5..9f0ac71 100644 --- a/iredis/data/command_syntax.csv +++ b/iredis/data/command_syntax.csv @@ -153,6 +153,7 @@ server,CONFIG SET,command_parameter_value,render_simple_string server,DBSIZE,command,render_int server,DEBUG OBJECT,command_key,render_simple_string server,DEBUG SEGFAULT,command,render_simple_string +server,FAILOVER,command_failover,render_simple_string server,FLUSHALL,command_asyncx,render_simple_string server,FLUSHDB,command_asyncx,render_simple_string server,INFO,command_sectionx,render_bulk_string_decode diff --git a/iredis/redis_grammar.py b/iredis/redis_grammar.py index d68bf63..3d7967a 100644 --- a/iredis/redis_grammar.py +++ b/iredis/redis_grammar.py @@ -136,6 +136,8 @@ CONST = { "db_const": "DB", "replace_const": "REPLACE", "to_const": "TO", + "timeout_const": "TIMEOUT", + "abort_const": "ABORT", } @@ -219,7 +221,7 @@ SECOND = rf"(?P<second>{NUM})" TIMESTAMP = rf"(?P<timestamp>{NUM})" # TODO test lexer & completer for multi spaces in command # For now, redis command can have one space at most -COMMAND = "(\s* (?P<command>[\w -]+))" +COMMAND = r"(\s* (?P<command>[\w -]+))" MILLISECOND = rf"(?P<millisecond>{NUM})" TIMESTAMPMS = rf"(?P<timestampms>{NUM})" ANY = r"(?P<any>.*)" # TODO deleted @@ -231,15 +233,14 @@ END = rf"(?P<end>{NNUM})" # https://redis.io/topics/streams-intro#special-ids-in-the-streams-api # stream id, DO NOT use r"" here, or the \+ will be two string # NOTE: if miss the outer (), multi IDS won't work. -STREAM_ID = "(?P<stream_id>[T\d:>+*\-\$]+)" +STREAM_ID = r"(?P<stream_id>[T\d:>+*\-\$]+)" DELTA = rf"(?P<delta>{NNUM})" OFFSET = rf"(?P<offset>{NUM})" # string offset, can't be negative -SHARP_OFFSET = f"(?P<offset>\#?{NUM})" # for bitfield command +SHARP_OFFSET = rf"(?P<offset>\#?{NUM})" # for bitfield command MIN = rf"(?P<min>{NNUM})" MAX = rf"(?P<max>{NNUM})" POSITION = rf"(?P<position>{NNUM})" -TIMEOUT = rf"(?P<timeout>{NUM})" SCORE = rf"(?P<score>{_FLOAT})" LEXMIN = rf"(?P<lexmin>{LEXNUM})" LEXMAX = rf"(?P<lexmax>{LEXNUM})" @@ -355,6 +356,8 @@ PAUSE_TYPE = rf"(?P<pause_type>{c('pause_type')})" DB_CONST = rf"(?P<db_const>{c('db_const')})" REPLACE_CONST = rf"(?P<replace_const>{c('replace_const')})" TO_CONST = rf"(?P<to_const>{c('to_const')})" +TIMEOUT_CONST = rf"(?P<timeout_const>{c('timeout_const')})" +ABORT_CONST = rf"(?P<abort_const>{c('abort_const')})" command_grammar = compile(COMMAND) @@ -649,10 +652,10 @@ GRAMMAR = { (\s+ {REPLACE_CONST})? \s*""", "command_failover": rf""" - (\s+ {TO_CONST} \s+ {HOST} \s+ {PORT} )? - (\s+ {LEN_CONST})? - (\s+ {MINMATCHLEN_CONST} \s+ {LEN})? - (\s+ {WITHMATCHLEN_CONST})? + (\s+ {TO_CONST} \s+ {HOST} \s+ {PORT} (\s+ {FORCE})? )? + (\s+ {ABORT_CONST})? + (\s+ {TIMEOUT_CONST} \s+ {MILLISECOND})? + \s*""", } diff --git a/tests/unittests/command_parse/test_server.py b/tests/unittests/command_parse/test_server.py index 817068b..7fc4c00 100644 --- a/tests/unittests/command_parse/test_server.py +++ b/tests/unittests/command_parse/test_server.py @@ -225,3 +225,48 @@ def test_acl_setuser(judge_command): def test_acl_getuser(judge_command): judge_command("acl getuser alan", {"command": "acl getuser", "username": "alan"}) judge_command("acl getuser", None) + + +def test_failover(judge_command): + judge_command( + "failover to 10.0.0.5 7379 abort timeout 101", + { + "command": "failover", + "to_const": "to", + "host": "10.0.0.5", + "port": "7379", + "abort_const": "abort", + "timeout_const": "timeout", + "millisecond": "101", + }, + ) + judge_command( + "failover abort timeout 101", + { + "command": "failover", + "abort_const": "abort", + "timeout_const": "timeout", + "millisecond": "101", + }, + ) + judge_command( + "failover timeout 101", + { + "command": "failover", + "timeout_const": "timeout", + "millisecond": "101", + }, + ) + judge_command( + "failover to 10.0.0.5 7379 force abort timeout 101", + { + "command": "failover", + "to_const": "to", + "force_const": "force", + "host": "10.0.0.5", + "port": "7379", + "abort_const": "abort", + "timeout_const": "timeout", + "millisecond": "101", + }, + ) |