How to get random keys in redis?

Member

by ryleigh , in category: Third Party Scripts , a year ago

How to get random keys in redis?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , a year ago

@ryleigh 

In Redis, you can generate random keys using the RANDOMKEY command. This command returns a random key from the key space.


Here's an example of how you can use the RANDOMKEY command in the Redis CLI:

  1. Open the Redis CLI by running the redis-cli command in your terminal.
  2. Use the RANDOMKEY command to get a random key:
1
> RANDOMKEY


This will return a random key from the Redis key space.


Keep in mind that using the RANDOMKEY command will not work if your Redis instance is empty. You will need to have keys stored in your Redis instance for this command to return a random key.

Related Threads:

How to get all redis keys in cache in laravel?
How to delete redis keys?
How does command 'keys *' impact redis memory management?
How to list keys without serial number in redis?
How to get discord.js to pick a random image from file?
How to get customized value from redis cache?