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 ...

Get Redis Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.