diff options
author | laixintao <laixintaoo@gmail.com> | 2022-06-24 00:37:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-24 00:37:39 +0800 |
commit | ac637de3fcc3aecfa64b5226ffcb0f43a87c07db (patch) | |
tree | 1e382d749435f9af1526e9bfb4b3a4811537f326 | |
parent | 6a87dbce3ee3b9adbb5f37c4de77b507ad676bf8 (diff) | |
parent | 49318617349ca660eccbede75799c655263e26a3 (diff) |
Merge pull request #429 from laixintao/update-commands
new commands: eval and failover and geo related commands
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | iredis/data/command_syntax.csv | 8 | ||||
-rw-r--r-- | iredis/redis_grammar.py | 41 | ||||
-rw-r--r-- | tests/unittests/command_parse/test_geo.py | 30 | ||||
-rw-r--r-- | tests/unittests/command_parse/test_server.py | 45 |
5 files changed, 86 insertions, 45 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 85f1e14..12c217c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ - Feature: `CLIENT TRACKING` support multiple prefixes. - Feature: support new command: `CLIENT TRACKINGINFO`. - Feature: support new command: `COPY`. +- Feature: support new command: `EVAL_RO` and `EVALSHA_RO`. +- Feature: support new command: `EXPIRETIME`. +- Feature: support new command: `FAILOVER`. +- Feature: `FLUSHDB` and `FLUSHALL` supports `SYNC` option. +- Feature: `GEOADD` supports `CH XX NX` options. +- Deprecate: `GEORADIUS` is deprecated, no auto-complete for this command anymore. +- Deprecate: `GEORADIUSBYMEMBER` is deprecated, no auto-complete for this command anymore. ## 1.11.1 diff --git a/iredis/data/command_syntax.csv b/iredis/data/command_syntax.csv index 3fd2a4f..560867a 100644 --- a/iredis/data/command_syntax.csv +++ b/iredis/data/command_syntax.csv @@ -49,6 +49,7 @@ generic,DUMP,command_key,render_bulk_string generic,EXISTS,command_keys,render_int generic,EXPIRE,command_key_second,render_int generic,EXPIREAT,command_key_timestamp,render_int +generic,EXPIRETIME,command_key,render_int generic,KEYS,command_pattern,command_keys generic,MIGRATE,command_migrate,render_simple_string generic,MOVE,command_key_index,render_int @@ -72,8 +73,8 @@ geo,GEOADD,command_key_longitude_latitude_members,render_int geo,GEODIST,command_geodist,render_bulk_string geo,GEOHASH,command_key_members,render_list geo,GEOPOS,command_key_members,render_list -geo,GEORADIUS,command_radius,render_list_or_string -geo,GEORADIUSBYMEMBER,command_georadiusbymember,render_list_or_string +geo,GEORADIUS,command_any,render_list_or_string +geo,GEORADIUSBYMEMBER,command_any,render_list_or_string hash,HDEL,command_key_fields,render_int hash,HEXISTS,command_key_field,render_int hash,HGET,command_key_field,render_bulk_string @@ -118,7 +119,9 @@ pubsub,PUNSUBSCRIBE,command_channels,render_subscribe pubsub,SUBSCRIBE,command_channels,render_subscribe pubsub,UNSUBSCRIBE,command_channels,render_subscribe scripting,EVAL,command_lua_any,render_list_or_string +scripting,EVAL_RO,command_lua_any,render_list_or_string scripting,EVALSHA,command_any,render_list_or_string +scripting,EVALSHA_RO,command_any,render_list_or_string scripting,SCRIPT DEBUG,command_scriptdebug,render_simple_string scripting,SCRIPT EXISTS,command_any,render_list scripting,SCRIPT FLUSH,command,render_simple_string @@ -150,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 06a24d6..d9869fb 100644 --- a/iredis/redis_grammar.py +++ b/iredis/redis_grammar.py @@ -32,7 +32,7 @@ CONST = { "type": "string list set zset hash stream", "position_choice": "BEFORE AFTER", "error": "TIMEOUT ERROR", - "async": "ASYNC", + "async": "ASYNC SYNC", "conntype": "NORMAL MASTER REPLICA PUBSUB", "samples": "SAMPLES", "slotsubcmd": "IMPORTING MIGRATING NODE STABLE", @@ -135,6 +135,9 @@ CONST = { "pause_type": "WRITE ALL", "db_const": "DB", "replace_const": "REPLACE", + "to_const": "TO", + "timeout_const": "TIMEOUT", + "abort_const": "ABORT", } @@ -218,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 @@ -230,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})" @@ -353,6 +355,9 @@ LR_CONST = rf"(?P<lr_const>{c('lr_const')})" 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) @@ -364,14 +369,6 @@ command_grammar = compile(COMMAND) GRAMMAR = { "command_key": rf"\s+ {KEY} \s*", "command_pattern": rf"\s+ {PATTERN} \s*", - "command_georadiusbymember": rf""" - \s+ {KEY} \s+ {MEMBER} - \s+ {FLOAT} \s+ {DISTUNIT} - (\s+ {GEOCHOICE})* - (\s+ {COUNT_CONST} \s+ {COUNT})? - (\s+ {ORDER})? - (\s+ {CONST_STORE} \s+ {KEY})? - (\s+ {CONST_STOREDIST} \s+ {KEY})? \s*""", "command_command": rf"\s+ {COMMAND} \s*", "command_slots": rf"\s+ {SLOTS} \s*", "command_node": rf"\s+ {NODE} \s*", @@ -449,7 +446,11 @@ GRAMMAR = { "command_key_members": rf"\s+ {KEY} \s+ {MEMBERS} \s*", "command_geodist": rf"\s+ {KEY} \s+ {MEMBER} \s+ {MEMBER} (\s+ {DISTUNIT})? \s*", "command_key_longitude_latitude_members": rf""" - \s+ {KEY} (\s+ {LONGITUDE} \s+ {LATITUDE} \s {MEMBER})+ \s*""", + \s+ {KEY} + (\s+ {CONDITION})? + (\s+ {CHANGED})? + (\s+ {LONGITUDE} \s+ {LATITUDE} \s {MEMBER})+ + \s*""", "command_destination_keys": rf"\s+ {DESTINATION} \s+ {KEYS} \s*", "command_object_key": rf"\s+ {OBJECT} \s+ {KEY} \s*", "command_key_member": rf"\s+ {KEY} \s+ {MEMBER} \s*", @@ -504,12 +505,6 @@ GRAMMAR = { )? (\s+ {CONST_KEYS} \s+ {KEYS})? \s*""", - "command_radius": rf"""\s+ {KEY} - \s+ {LONGITUDE} \s+ {LATITUDE} \s+ {FLOAT} \s+ {DISTUNIT} - (\s+ {GEOCHOICE})* (\s+ {COUNT_CONST} \s+ {COUNT})? - (\s+ {ORDER})? - (\s+ {CONST_STORE} \s+ {KEY})? - (\s+ {CONST_STOREDIST} \s+ {KEY})? \s*""", "command_restore": rf"""\s+ {KEY} \s+ {TIMEOUT} \s+ {VALUE} (\s+ {SUBRESTORE} \s+ {SECOND})? \s*""", "command_pubsubcmd_channels": rf"\s+ {PUBSUBCMD} (\s+ {CHANNEL})+ \s*", @@ -646,6 +641,12 @@ GRAMMAR = { (\s+ {DB_CONST} \s+ {INDEX})? (\s+ {REPLACE_CONST})? \s*""", + "command_failover": rf""" + (\s+ {TO_CONST} \s+ {HOST} \s+ {PORT} (\s+ {FORCE})? )? + (\s+ {ABORT_CONST})? + (\s+ {TIMEOUT_CONST} \s+ {MILLISECOND})? + + \s*""", } pipeline = r"(?P<shellcommand>\|.*)?" diff --git a/tests/unittests/command_parse/test_geo.py b/tests/unittests/command_parse/test_geo.py index 8a8d4c7..ba9c3fd 100644 --- a/tests/unittests/command_parse/test_geo.py +++ b/tests/unittests/command_parse/test_geo.py @@ -9,31 +9,15 @@ def test_geoadd(judge_command): "member": '"Catania"', }, ) - - -def test_georadiusbymember(judge_command): judge_command( - "GEORADIUSBYMEMBER Sicily Agrigento 100 km", + 'GEOADD Sicily NX CH 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"', { - "command": "GEORADIUSBYMEMBER", - "key": "Sicily", - "member": "Agrigento", - "float": "100", - "distunit": "km", - }, - ) - - -def test_georadius(judge_command): - judge_command( - "GEORADIUS Sicily 15 37 200 km WITHDIST WITHCOORD ", - { - "command": "GEORADIUS", + "command": "GEOADD", + "condition": "NX", + "changed": "CH", "key": "Sicily", - "longitude": "15", - "latitude": "37", - "float": "200", - "distunit": "km", - "geochoice": "WITHCOORD", + "longitude": "15.087269", + "latitude": "37.502669", + "member": '"Catania"', }, ) diff --git a/tests/unittests/command_parse/test_server.py b/tests/unittests/command_parse/test_server.py index 817068b..5ecccbf 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": "force", + "host": "10.0.0.5", + "port": "7379", + "abort_const": "abort", + "timeout_const": "timeout", + "millisecond": "101", + }, + ) |