{"id":46301,"library":"safe-redis-schema","title":"safe-redis-schema","description":"Type-safe and validated data schemas for Redis with TypeScript. Version 1.1.0 provides runtime and compile-time validation for Redis data structures like hashes, counters, and objects. Ensures key uniqueness across schema definitions to prevent accidental reuse. Different from generic Redis ORMs by enforcing schema validation at both read and write, with built-in TypeScript type inference. Low release cadence; stable for production use cases requiring strict data integrity.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install safe-redis-schema","lang":"bash","label":"npm"},{"cmd":"yarn add safe-redis-schema","lang":"bash","label":"yarn"},{"cmd":"pnpm add safe-redis-schema","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for runtime type validation (Safe.str, Safe.int, Safe.obj).","package":"safe-portals","optional":false}],"imports":[{"note":"ESM-only; CommonJS require works but types may not infer correctly.","wrong":"const RedisStore = require('safe-redis-schema').RedisStore;","symbol":"RedisStore","correct":"import { RedisStore } from 'safe-redis-schema';"},{"note":"Named export, not default.","wrong":"import defineObj from 'safe-redis-schema';","symbol":"defineObj","correct":"import { defineObj } from 'safe-redis-schema';"},{"note":"Exported from package root, no subpath.","wrong":"import { defineHashOf } from 'safe-redis-schema/defineHashOf';","symbol":"defineHashOf","correct":"import { defineHashOf } from 'safe-redis-schema';"}],"quickstart":{"code":"import { RedisStore, defineHashOfCounters, defineHashOf } from 'safe-redis-schema';\nimport * as Safe from 'safe-portals';\n\nconst secureRandomSecret = process.env.REDIS_URL ?? '';\nconst store = new RedisStore(secureRandomSecret);\nconst ns = store.namespacedBy('myApp:');\n\nconst pageHits = defineHashOfCounters(ns, 'pageHits');\nconst users = defineHashOf(ns, 'users', Safe.obj({ name: Safe.str, age: Safe.int }));\n\nasync function main() {\n  await pageHits.incrby('/home', 1);\n  const count = await pageHits.get('/home');\n  console.log('Page hits:', count);\n\n  await users.hset('user:1', { name: 'Alice', age: 30 });\n  const user = await users.hget('user:1');\n  console.log('User:', user);\n}\nmain().catch(console.error);","lang":"typescript","description":"Defines and uses a Redis schema with validated hashes and counters, demonstrating key reuse prevention and type safety."},"warnings":[{"fix":"Ensure each Redis key is used only once across schema definitions (e.g., do not define both defineObj and defineHashOfCounters for same key).","message":"Key reuse across schema types throws error","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Set REDIS_URL environment variable or pass URL to RedisStore constructor.","message":"Redis URL must be provided via environment variable or constructor","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Enable strict mode in tsconfig.json to benefit from type inference.","message":"TypeScript strict mode required for full type safety","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.0':17 'accident':42 'across':37 'built':60 'built-in':59 'cadenc':67 'case':72 'compil':22 'compile-tim':21 'counter':31 'data':10,27,75 'definit':39 'differ':44 'enforc':50 'ensur':34 'generic':46 'hash':30 'infer':64 'integr':76 'javascript':77 'key':35 'like':29 'low':65 'object':33 'orm':48 'prevent':41 'product':70 'provid':18 'read':55 'redi':3,13,26,47 'releas':66 'requir':73 'reus':43 'runtim':19 'safe':2,7 'safe-redis-schema':1 'schema':4,11,38,51 'stabl':68 'strict':74 'structur':28 'time':23 'type':6,63 'type-saf':5 'typescript':15,62,78 'uniqu':36 'use':71 'valid':9,24,52 'version':16 'write':57","created_at":"2026-06-07T12:59:16.108090+00:00","updated_at":"2026-06-07T12:59:16.108090+00:00","problems":[{"fix":"Use unique keys for each schema definition or namespace them appropriately.","cause":"Attempted to define a schema with a key that is already used by another schema definition.","error":"Error: Key 'pageHits' already used for a different schema type"},{"fix":"Ensure RedisStore is correctly imported: import { RedisStore } from 'safe-redis-schema';","cause":"Called namespacedBy on something that is not a RedisStore instance, possibly due to incorrect import.","error":"TypeError: store.namespacedBy is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"safe-redis-schema","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}