← 返回命令列表

Linux command

redis-cli 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Connect to local Redis server

redis-cli

Connect to a remote Redis server

redis-cli -h [hostname] -p [port]

Connect with password authentication

redis-cli -a [password]

Connect with TLS

redis-cli --tls -h [hostname] -p [port] -a [password]

Execute a single command

redis-cli [command] [arguments]

Get a key value

redis-cli GET [key]

Set a key value

redis-cli SET [key] "[value]"

List all keys

redis-cli KEYS "*"

Monitor all commands

redis-cli MONITOR

Get server statistics

redis-cli INFO

说明

redis-cli is the command-line interface for Redis, an in-memory data structure store used as database, cache, and message broker. It provides interactive and scripted access to Redis servers. In interactive mode (no command specified), redis-cli presents a prompt for entering commands. Commands follow Redis protocol: command name followed by arguments, with responses displayed immediately. Common operations include key-value storage (GET, SET, DEL), lists (LPUSH, RPOP), sets (SADD, SMEMBERS), hashes (HSET, HGET), and pub/sub messaging (PUBLISH, SUBSCRIBE). The tool supports cluster mode, sentinel connections, and various debugging and monitoring features for Redis administration.

参数

-h _host_
Server hostname (default: 127.0.0.1)
-p _port_
Server port (default: 6379)
-a _password_
Password for AUTH command
-n _db_
Database number to select
-u _uri_
Connect using Redis URI (redis://...)
-r _count_
Repeat command count times
-i _interval_
Interval between repeats (seconds)
--scan
List keys using SCAN instead of KEYS
--pipe
Transfer raw Redis protocol from stdin
--rdb _file_
Transfer RDB dump from server to file
-c
Enable cluster mode (follow -ASK and -MOVED redirections)
-s _socket_
Server socket path (overrides hostname and port)
--tls
Establish a secure TLS connection
--user _username_
ACL username for AUTH
--pass _password_
Alias for -a
--csv
Output in CSV format
--bigkeys
Sample keys looking for keys with many elements
--memkeys
Sample keys looking for keys consuming the most memory
--cluster _command_
Execute cluster commands
--latency
Monitor latency continuously
--stat
Print rolling stats

FAQ

What is the redis-cli command used for?

redis-cli is the command-line interface for Redis, an in-memory data structure store used as database, cache, and message broker. It provides interactive and scripted access to Redis servers. In interactive mode (no command specified), redis-cli presents a prompt for entering commands. Commands follow Redis protocol: command name followed by arguments, with responses displayed immediately. Common operations include key-value storage (GET, SET, DEL), lists (LPUSH, RPOP), sets (SADD, SMEMBERS), hashes (HSET, HGET), and pub/sub messaging (PUBLISH, SUBSCRIBE). The tool supports cluster mode, sentinel connections, and various debugging and monitoring features for Redis administration.

How do I run a basic redis-cli example?

Run `redis-cli` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -h _host_ do in redis-cli?

Server hostname (default: 127.0.0.1)