LinuxCommandLibrary

redis-cli

TLDR

Connect to local Redis server

$ redis-cli
copy
Connect to a remote Redis server
$ redis-cli -h [hostname] -p [port]
copy
Connect with password authentication
$ redis-cli -a [password]
copy
Execute a single command
$ redis-cli [command] [arguments]
copy
Get a key value
$ redis-cli GET [key]
copy
Set a key value
$ redis-cli SET [key] "[value]"
copy
List all keys matching a pattern
$ redis-cli KEYS "*"
copy
Monitor all commands in real-time
$ redis-cli MONITOR
copy
Get server statistics
$ redis-cli INFO
copy

SYNOPSIS

redis-cli [-h host] [-p port] [-a password] [-n db] [command [args...]]

DESCRIPTION

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.

PARAMETERS

-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
--cluster command
Execute cluster commands
--latency
Monitor latency continuously
--stat
Print rolling stats

COMMON COMMANDS

SET key value: Store a value
GET key: Retrieve a value
DEL key: Delete a key
KEYS pattern: Find keys matching pattern
EXPIRE key seconds: Set key expiration
TTL key: Get remaining time to live
FLUSHDB: Delete all keys in current database
INFO: Server information and statistics
PING: Test connection

CAVEATS

Using KEYS \* on production servers with large datasets can block the server. Use SCAN instead for iterating keys in production.
Passwords passed with -a appear in process listings and shell history. Use REDIS_AUTH environment variable or interactive AUTH for sensitive environments.
Redis databases are numbered 0-15 by default. Use -n to select a database or SELECT command interactively.

SEE ALSO

Copied to clipboard