Redis Hashes and sharding

60 views
Skip to first unread message

Shushant Arora

unread,
Oct 10, 2017, 12:36:01 AM10/10/17
to Redis DB
Redis supports a datatype hash - which is same as hashmap in java.

for redis operation :
In below example does student1 and student2 gets stored on same node as both belong to same hash Student - irrespective of number of nodes in my resis cluster.


HSET Student student1 "ABC" 
HSET Student student2 "DEF"


And also for Redis Spring integration as per http://www.baeldung.com/spring-data-redis-tutorial , The opsForHash() function returns the operations performed on hash values bound to the given key.

Here KEY is fixed string. private static final String KEY = "Student";

hashOps.put(KEY, student.getId(), student);

Will all the data here will go to one node since KEY for all data is same as Student.And it here it is a single key student of type hashmap ?

















Dvir Volk

unread,
Oct 10, 2017, 5:26:32 AM10/10/17
to Redis DB
Yes, sharding is done by the key, not by the Hash's sub-element. So all HSET operations on the same hash will go to the same shard, always, 

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@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.

Shushant Arora

unread,
Oct 10, 2017, 6:37:59 AM10/10/17
to Redis DB
Thanks!

And also is it possible to have value of Hash as ListType instead of simple String ?

say HSET Student Subjects "Subject1,Subject2,Subject3"  ?

Thanks

Jan-Erik Rediger

unread,
Oct 10, 2017, 9:29:29 AM10/10/17
to redi...@googlegroups.com
No, Redis does not natively support nesting of data structures.
You can built this yourself by either embedding a parseable format
("split the value at ',' to get a list") or by using an indirection
(store an ID/other key name, get the value from the set, then use this
value as a key to get the actual object)
> >> email to redis-db+u...@googlegroups.com <javascript:>.
> >> To post to this group, send email to redi...@googlegroups.com
> >> <javascript:>.
Reply all
Reply to author
Forward
0 new messages