问题
I did a web search but found nothing on this. I am running redis on a cluster and would like to find out which machine is connecting to redis ( especially when no machine is supposed to be connecting, but redis still says some machine connected).
thanks in advance.
回答1:
With MONITOR, only the clients actually sending traffic to Redis will be shown. If you just need to get a list of connected clients, you can use the CLIENT LIST command.
$ redis-cli client list
It will return a table whose fields are described there:
Redis "Client List" purpose and description
回答2:
Did you try the MONITOR command?
http://redis.io/commands/monitor
$ redis-cli monitor
1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
1339518087.877697 [0 127.0.0.1:60866] "dbsize"
1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
1339518096.506257 [0 127.0.0.1:60866] "get" "x"
1339518099.363765 [0 127.0.0.1:60866] "del" "x"
1339518100.544926 [0 127.0.0.1:60866] "get" "x"
Use SIGINT (Ctrl-C) to stop a MONITOR stream running via redis-cli.
# OR
$ telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
MONITOR
+OK
+1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
+1339518087.877697 [0 127.0.0.1:60866] "dbsize"
+1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
+1339518096.506257 [0 127.0.0.1:60866] "get" "x"
+1339518099.363765 [0 127.0.0.1:60866] "del" "x"
+1339518100.544926 [0 127.0.0.1:60866] "get" "x"
QUIT
+OK
Connection closed by foreign host.
来源:https://stackoverflow.com/questions/11661314/is-there-a-way-to-get-the-client-ip-in-redis