Skip to content

Commit

Permalink
Merge pull request #175 from laixintao/server-commands
Browse files Browse the repository at this point in the history
Finish supporting all server commands.
  • Loading branch information
laixintao authored Dec 22, 2019
2 parents fc4f2f3 + a549273 commit 613b21a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.1
current_version = 0.3.2
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion iredis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from pathlib import Path

__version__ = "0.3.1"
__version__ = "0.3.2"


logging.basicConfig(
Expand Down
27 changes: 24 additions & 3 deletions iredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
from redis.connection import Connection
from redis.exceptions import TimeoutError, ConnectionError
from prompt_toolkit.formatted_text import FormattedText
from prompt_toolkit import print_formatted_text

from . import renders
from . import markdown
from . import utils, project_path
from .config import config
from .commands_csv_loader import all_commands, command2callback, commands_summary
from .utils import nativestr, split_command_args, _strip_quote_args
from .utils import compose_command_syntax
from .renders import render_error
from .completers import LatestUsedFirstWordCompleter
from . import markdown
from .utils import compose_command_syntax
from .exceptions import NotRedisCommand
from . import utils, project_path
from .style import STYLE

logger = logging.getLogger(__name__)
CLIENT_COMMANDS = ["HELP"]
Expand Down Expand Up @@ -148,6 +150,18 @@ def render_response(self, response, completer, command_name, **options):
rendered = self.render_command_result(command_name, response, completer)
return rendered

def monitor(self):
"""Redis' MONITOR command:
https://redis.io/commands/monitor
This command need to read from a stream resp, so
it's different
"""
# FIXME maybe need to make this a generator, use yield
# for pubsub and stream
while 1:
response = self.connection.read_response()
print(response)

def send_command(self, raw_command, completer):
"""
Send raw_command to redis-server, return parsed response.
Expand All @@ -169,6 +183,13 @@ def send_command(self, raw_command, completer):
completer, command_name, *args
)
self.after_hook(raw_command, command_name, args, completer)
if command_name.upper() == "MONITOR":
logger.info("monitor")
print_formatted_text(redis_resp, style=STYLE)
try:
self.monitor()
except KeyboardInterrupt:
return
except Exception as e:
logger.exception(e)
return render_error(str(e))
Expand Down
12 changes: 6 additions & 6 deletions iredis/data/command_syntax.csv
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,23 @@ server,COMMAND COUNT,command,render_int
server,COMMAND GETKEYS,command_any,render_list
server,COMMAND INFO,command_commandname,render_list
server,CONFIG GET,command_parameter,render_nested_pair
server,CONFIG RESETSTAT,command_pass,
server,CONFIG REWRITE,command_pass,
server,CONFIG RESETSTAT,command,render_simple_string
server,CONFIG REWRITE,command,render_simple_string
server,CONFIG SET,command_parameter_value,render_simple_string
server,DBSIZE,command,render_int
server,DEBUG OBJECT,command_pass,
server,DEBUG SEGFAULT,command_pass,
server,DEBUG OBJECT,command_key,render_simple_string
server,DEBUG SEGFAULT,command,render_simple_string
server,FLUSHALL,command_asyncx,render_simple_string
server,FLUSHDB,command_asyncx,render_simple_string
server,INFO,command,render_bulk_string_decode
server,LASTSAVE,command,render_unixtime
server,MEMORY DOCTOR,command,render_bulk_string_decode
server,MEMORY HELP,command,render_list
server,MEMORY MALLOC-STATS,command_pass,
server,MEMORY MALLOC-STATS,command,render_bulk_string_decode
server,MEMORY PURGE,command,render_simple_string
server,MEMORY STATS,command,render_nested_pair
server,MEMORY USAGE,command_key_samples_count,render_int
server,MONITOR,command_pass,
server,MONITOR,command,render_simple_string
server,REPLICAOF,command_any,render_simple_string
server,ROLE,command,
server,SAVE,command,render_simple_string
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "iredis"
version = "0.3.1"
version = "0.3.2"
description = "Terminal Client for Redis with AutoCompletion and Syntax Highlighting."
authors = ["laixintao <laixintao1995@163.com>"]
readme = 'README.md'
Expand Down
1 change: 1 addition & 0 deletions scripts/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
port 7379

0 comments on commit 613b21a

Please sign in to comment.