Redis prefix key naming is a convention where Redis keys are structured with a colon-delimited prefix to create logical namespaces, analogous to folders or tables in a traditional database.

Format

prefix:identifier
products:123
reset_token:abc456

Purpose

  • Prevents key collisions across different data domains
  • Enables folder-like browsing in tools like RedisInsight
  • Makes cache invalidation by domain possible (e.g., delete all products:* keys)

Implementation in NestJS

The Using Redis Client in NestJS article uses a RedisPrefixEnum to define prefixes as enum values, passed to repository methods:

async get(prefix: RedisPrefixEnum, key: string): Promise<string | null> {
  return this.redisClient.get(`${prefix}:${key}`);
}