best way to store a set linked to a hash in Redis?

mkto

I need to store data about classrooms and students in Redis.

I have hashes for classroom info, e.g.: classroom:0 where 0 is the class room id and it has field value pairs like:

classroomName -> xx, teacherId -> yy

In order to store students for these classroom, I have separate Set, e.g:

studentsForClassroom:0, and this set contains array of student IDs in that class.

Following this design, in order to get all information about a class, I have to first do a hgetall command for classroom:0 and then a smembers command for studentsForClassroom:0.

Is this the right way? Any better solution? Is it possible that the students SET can somehow be nested in the classroom hash so that when I do a hgetall, the entire students array is populated right there in the classroom data?

Itamar Haber

You're doing it right. Redis doesn't have nested data structures.

Since your classroom hashes and students sets are not too big, using HGETALL and SMEMBERS is OK but remember that for larger volumes you'd probably want to use HSCAN and SSCAN instead.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Redis: the best way to get all hash values

From Dev

Best way to store a list of java objects in Redis

From Dev

Redis — best way to store a large map (dictionary)

From Dev

What is the best way to store a set of strings

From Dev

Best way to store two related Hash Keys for Single value

From Dev

Redis how to store associative array? Set or Hash or List?

From Dev

Best way to hash a vertex

From Dev

What is the conventional way to store objects in a sorted set in redis?

From Dev

What is the best way to store string? SharedPreferences Set Collection or Files?

From Dev

Best way to store locators

From Dev

Best way to store files

From Dev

Best way to store content?

From Dev

Best way to resize a hash table

From Dev

Which is the best way to update a hash within a hash?

From Dev

sort set in redis with hash in the collection

From Dev

What way is the best way to hash a password?

From Dev

Whats the best way to obtain a concurrent hash set when write operations are excess than read operations?

From Dev

Redis, how to store sets as the values of hash key

From Dev

Best way to store an OrderId in a cookie?

From Java

Best way to store password in database

From Dev

Best way to store status flags

From Dev

best way to store data in session

From Dev

Best way to store information on server

From Dev

The best way to store graph into the memory

From Dev

Best way to store a collection of objects

From Dev

Best way to store user settings

From Dev

Best way to store followed users

From Dev

best way to store session in codeigniter

From Dev

Best way for store data into client