7

Is there a way to pass the return value of one function to another in Redis? Of course, if you're using a language wrapper (like Ruby), it's easy — but what about from the CLI?

e.g. something like this, bash style

redis 127.0.0.1:6379> keys student* | mget

or something like this

redis 127.0.0.1:6379> mget(keys student*)

keys student* will return a list of keys, but I've no idea how to fetch all the values for those keys.

Thoughts?

tekknolagi
  • 10,663
  • 24
  • 75
  • 119

1 Answers1

7

From the CLI, you just have to let the shell do its job.

./redis-cli --raw keys 'student:*' | awk '{printf "get %s\n", $1}' | ./redis-cli --raw

Please note you are not supposed to use the keys command in applications because of its linear complexity.

Didier Spezia
  • 70,911
  • 12
  • 189
  • 154
  • 2
    Even simpler (`--raw` is default when piping to another command): `redis-cli keys 'student:*' | xargs redis-cli mget`. For unary commands (such as `type`), use `redis-cli keys 'student:*' | xargs -n1 redis-cli type`. Of course, the `keys` command is discouraged, and the usefulness of this if you have e.g. a set with all the keys is diminished by the `sort` command, which should yield better performance. – Linus Thiel Sep 07 '12 at 10:49
  • 1
    xargs is nice, but xargs -n1 will fork one process per input line, while piping in redis-cli will not. – Didier Spezia Sep 07 '12 at 12:31
  • I wanted to delete 75k keys, and this technique was like 100x faster than using the python client and pipeline – matiu Sep 26 '18 at 02:32