What are the normal naming convention for keys in redis? I've seen values separated by :
but I'm not sure what the normal convention is, or why.
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 the ways that work for people and why they chose them.
Best Solution
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 be a 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.