目录
Features 特征
Install 安装
Pip
Brew
Linux的
Download Binary 下载 Binary
Usage 用法
Using DSN 使用 DSN
Change The Default Prompt更改默认提示
Configuration 配置
Keys
Development 发展
Release Strategy 发布策略
Setup Environment 设置环境
Development Logs 开发日志
Catch Up with Latest Redis-doc了解最新的 Redis-doc
Related Projects 相关项目
先放链接:
laixintao/iredis: Interactive Redis: A Terminal Client for Redis with AutoCompletion and Syntax Highlighting.
最近学习redis ,因为在linux下,redis的代码提示和输入代码颜色没有区分,使用起来不太方便,今天周末 不是很忙,想着搜索解决一下
原来:
期间也尝试了rlwrap的设置方法,但可能因为环境问题,无法很好的解决补全的显示,要自己写脚本设计什么的,倒腾了几个小时,发现设计的也达不到理想的效果qwq,然后,我就在想,会不会有大佬写过呢(●'◡'●),于是就发现了iredis~~真的!就是说!超级丝滑!啊啊啊啊啊 在linux上学习redis的初学者 快!安!它!
为了发扬 iredis,让有需要的uu可以在环境配置上少走弯路,我把它翻译过来了
配置后的效果:(理想的效果 对 就是我写脚本 想达到的效果/(ㄒoㄒ)/
Interactive Redis: A Cli for Redis with AutoCompletion and Syntax Highlighting.
交互式 Redis:具有自动完成和语法突出显示功能的 Redis CLI 。
IRedis is a terminal client for redis with auto-completion and syntax highlighting. IRedis lets you type Redis commands smoothly, and displays results in a user-friendly format.
IRedis 是具有自动完成和语法高亮功能的 redis 终端客户端。IRedis 允许您流畅地键入 Redis 命令,并以用户友好的格式显示结果。
IRedis is an alternative for redis-cli. In most cases, IRedis behaves exactly the same as redis-cli. Besides, it is safer to use IRedis on production servers than redis-cli: IRedis will prevent accidentally running dangerous commands, like KEYS *
(see Redis docs / Latency generated by slow commands).
IRedis 是 redis-cli 的替代方案。在大多数情况下,IRedis 的行为与 redis-cli 完全相同。此外,在生产服务器上使用 IRedis 比 redis-cli 更安全:IRedis 可以防止意外运行危险的命令,例如 KEYS *
(参见 Redis 文档 / 慢速命令产生的延迟)。
Features 特征
- Advanced code completion. If you run command
KEYS
then runDEL
, IRedis will auto-complete your command based onKEYS
result.
高级代码完成。如果你运行命令KEYS
然后运行DEL
,IRedis 将根据KEYS
结果自动完成你的命令。 - Command validation. IRedis will validate command while you are typing, and highlight errors. E.g. try
CLUSTER MEET IP PORT
, IRedis will validate IP and PORT for you.
命令验证。IRedis 将在您键入时验证命令,并突出显示错误。例如,tryCLUSTER MEET IP PORT
,IRedis 将为您验证 IP 和 PORT。 - Command highlighting, fully based on redis grammar. Any valid command in IRedis shell is a valid redis command.
命令高亮,完全基于 redis 语法。IRedis shell 中的任何有效命令都是有效的 redis 命令。 - Human-friendly result display.
人性化的结果显示。 - pipeline feature, you can use your favorite shell tools to parse redis' response, like
get json | jq .
.
pipeline 功能,你可以使用自己喜欢的 shell 工具来解析 Redis 的响应,比如get json | jq .
。 - Support pager for long output.
支持长输出的寻呼机。 - Support connection via URL,
iredis --url redis://example.com:6379/1
.
支持通过 URLiredis --url redis://example.com:6379/1
进行连接。 - Support cluster, IRedis will auto reissue command for
MOVED
response in cluster mode.
支持集群,IRedis 会在集群模式下自动重新发出MOVED
响应的命令。 - Store server configuration:
iredis -d prod-redis
(see dsn for more).
存储服务器配置:iredis -d prod-redis
(有关详细信息,请参阅 dsn)。 peek
command to check the key's type then automatically callget
/lrange
/sscan
, etc, depending on types. You don't need to call thetype
command then type another command to get the value.peek
will also display the key's length and memory usage.peek
命令检查键的类型,然后根据类型自动调用get
/lrange
/sscan
等。您无需调用type
命令,然后键入另一个命令即可获取该值。peek
还将显示密钥的长度和内存使用情况。- Ctrl + C to cancel the current typed command, this won't exit IRedis, exactly like bash behaviour. Use Ctrl + D to send a EOF to exit IRedis.
Ctrl + C 取消当前键入的命令,这不会退出 IRedis,就像 bash 行为一样。使用 Ctrl + D 发送 EOF 以退出 IRedis。 - Ctrl + R to open reverse-i-search to search through your command history.
Ctrl + R 打开 reverse-i-search 以搜索您的命令历史记录。 - Auto suggestions. (Like fish shell.)
自动建议。(就像鱼壳一样。 - Support
--encode=utf-8
, to decode Redis' bytes responses.
支持--encode=utf-8
来解码 Redis 的字节响应。 - Command hint on bottom, include command syntax, supported redis version, and time complexity.
命令提示位于底部,包括命令语法、支持的 redis 版本和时间复杂度。 - Official docs with built-in
HELP
command, tryHELP SET
!
内置HELP
命令的官方文档,试试HELP SET
! - Written in pure Python, but IRedis was packaged into a single binary with PyOxidizer, you can use cURL to download and run, it just works, even you don't have a Python interpreter.
用纯 Python 编写,但 IRedis 与 PyOxidizer 打包成单个二进制文件,您可以使用 cURL 下载和运行,即使您没有 Python 解释器,它也可以工作。 - You can change the cli prompt using
--prompt
option or set via~/.iredisrc
config file.
您可以使用--prompt
选项或通过~/.iredisrc
配置文件更改 cli 提示符。 - Hide password for
AUTH
command.
隐藏AUTH
命令的密码。 - Says "Goodbye!" to you when you exit!
当你离开时对你说 “再见! - For full features, please see: iredis.xbin.io
有关完整功能,请参阅:iredis.xbin.io
Install 安装
Pip
Install via pip: 通过 pip 安装:
pip install iredis
pipx is recommended:
建议使用 pipx:
pipx install iredis
Brew
For Mac users, you can install iredis via brew 🍻
对于 Mac 用户,您可以通过 brew 🍻 安装 iredis
brew install iredis
Linux的
You can also use your Linux package manager to install IRedis, like apt
in Ubuntu (Only available on Ubuntu 21.04+).
您还可以使用 Linux 包管理器安装 IRedis,例如 Ubuntu 中的 apt
(仅适用于 Ubuntu 21.04+)。
apt install iredis
Download Binary 下载 Binary
Or you can download the executable binary with cURL(or wget), untar, then run. It is especially useful when you don't have a python interpreter(E.g. the official Redis docker image which doesn't have Python installed.):
或者,您可以使用 cURL(或 wget)下载可执行二进制文件,解压,然后运行。当您没有 python 解释器时(例如,没有安装 Python 的官方 Redis docker 镜像)尤其有用。
wget https://github.com/laixintao/iredis/releases/latest/download/iredis.tar.gz \
&& tar -xzf iredis.tar.gz \
&& ./iredis
(Check the release page if you want to download an old version of IRedis.)
(如果您想下载旧版本的 IRedis,请查看发布页面。
Usage 用法
Once you install IRedis, you will know how to use it. Just remember, IRedis supports similar options like redis-cli, like -h
for redis-server's host and -p
for port.
安装 IRedis 后,您将知道如何使用它。请记住,IRedis 支持与 redis-cli 类似的选项,例如 -h
用于 redis-server 的主机,-p
用于端口。
$ iredis --help
Usage: iredis [OPTIONS] [CMD]...
IRedis: Interactive Redis
When no command is given, IRedis starts in interactive mode.
Examples:
- iredis
- iredis -d dsn
- iredis -h 127.0.0.1 -p 6379
- iredis -h 127.0.0.1 -p 6379 -a <password>
- iredis --url redis://localhost:7890/3
Type "help" in interactive mode for information on available commands and
settings.
Options:
-h TEXT Server hostname (default: 127.0.0.1).
-p TEXT Server port (default: 6379).
-s, --socket TEXT Server socket (overrides hostname and port).
-n INTEGER Database number.(overwrites dsn/url's db
number)
-u, --username TEXT User name used to auth, will be ignore for
redis version < 6.
-a, --password TEXT Password to use when connecting to the
server.
--url TEXT Use Redis URL to indicate connection(Can set
with env `IREDIS_URL`), Example: redis:/
/[[username]:[password]]@localhost:6379/0
rediss://[[username]:[password]]@localhost:6
379/0 unix://[[username]:[password]]@/pa
th/to/socket.sock?db=0
-d, --dsn TEXT Use DSN configured into the [alias_dsn]
section of iredisrc file. (Can set with env
`IREDIS_DSN`)
--newbie / --no-newbie Show command hints and useful helps.
--iredisrc TEXT Config file for iredis, default is
~/.iredisrc.
--decode TEXT decode response, default is No decode, which
will output all bytes literals.
--client_name TEXT Assign a name to the current connection.
--raw / --no-raw Use raw formatting for replies (default when
STDOUT is not a tty). However, you can use
--no-raw to force formatted output even when
STDOUT is not a tty.
--rainbow / --no-rainbow Display colorful prompt.
--shell / --no-shell Allow to run shell commands, default to
True.
--pager / --no-pager Using pager when output is too tall for your
window, default to True.
--verify-ssl [none|optional|required]
Set the TLS certificate verification
strategy
--prompt TEXT Prompt format (supported interpolations:
{client_name}, {db}, {host}, {path}, {port},
{username}, {client_addr}, {client_id}).
--version Show the version and exit.
--help Show this message and exit.
Using DSN 使用 DSN
IRedis support storing server configuration in config file. Here is a DSN config:
IRedis 支持将服务器配置存储在配置文件中。以下是 DSN 配置:
[alias_dsn]
dev=redis://localhost:6379/4
staging=redis://username:password@staging-redis.example.com:6379/1
Put this in your iredisrc
then connect via iredis -d staging
or iredis -d dev
.
将其放入 iredisrc
中,然后通过 iredis -d staging
或 iredis -d dev
连接。
Change The Default Prompt
更改默认提示
You can change the prompt str, the default prompt is:
你可以更改提示符 str,默认提示符为:
127.0.0.1:6379>
Which is rendered by {host}:{port}[{db}]>
, you can change this via --prompt
option or change iredisrc config file. The prompwt string uses python string format engine, supported interpolations:
它由 {host}:{port}[{db}]>
渲染,您可以通过 --prompt
选项或更改 iredisrc 配置文件。prompwt 字符串使用 python 字符串格式引擎,支持的插值方式如下:
{client_name}
{db}
{host}
{path}
{port}
{username}
{client_addr}
{client_id}
The --prompt
utilize Python String format engine, so as long as it is a valid string formatter, it will work( anything that "<your prompt>".format(...)
accepts). For example, you can limit your Redis server host name's length to 5 by setting --prompt
to iredis --prompt '{host:.5s}'
.--prompt
使用 Python 字符串格式引擎,因此只要它是一个有效的字符串格式化程序,它就可以工作("<your prompt>".format(...)
接受的任何东西)。例如,您可以通过将 --prompt
设置为 iredis --prompt '{host:.5s}'
来将 Redis 服务器主机名的长度限制为 5。
Configuration 配置
IRedis supports config files. Command-line options will always take precedence over config. Configuration resolution from highest to lowest precedence is:
IRedis 支持配置文件。命令行选项将始终优先于配置。从最高优先级到最低优先级的配置解析为:
- Options from command line
命令行中的选项 $PWD/.iredisrc
~/.iredisrc
(this path can be changed withiredis --iredisrc $YOUR_PATH
)~/.iredisrc
(此路径可使用iredis --iredisrc $YOUR_PATH
更改)/etc/iredisrc
- default config in IRedis package.
IRedis 包中的 default 配置。
You can copy the self-explained default config here:
您可以在此处复制自我解释的默认配置:
https://raw.githubusercontent.com/laixintao/iredis/master/iredis/data/iredisrc
And then make your own changes.
然后进行您自己的更改。
(If you are using an old versions of IRedis, please use the config file below, and change the version in URL):
(如果您使用的是旧版本的 IRedis,请使用下面的配置文件,并在 URL 中更改版本):
https://raw.githubusercontent.com/laixintao/iredis/v1.0.4/iredis/data/iredisrc
Keys
IRedis support unix/readline-style REPL keyboard shortcuts, which means keys like Ctrl + F to forward work.
IRedis 支持 unix/readline 风格的 REPL 键盘快捷键,即 Ctrl + F 等键可以转发工作。
Also: 也:
- Ctrl + D (i.e. EOF) to exit; you can also use the
exit
command.
Ctrl + D(即 EOF)退出;您也可以使用exit
命令。 - Ctrl + L to clear screen; you can also use the
clear
command.
Ctrl + L 清除屏幕;您也可以使用clear
命令。 - Ctrl + X Ctrl + E to open an editor to edit command, or V in vi-mode.
Ctrl + X Ctrl + E 打开编辑器以编辑命令,或在 vi 模式下使用 V。
Development 发展
Release Strategy 发布策略
IRedis is built and released by GitHub Actions
. Whenever a tag is pushed to the master
branch, a new release is built and uploaded to pypi.org, it's very convenient.
IRedis 由 GitHub Actions
构建和发布。每当将标签推送到 master
分支时,都会构建新版本并将其上传到 pypi.org,这非常方便。
Thus, we release as often as possible, so that users can always enjoy the new features and bugfixes quickly. Any bugfix or new feature will get at least a patch release, whereas big features will get a minor release.
因此,我们尽可能频繁地发布,以便用户始终可以快速享受新功能和错误修复。任何错误修复或新功能都将至少获得补丁版本,而大型功能将获得次要版本。
Setup Environment 设置环境
IRedis favors poetry as package management tool. To setup a develop environment on your computer:
IRedis 喜欢将诗歌作为包管理工具。要在计算机上设置开发环境:
First, install poetry (you can do it in a python's virtualenv):
首先,安装 poetry(你可以在 python 的 virtualenv 中完成):
pip install poetry
Then run (which is similar to pip install -e .
):
然后运行 (类似于 pip install -e .
):
poetry install
Be careful running testcases locally, it may flush you db!!!
在本地运行 testcases 时要小心,它可能会刷新你的 db!!
Development Logs 开发日志
This is a command-line tool, so we don't write logs to stdout.
这是一个命令行工具,因此我们不会将日志写入 stdout。
You can tail -f ~/.iredis.log
to see logs, the log is pretty clear, you can see what actually happens from log files.
你可以 tail -f ~/.iredis.log
查看日志,日志非常清晰,你可以从日志文件中看到实际发生的情况。
Catch Up with Latest Redis-doc
了解最新的 Redis-doc
IRedis use a git submodule to track current-up-to-date redis-doc version. To catch up with latest:
IRedis 使用 git 子模块来跟踪当前最新的 redis-doc 版本。要赶上最新版本:
- Git pull in redis-doc
在 redis-doc 中加入 Git pull - Copy doc files to
/data
:cp -r redis-doc/commands* iredis/data
将 doc 文件复制到/data
:cp -r redis-doc/commands* iredis/data
- Prettier markdown
prettier --prose-wrap always iredis/data/commands/*.md --write
更漂亮的 markdownprettier --prose-wrap always iredis/data/commands/*.md --write
- Check the diff, update IRedis' code if needed.
检查差异,如果需要,更新 IRedis 的代码。
Related Projects 相关项目
- redis-tui
If you like iredis, you may also like other cli tools by dbcli:
如果你喜欢 iredis,你可能也会喜欢 dbcli 的其他 cli 工具:
- pgcli - Postgres Client with Auto-completion and Syntax Highlighting
pgcli - 具有自动完成和语法高亮功能的 Postgres 客户端 - mycli - MySQL/MariaDB/Percona Client with Auto-completion and Syntax Highlighting
mycli - 具有自动完成和语法高亮功能的 MySQL/MariaDB/Percona 客户端 - litecli - SQLite Client with Auto-completion and Syntax Highlighting
litecli - 具有自动完成和语法高亮功能的 SQLite 客户端 - mssql-cli - Microsoft SQL Server Client with Auto-completion and Syntax Highlighting
mssql-cli - 具有自动完成和语法高亮功能的 Microsoft SQL Server 客户端 - athenacli - AWS Athena Client with Auto-completion and Syntax Highlighting
athenacli - 具有自动完成和语法突出显示功能的 AWS Athena 客户端 - vcli - VerticaDB client
vcli - VerticaDB 客户端 - iredis - Client for Redis with AutoCompletion and Syntax Highlighting
iredis - 具有自动完成和语法高亮显示的 Redis 客户端
IRedis is build on the top of prompt_toolkit, a Python library (by Jonathan Slenders) for building rich commandline applications.
IRedis 构建在 prompt_toolkit 之上,后者是一个 Python 库(由 Jonathan Slenders 编写),用于构建丰富的命令行应用程序。