Table school:
3 fields:
sid (school id)
s_name(school_name)
s_type(school type)
Table user:
2 fields:
user_id(user id)
name(user name)
Table school_user_relationship:
3 fields:
rid(relationship id)
sid(school id)
user_id(user id)
How to use Redis to optimize the following two requirements?
Data structure: hash? set? bitset?
When not using any optimization, the query time is a bit long. Therefore, optimization is very likely to graduate. But I don't have any plans yet.
Your question makes it sound like you have a relational database (SQL) approach to your problem. Redis, on the other hand, is, at its core, a key-value store, or an associative array. The Java developer kit provides the HashMap data type as a key-value store. Python provides dictionaries and Javascript provides objects with properties. php and perl provide associative arrays
Let's just call the data structure a dictionary (generic, not python). In all these data structures, and in redis, you store, let us say, your user data by doing something like this pseudo code to put your user's name into a usernames dictionary. ( <--
is the pseudo code assignment operator.)
usernames[user_id] <-- name
Then, later if you know a user's id you can get the name like so
name <-- usernames[user_id]
But if you know the user's name and you want their id, you need a separate data structure
userids[name] <-- user_id
and do this to recover the id by name.
user_id <-- userids[name]
In SQL you could say SELECT user_id FROM users WHERE name = whatever
, but dictionaries don't work that way (not efficiently anyhow).
Dictionaries can have dictionaries (HASH in redis) and sets (SET in redis) as values. So you can have a dictionary with one entry for each school that is the set of user ids for people enrolled in that school
A good way to approach a well-performing design for redis is to work out how you would do it in an ordinary programming language with dictionaries.