Registry / database / create-redis-key

create-redis-key

JSON →
library1.0.1jsnpmunverified

A TypeScript utility for creating Redis keys with type-safe template literals (v1.0.1, stable). Supports nested configuration objects to define reusable Redis key templates with parameters, using TypeScript's template literal types (requires TS 4.1+). Provides three usage modes: a static map via createRedisKeysMap(), a dynamic key object, and direct string templates. Key differentiator: full type safety with parameter autocompletion and compile-time validation of required and optional parameters. Lightweight, zero dependencies, ships TypeScript types.

npm install create-redis-key
INSTALL
IMPORT
SIG · CREATE-REDIS-KEY
C
create-redis-key
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createRedisKey
import { createRedisKey } from 'create-redis-key'
import createRedisKey from 'create-redis-key'
ESM named export; default export does not exist.
createRedisKeysMap
import { createRedisKeysMap } from 'create-redis-key'
const { createRedisKeysMap } = require('create-redis-key');
Works in both ESM and CJS; require is correct for CJS, but wrong if used in an ESM context.

Demonstrates two ways to create Redis keys: with createRedisKeysMap for reusable templates and direct template string.

import { createRedisKey, createRedisKeysMap } from 'create-redis-key'; // Option 1: Using createRedisKeysMap (recommended) const keysConfig = createRedisKeysMap({ post: 'posts:%PostID%', user: 'users:%UserID%', } as const); const postKey = createRedisKey(keysConfig.post, { PostID: '123' }); console.log(postKey); // 'posts:123' // Option 2: Direct template const userKey = createRedisKey('users:%UserID%', { UserID: '456' }); console.log(userKey); // 'users:456'
Debug
Known issues
gotchaYou must append `as const` to the config object when using createRedisKeysMap for literal type inference.
fix
Add 'as const' after the object literal: createRedisKeysMap({ key: 'template' } as const)
affects: >=1.0
gotchaAll parameters in a template are required by default. Missing parameters cause TypeScript compile error.
fix
Ensure every %ParamName% in the template has a corresponding key in the params object.
affects: >=1.0
deprecatedOption 2 (dynamic key object with placeholders) is documented but may be removed in future versions.
fix
Use createRedisKeysMap() or direct string templates instead.
affects: 1.0
Errors
Common errors & fixes
TypeScript error: 'createRedisKeysMap' is possibly 'undefined'.
Not importing the function correctly.
fix
Use proper import: import { createRedisKeysMap } from 'create-redis-key';
Argument of type 'readonly [string, string]' is not assignable to parameter of type 'string'.
Using a tuple instead of a string for the template.
fix
Pass a single template string, not an array.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
create-redis-key — npm install create-redis-key · libregistry