Keys without a namespace
It is good practice to use namespaces when defining your keys in Redis in order to avoid key name collisions and to organize your keys based on your application section or area.
In SQL databases, a namespace can be represented by the database name or the database tables.
Also, in a SQL database, it is reasonable to assume that a database called music-online
has tables called album
, song
, and author
.
Redis does not support namespacing. Usually, key name conventions are used to mimic namespaces. A common way of adding namespaces to Redis keys is by prepending a namespace (that is, namespace:key_name). Some Redis clients support addition of a prefix to all Redis keys.
Here are a few examples of key names with namespaces:
music-online:song:1
music-online:song:2
music-online:album:10001:metadata
music-online:album:10001:songs
music-online:author:123
Tip
Multiple databases are not an excuse not to use proper key naming. Always use consistent namespaces.