Registry / database / redis-typed-keys

redis-typed-keys

JSON →
library0.2.1jsnpmunverified

redis-typed-keys is a TypeScript library (v0.2.1, pre-1.0, irregular releases) that provides a type-safe wrapper around Redis commands, enforcing key naming conventions (prefixes, separators) and typed data structures (hashes, sets, sorted sets). Unlike raw redis or ioredis, it prevents runtime mistakes by ensuring keys follow defined patterns and values are serialized/deserialized correctly. It ships its own types but depends on a Redis client (e.g., ioredis).

npm install redis-typed-keys
INSTALL
IMPORT
SIG · REDIS-TYPED-KEYS
R
redis-typed-keys
databasejavascriptv0.2.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.

RedisTypedKeys
✓ import { RedisTypedKeys } from 'redis-typed-keys'
✗ const RedisTypedKeys = require('redis-typed-keys')
ESM-only; CJS require will not work.
createClient
✓ import { createClient } from 'redis-typed-keys'
✗ const { createClient } = require('redis-typed-keys')
Default export is a factory; named import is correct.
KeySchema
✓ import type { KeySchema } from 'redis-typed-keys'
TypeScript only; use import type for runtime-free types.

Shows typed Redis hash operations: set and get a user record using schema-defined key prefixes and field types.

import { RedisTypedKeys } from 'redis-typed-keys'; import Redis from 'ioredis'; const redisClient = new Redis({ host: process.env.REDIS_HOST || 'localhost' }); const client = new RedisTypedKeys(redisClient, { prefix: 'app:', schemas: { user: { key: (id: string) => `user:${id}`, fields: ['name', 'email'] as const, }, }, }); async function demo() { const userId = '123'; await client.hSet('user', userId, { name: 'Alice', email: 'alice@example.com' }); const user = await client.hGetAll('user', userId); console.log(user); } demo().catch(console.error);
Debug
Known issues
breakingKey schema configuration changed between 0.1.x and 0.2.x: now uses `schemas` object instead of `keys`.
fix
Update schema initialization: replace `keys` with `schemas` and adjust structure.
affects: >=0.2.0
deprecatedThe `.getClient()` method is deprecated in favor of direct access via `.client`.
fix
Use `client.client` instead of `client.getClient()`.
affects: >=0.2.0
gotchaAll keys must be defined in schema; unknown keys throw runtime errors.
fix
Ensure all used key names are added to the schema before operations.
affects: *
gotchaTypeScript strict mode required for full type safety; loose mode may allow untyped operations.
fix
Enable `strict` in tsconfig.json to enforce schema types.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'key')
Key schema name provided to operation does not exist in schemas map.
fix
Add the missing schema definition or correct the key name.
TypeError: client.getClient is not a function
Using deprecated getClient() method removed in 0.2.0.
fix
Use client.client directly (the underlying Redis connection).
Error: Redis connection refused (ECONNREFUSED)
ioredis cannot connect; Redis server not running or wrong host/port.
fix
Check that Redis is running locally or set REDIS_HOST environment variable.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
ioredisrequiredPeer dependency for actual Redis connection; the library only wraps commands.
Agent activity
14 hits · last 30 days
node
12
Meta
1
Resources
redis-typed-keys — npm install redis-typed-keys · libregistry