RedisJSON - MGET Example?

1.4k views Asked by At

I am using RedisJSON and I can't figure out how to get the full JSON values stored for multiple keys, following the documentation on the official site of the plugin.

For example, from the redis-cli:

redis-cli-1234> json.set k1 . '{"a":"a" }'
OK
redis-cli-1234> json.set k2 . '{"b":"b" }'
OK

Now I would like to run a command that would get k1, k2 (the keys of the desired values) and return their values, in one-go:

1) "{\"a\":\"a\"}"
2) "{\"b\":\"b\"}"

But I can't figure out how.

I've tried:

redis-cli-1234> json.mget k1 k2 .

And several other stuff, but I can only get redis to return either one value or the other, bot not both.

Any idea?

1

There are 1 answers

3
Pieter Cailliau On

https://redis.io/topics/transactions

redis-cloud:6379> multi
OK
redis-cloud:6379(TX)> json.get k1
QUEUED
redis-cloud:6379(TX)> json.get k2
QUEUED
redis-cloud:6379(TX)> exec
1) "{\"a\":\"a\"}"
2) "{\"b\":\"b\"}"