0

Hi is there a way to know the active db on redis? As for now i am using $this->redis->select(7), so I basically select it manually. But is there a way where i can get the redis db that is set?

1 Answers1

1

While there is no command to know which database the current connection is using, however, you can use CLIENT LIST which lists the current db in use for each client.

Ex:

127.0.0.1:6379> client list
id=6 addr=127.0.0.1:64502 fd=8 name= age=7 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

You can also use CLIENT SETNAME to set name of the client during connection and filter the CLIENT LIST output to that name.

127.0.0.1:6379> client setname hello
OK
127.0.0.1:6379> client list
id=6 addr=127.0.0.1:64502 fd=8 name=hello age=189 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
127.0.0.1:6379> 

for more details see the redis document https://redis.io/commands/client-list

tabreaz
  • 649
  • 4
  • 17