Reputation: 4664
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?
Upvotes: 1
Views: 294
Reputation: 5981
You should not be worried about this. Redis is blazing fast and it's the usual way to use it: making a lot of simple requests. Moreover node-redis automatically pipelines commands. If you really have perfomance issues, ensure you installed hiredis. Node_redis will use it.
Upvotes: 0
Reputation: 49942
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.
Upvotes: 1