Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value by redis-cli keys

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
like image 420
weiwei Avatar asked Jun 29 '17 13:06

weiwei


People also ask

How do I get Redis keys?

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.

Is Redis key-value?

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.

What does Redis-CLI command do?

The Redis command line interface ( redis-cli ) is a terminal program used to send commands to and read replies from the Redis server.

How use Redis command line?

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.


1 Answers

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:

  1. Use the -L switch with xargs, i.e.: redis-cli keys number_* | xargs -L 1 redis-cli get
  2. Use MGET, i.e.: redis-cli keys number_* | xargs redis-cli mget

Important warning: KEYS is a dangerous command as it may block the server for a long time - do not use it in production!

like image 120
Itamar Haber Avatar answered Sep 18 '22 23:09

Itamar Haber