Alex Rivera | Logout

Redis key naming conventions?

Asked 2011-08-06T07:34:32.493
297

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.

Edit
Report

1 Answer

6

I don't know if there really are widespread "best practices" for Redis key naming yet.

I've experimented with using ASCII NUL characters as my separators (since Redis and Python are both 8-bit clean). It looks a little ugly if you're looking at raw keys, but the idea is to hide it behind an abstraction layer. Colon and pipe symbols are obvious alternatives so long as the components of your name space are either guaranteed not to use them or you're willing to encode each component as necessary. However, if you'd be encoding them then you'd want develop the abstraction layer and avoiding viewing raw keys anyway ... which brought me right back to just using \0 in my reasoning.

I'll be interesting in seeing if any other opinions are articulated on this.

answered 2011-08-09T09:11:53.193

Your Answer