如何通过远程服务器/URL运行Redis客户端及查看Redis连接列表?
Hey there, let's walk through your questions step by step:
1. How to run a Redis client against a remote server?
Connecting to a remote Redis instance with the official redis-cli tool is straightforward—here are your go-to options, depending on server authentication requirements:
- Basic connection (no password): Use the
-hflag to specify the remote server's IP/hostname, and-pfor the port (you can skip-pif using the default 6379 port).
Example:redis-cli -h 10.0.0.5 -p 6379 - Connection with password authentication: Either pass the password directly with the
-aflag, or connect first then authenticate with theAUTHcommand.
Example with-a:
Example with post-connection auth:redis-cli -h 10.0.0.5 -p 6379 -a mySecurePassword123redis-cli -h 10.0.0.5 -p 6379 # Once connected, run: AUTH mySecurePassword123
2. How to run a Redis client via a remote URL, and how to get the list of connections in Redis cache?
Connecting via a remote URL
Redis supports URL-based connection strings with redis-cli, which is great for scripting or quick one-off connections. The URL format is:redis://[:password@]host:port/database_number
- No password, default database (0):
redis-cli redis://10.0.0.5:6379 - With password and specific database:
redis-cli redis://:mySecurePassword123@10.0.0.5:6379/2
Retrieving active connections
To get full details about all current client connections to your Redis server, use the INFO clients command. When you run this in the connected client, it returns a section with metrics like total connected clients, plus a detailed list of each connection's metadata (IP address, port, idle time, etc.).
Example output snippet:
Clientsconnected_clients:7
blocked_clients:0
client_list:id=4 addr=192.168.1.20:45678 fd=6 name= age=24 idle=5 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=ping
For a more concise, line-by-line breakdown of every connection, use the CLIENT LIST command directly—each line represents a single client connection with all its associated details.
内容的提问来源于stack exchange,提问作者Manish

