jedis multi get

691 views
Skip to first unread message

Shushant Arora

unread,
Nov 4, 2017, 4:07:55 PM11/4/17
to Redis DB
Hi

I want to get multiple keys from redis.  I am using jedis client library in java,
Is pipeline the only and best option or is there any other way to achievce multiget or batch/bulk get ?

hva...@gmail.com

unread,
Nov 4, 2017, 5:42:18 PM11/4/17
to Redis DB
I assume the option of issuing multiple GET commands is not attractive to you because you want the values of all the keys to be unchanged.  I.e., if you issue "GET key1", "GET key2", and "GET key3", you don't want there to be a chance that the value of key3 changes between the time you fetch key1 and the time you fetch key3.

One solution to this is to wrap the commands to read the keys within a "MULTI ... EXEC" block.  This will make Redis process all the GET commands between MULTI and EXEC together as if they were a single command.  I.e., commands from other clients won't get in between the GETs and change any of the keys.

Depending on what other kinds of operations you're performing on the keys, it might be useful to keep them as fields in a hash.  If you do, the HGETALL command will fetch all the fields and values in the hash together in one command.  This is equivalent to fetching multiple keys at the same time.

Shushant Arora

unread,
Nov 5, 2017, 3:53:25 AM11/5/17
to redi...@googlegroups.com
No there is no client in between reads.

My scenario is there are multiple keys (K1,K2,..K10) all are of hash types - each containing ~20 hashkeys say (f11,f12..f120 for K1 ) and (f21,f22,..f220) for K2 and so on for k3..k10
My aim is to get values of fields from different keys say f11,f12 from k1 and f21,f29 from k2 and f42,f43 from k4 .

Can I achieve this in single network call in O(1) there is no other client in between read which is writing.


--
You received this message because you are subscribed to a topic in the Google Groups "Redis DB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/redis-db/I9KV60JQVEI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

hva...@gmail.com

unread,
Nov 5, 2017, 1:21:09 PM11/5/17
to Redis DB
If the fields are in different hashes, as you describe, then no, I don't think there is a single call to read them all.

The closest thing to a single command to fetch them is to issue one HGETALL or HMGET for each hash, and wrap these multiple commands in a MULTI ... EXEC block so the values are all returned at the same time.
To unsubscribe from this group and all its topics, send an email to redis-db+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages