I want get value by redis-cli keys
This is work
redis-cli keys number_* | xargs redis-cli del
But this is not work
redis-cli keys number_* | xargs redis-cli get
Redis GET all Keys To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.
redis is an in-memory, key/value store. Think of it as a dictionary with any number of keys, each of which has a value that can be set or retrieved. However, Redis goes beyond a simple key/value store as it is actually a data structures server, supporting different kinds of values.
The Redis command line interface ( redis-cli ) is a terminal program used to send commands to and read replies from the Redis server.
To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.
The difference between DEL
and GET
, in this context, is that the former is variadic (i.e. accepts one or more arguments) whereas the latter isn't (one and only one key name is expected).
To solve this you can choose one of the following:
-L
switch with xargs, i.e.: redis-cli keys number_* | xargs -L 1 redis-cli get
MGET
, i.e.: redis-cli keys number_* | xargs redis-cli mget
KEYS
is a dangerous command as it may block the server for a long time - do not use it in production!If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With