What is the standard naming convention for keys in redis? I’ve seen values separated by :, but I’m not sure what the standard convention is.
For a user, would you do something like:user:00
If the user’s id was 00
Are you able to query for just the beginning of the key to return all users?
I’m mainly just hoping to avoid any future problems by researching how that work for people and why they chose them.
Yes, colon sign
:is a convention when naming keys. In this tutorial on redis website is stated: Try to stick with a schema. For instance "object-type:id:field" can bea nice idea, like in "user:1000:password". I like to use dots for
multi-words fields, like in "comment:1234:reply.to".
If you mean something like directly querying for all keys which starts with
user:there is a keys command for that. This command should be however used only for debugging purpose since it’s O(N) because it’s searching through all keys stored in database.More appropriate solution for this problem is to create dedicated key, let’s name it
users, which will store all the users keys, for example, in list or set data structure.