Debian Codegraph @

README.md

raw
1 <p align="center">
2 <img width="100" height="100" src="https://raw.githubusercontent.com/laixintao/iredis/master/docs/assets/logo.png" />
3 </p>
4
5 <h3 align="center">Interactive Redis: A Cli for Redis with AutoCompletion and Syntax Highlighting.</h3>
6
7 <p align="center">
8 <a href="https://github.com/laixintao/iredis/actions"><img src="https://github.com/laixintao/iredis/actions/workflows/test.yaml/badge.svg?branch=master" alt="Github Action"></a>
9 <a href="https://badge.fury.io/py/iredis"><img src="https://badge.fury.io/py/iredis.svg" alt="PyPI version"></a>
10 <img src="https://badgen.net/badge/python/3.10%20%7C%203.11%20%7C%203.12" alt="Python version">
11 <a href="https://pepy.tech/project/iredis"><img src="https://pepy.tech/badge/iredis" alt="Download stats"></a>
12 </p>
13
14 <p align="center">
15 <img src="./docs/assets/demo.svg" alt="demo">
16 </p>
17
18 IRedis is a terminal client for redis with auto-completion and syntax
19 highlighting. IRedis lets you type Redis commands smoothly, and displays results
20 in a user-friendly format.
21
22 IRedis is an alternative for redis-cli. In most cases, IRedis behaves exactly
23 the same as redis-cli. Besides, it is safer to use IRedis on production servers
24 than redis-cli: IRedis will prevent accidentally running dangerous commands,
25 like `KEYS *` (see
26 [Redis docs / Latency generated by slow commands](https://redis.io/topics/latency#latency-generated-by-slow-commands)).
27
28 ## Features
29
30 - Advanced code completion. If you run command `KEYS` then run `DEL`, IRedis
31 will auto-complete your command based on `KEYS` result.
32 - Command validation. IRedis will validate command while you are typing, and
33 highlight errors. E.g. try `CLUSTER MEET IP PORT`, IRedis will validate IP and
34 PORT for you.
35 - Command highlighting, fully based on redis grammar. Any valid command in
36 IRedis shell is a valid redis command.
37 - Human-friendly result display.
38 - _pipeline_ feature, you can use your favorite shell tools to parse redis'
39 response, like `get json | jq .`.
40 - Support pager for long output.
41 - Support connection via URL, `iredis --url redis://example.com:6379/1`.
42 - Support cluster, IRedis will auto reissue command for `MOVED` response in
43 cluster mode.
44 - Support NAT mapping for Redis clusters `--natmap
45 remoteHost:remotePort:localHost:localPort` (comma-separated for multiple
46 nodes).
47 - Store server configuration: `iredis -d prod-redis` (see [dsn](#using-dsn) for
48 more).
49 - `peek` command to check the key's type then automatically call
50 `get`/`lrange`/`sscan`, etc, depending on types. You don't need to call the
51 `type` command then type another command to get the value. `peek` will also
52 display the key's length and memory usage.
53 - <kbd>Ctrl</kbd> + <kbd>C</kbd> to cancel the current typed command, this won't
54 exit IRedis, exactly like bash behaviour. Use <kbd>Ctrl</kbd> + <kbd>D</kbd>
55 to send a EOF to exit IRedis.
56 - <kbd>Ctrl</kbd> + <kbd>R</kbd> to open **reverse-i-search** to search through
57 your command history.
58 - Auto suggestions. (Like [fish shell](http://fishshell.com/).)
59 - Support `--encode=utf-8`, to decode Redis' bytes responses.
60 - Command hint on bottom, include command syntax, supported redis version, and
61 time complexity.
62 - Official docs with built-in `HELP` command, try `HELP SET`!
63 - Written in pure Python, but IRedis was packaged into a single binary with
64 [PyOxidizer](https://github.com/indygreg/PyOxidizer), you can use cURL to
65 download and run, it just works, even you don't have a Python interpreter.
66 - You can change the cli prompt using `--prompt` option or set via `~/.iredisrc`
67 config file.
68 - Hide password for `AUTH` command.
69 - Says "Goodbye!" to you when you exit!
70 - For full features, please see: [iredis.xbin.io](https://www.iredis.xbin.io)
71
72 ## Install
73
74 ### Pip
75
76 Install via pip:
77
78 ```
79 pip install iredis
80 ```
81
82 [pipx](https://github.com/pipxproject/pipx) is recommended:
83
84 ```
85 pipx install iredis
86 ```
87
88 ### Brew
89
90 For Mac users, you can install iredis via brew 🍻
91
92 ```
93 brew install iredis
94 ```
95
96 ### Linux
97
98 You can also use your Linux package manager to install IRedis, like `apt` in
99 Ubuntu (Only available on Ubuntu 21.04+).
100
101 ```shell
102 apt install iredis
103 ```
104
105 [![Packaging status](https://repology.org/badge/vertical-allrepos/iredis.svg)](https://repology.org/project/iredis/versions)
106
107 ### Download Binary
108
109 Or you can download the executable binary with cURL(or wget), untar, then run.
110 It is especially useful when you don't have a python interpreter(E.g. the
111 [official Redis docker image](https://hub.docker.com/_/redis/) which doesn't
112 have Python installed.):
113
114 ```
115 wget https://github.com/laixintao/iredis/releases/download/v1.15.2/iredis.tar.gz \
116 && tar -xzf iredis.tar.gz \
117 && ./iredis
118 ```
119
120 (Check the [release page](https://github.com/laixintao/iredis/releases) if you
121 want to download an old version of IRedis.)
122
123 Please note that the single binary build only support until IRedis v1.15.2, all
124 versions before IRedis v1.15.2 has the single binary build that you can download
125 directly. After v1.15.2, as the PyOxidizer [is no longer maintained](
126 https://gregoryszorc.com/blog/2024/03/17/my-shifting-open-source-priorities/),
127 IRedis doesn't do the single binary build either.
128
129 ## Usage
130
131 Once you install IRedis, you will know how to use it. Just remember, IRedis
132 supports similar options like redis-cli, like `-h` for redis-server's host and
133 `-p` for port.
134
135 ```
136 $ iredis --help
137
138 Usage: iredis [OPTIONS] [CMD]...
139
140 IRedis: Interactive Redis
141
142 When no command is given, IRedis starts in interactive mode.
143
144 Examples:
145 - iredis
146 - iredis -d dsn
147 - iredis -h 127.0.0.1 -p 6379
148 - iredis -h 127.0.0.1 -p 6379 -a <password>
149 - iredis --url redis://localhost:7890/3
150
151 Type "help" in interactive mode for information on available commands and
152 settings.
153
154 Options:
155 -h TEXT Server hostname (default: 127.0.0.1).
156 -p TEXT Server port (default: 6379).
157 -s, --socket TEXT Server socket (overrides hostname and port).
158 -n INTEGER Database number.(overwrites dsn/url's db
159 number)
160
161 -u, --username TEXT User name used to auth, will be ignore for
162 redis version < 6.
163
164 -a, --password TEXT Password to use when connecting to the
165 server.
166
167 --url TEXT Use Redis URL to indicate connection(Can set
168 with env `IREDIS_URL`), Example: redis:/
169 /[[username]:[password]]@localhost:6379/0
170 rediss://[[username]:[password]]@localhost:6
171 379/0 unix://[[username]:[password]]@/pa
172 th/to/socket.sock?db=0
173
174 -d, --dsn TEXT Use DSN configured into the [alias_dsn]
175 section of iredisrc file. (Can set with env
176 `IREDIS_DSN`)
177
178 --newbie / --no-newbie Show command hints and useful helps.
179 --iredisrc TEXT Config file for iredis, default is
180 ~/.iredisrc.
181
182 --decode TEXT decode response, default is No decode, which
183 will output all bytes literals.
184
185 --client_name TEXT Assign a name to the current connection.
186 --raw / --no-raw Use raw formatting for replies (default when
187 STDOUT is not a tty). However, you can use
188 --no-raw to force formatted output even when
189 STDOUT is not a tty.
190
191 --rainbow / --no-rainbow Display colorful prompt.
192 --shell / --no-shell Allow to run shell commands, default to
193 True.
194
195 --pager / --no-pager Using pager when output is too tall for your
196 window, default to True.
197
198 --verify-ssl [none|optional|required]
199 Set the TLS certificate verification
200 strategy
201
202 --prompt TEXT Prompt format (supported interpolations:
203 {client_name}, {db}, {host}, {path}, {port},
204 {username}, {client_addr}, {client_id}).
205
206 --version Show the version and exit.
207 --help Show this message and exit.
208
209 ```
210
211 ### Using DSN
212
213 IRedis support storing server configuration in config file. Here is a DSN
214 config:
215
216 ```
217 [alias_dsn]
218 dev=redis://localhost:6379/4
219 staging=redis://username:[email protected]:6379/1
220 ```
221
222 Put this in your `iredisrc` then connect via `iredis -d staging` or
223 `iredis -d dev`.
224
225 ### Using `--natmap` with Redis Cluster
226
227 Use `--natmap` when you can connect to a Redis Cluster through local forwarded
228 ports, but the cluster nodes still advertise different remote or private
229 addresses in `MOVED` replies. This usually happens when the cluster is behind
230 SSH tunnels, Docker port publishing, Kubernetes port-forwarding, or another NAT
231 layer.
232
233 `--natmap` tells IRedis how to translate the address announced by Redis into
234 the address that is actually reachable from your machine.
235
236 Format:
237
238 ```shell
239 iredis --natmap remoteHost:remotePort:localHost:localPort
240 ```
241
242 Use a comma-separated list when more than one cluster node needs translation.
243
244 Example: suppose the cluster replies with node addresses on a private network:
245
246 ```text
247 10.0.0.11:6379
248 10.0.0.12:6379
249 10.0.0.13:6379
250 ```
251
252 but you access those nodes locally through SSH tunnels:
253
254 ```text
255 127.0.0.1:7001
256 127.0.0.1:7002
257 127.0.0.1:7003
258 ```
259
260 then start IRedis like this:
261
262 ```shell
263 iredis -h 127.0.0.1 -p 7001 \
264 --natmap 10.0.0.11:6379:127.0.0.1:7001,10.0.0.12:6379:127.0.0.1:7002,10.0.0.13:6379:127.0.0.1:7003
265 ```
266
267 Now when a command hits the wrong node and Redis returns `MOVED 12182
268 10.0.0.12:6379`, IRedis will reconnect to `127.0.0.1:7002` and reissue the
269 command automatically.
270
271 ### Change The Default Prompt
272
273 You can change the prompt str, the default prompt is:
274
275 ```shell
276 127.0.0.1:6379>
277 ```
278
279 Which is rendered by `{host}:{port}[{db}]> `, you can change this via `--prompt`
280 option or change
281 [iredisrc](https://github.com/laixintao/iredis/blob/master/iredis/data/iredisrc)
282 config file. The prompwt string uses python string format engine, supported
283 interpolations:
284
285 - `{client_name}`
286 - `{db}`
287 - `{host}`
288 - `{path}`
289 - `{port}`
290 - `{username}`
291 - `{client_addr}`
292 - `{client_id}`
293
294 The `--prompt` utilize
295 [Python String format engine](https://docs.python.org/3/library/string.html#formatstrings),
296 so as long as it is a valid string formatter, it will work( anything that
297 `"<your prompt>".format(...)` accepts). For example, you can limit your Redis
298 server host name's length to 5 by setting `--prompt` to
299 `iredis --prompt '{host:.5s}'`.
300
301 ### Configuration
302
303 IRedis supports config files. Command-line options will always take precedence
304 over config. Configuration resolution from highest to lowest precedence is:
305
306 - _Options from command line_
307 - `$PWD/.iredisrc`
308 - `~/.iredisrc` (this path can be changed with `iredis --iredisrc $YOUR_PATH`)
309 - `/etc/iredisrc`
310 - default config in IRedis package.
311
312 You can copy the _self-explained_ default config here:
313
314 https://raw.githubusercontent.com/laixintao/iredis/master/iredis/data/iredisrc
315
316 And then make your own changes.
317
318 (If you are using an old versions of IRedis, please use the config file below,
319 and change the version in URL):
320
321 https://raw.githubusercontent.com/laixintao/iredis/v1.0.4/iredis/data/iredisrc
322
323 ### Keys
324
325 IRedis support unix/readline-style REPL keyboard shortcuts, which means keys
326 like <kbd>Ctrl</kbd> + <kbd>F</kbd> to forward work.
327
328 Also:
329
330 - <kbd>Ctrl</kbd> + <kbd>D</kbd> (i.e. EOF) to exit; you can also use the `exit`
331 command.
332 - <kbd>Ctrl</kbd> + <kbd>L</kbd> to clear screen; you can also use the `clear`
333 command.
334 - <kbd>Ctrl</kbd> + <kbd>X</kbd> <kbd>Ctrl</kbd> + <kbd>E</kbd> to open an
335 editor to edit command, or <kbd>V</kbd> in vi-mode.
336
337 ## Development
338
339 ### Release Strategy
340
341 IRedis is built and released by `GitHub Actions`. Whenever a tag is pushed to
342 the `master` branch, a new release is built and uploaded to pypi.org, it's very
343 convenient.
344
345 Thus, we release as often as possible, so that users can always enjoy the new
346 features and bugfixes quickly. Any bugfix or new feature will get at least a
347 patch release, whereas big features will get a minor release.
348
349 ### Setup Environment
350
351 IRedis favors [poetry](https://github.com/sdispater/poetry) as package
352 management tool. To setup a develop environment on your computer:
353
354 First, install poetry (you can do it in a python's virtualenv):
355
356 ```
357 pip install poetry
358 ```
359
360 Then run (which is similar to `pip install -e .`):
361
362 ```
363 poetry install
364 ```
365
366 **Be careful running testcases locally, it may flush you db!!!**
367
368 ### Code style
369
370 Code is formatted with [black](https://github.com/psf/black). After modifying code, run:
371
372 ```bash
373 black .
374 ```
375
376 We recommend installing [pre-commit](https://pre-commit.com/) so black and flake8 run automatically on each `git commit`:
377
378 ```bash
379 poetry run pre-commit install
380 ```
381
382 ### Development Logs
383
384 This is a command-line tool, so we don't write logs to stdout.
385
386 You can `tail -f ~/.iredis.log` to see logs, the log is pretty clear, you can
387 see what actually happens from log files.
388
389 ### Catch Up with Latest Redis-doc
390
391 IRedis use a git submodule to track current-up-to-date redis-doc version. To
392 catch up with latest:
393
394 1. Git pull in redis-doc
395 2. Copy doc files to `/data`: `cp -r redis-doc/commands* iredis/data`
396 3. Prettier
397 markdown`prettier --prose-wrap always iredis/data/commands/*.md --write`
398 4. Check the diff, update IRedis' code if needed.
399
400 ## Related Projects
401
402 - [redis-tui](https://github.com/mylxsw/redis-tui)
403
404 If you like iredis, you may also like other cli tools by
405 [dbcli](https://www.dbcli.com/):
406
407 - [pgcli](https://www.pgcli.com) - Postgres Client with Auto-completion and
408 Syntax Highlighting
409 - [mycli](https://www.mycli.net) - MySQL/MariaDB/Percona Client with
410 Auto-completion and Syntax Highlighting
411 - [litecli](https://litecli.com) - SQLite Client with Auto-completion and Syntax
412 Highlighting
413 - [mssql-cli](https://github.com/dbcli/mssql-cli) - Microsoft SQL Server Client
414 with Auto-completion and Syntax Highlighting
415 - [athenacli](https://github.com/dbcli/athenacli) - AWS Athena Client with
416 Auto-completion and Syntax Highlighting
417 - [vcli](https://github.com/dbcli/vcli) - VerticaDB client
418 - [iredis](https://github.com/laixintao/iredis/) - Client for Redis with
419 AutoCompletion and Syntax Highlighting
420
421 IRedis is build on the top of
422 [prompt_toolkit](https://github.com/jonathanslenders/python-prompt-toolkit), a
423 Python library (by [Jonathan Slenders](https://twitter.com/jonathan_s)) for
424 building rich commandline applications.