Is there any way to save client ip in Redis?

Is it possible to save the client's IP address in a team SETin the Redis by Redis engine?

Something like that:

SET my_key $client_ip
+4
source share
1 answer

Assuming you don’t know yours $client_ip, you can do the following:

  • Set a unique name for your connection with Redis with CLIENT SETNAME
  • Get customer list with CLIENT LIST
  • Find the line with the name of the connection and extract the IP address.
  • Use the resulting IP address in your team SET

Example

127.0.0.1:6379> client getname
(nil)
127.0.0.1:6379> client setname FreddyFrog
OK
127.0.0.1:6379> client getname
"FreddyFrog"
127.0.0.1:6379> client list
id=4 addr=127.0.0.1:49426 fd=6 name=FreddyFrog age=25 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
+8
source

Source: https://habr.com/ru/post/1606095/


All Articles