Redis key naming conventions?

Viewed 101214

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.

5 Answers

For your usecase it seems to me HSET/HGET would be a better fit. There is also HKEYS command.

All those commands have same complexity as GET/SET/KEYS, so why not use them?

You could have this structure then:

  • users > 00 > value
  • users > 01 > value

or:

  • users:username > 00 > value
  • users:username > 01 > value

Just extract user's ID and use it as a hash key. I personally prefer this approach as it feels nicer and also you can easily query for existing user IDs.

Related