Registry / storage / secure-store-redis

secure-store-redis

JSON →
library4.1.3jsnpmunverified

A Node.js wrapper for encrypting and decrypting data stored in Redis using AES-256-GCM encryption with unique IVs per entry. Currently at version 4.1.3, actively maintained. Key differentiators include built-in secret key validation via SecretValidator, support for both Redis connection options and existing ioredis clients (including Cluster), automatic UUID-based prefixing, and ESM-only with TypeScript types. Provides simple save/get/delete operations on serialized JSON objects with strong encryption.

npm install secure-store-redis
INSTALL
IMPORT
SIG · SECURE-STORE-REDIS
S
secure-store-redis
storagejavascriptv4.1.3
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.

SecureStore
import SecureStore from 'secure-store-redis'
import { SecureStore } from 'secure-store-redis'
SecureStore is the default export (not named). For TypeScript, use the default import pattern; named import will fail at runtime.
SecretValidator
import { SecretValidator } from 'secure-store-redis'
import SecretValidator from 'secure-store-redis'
SecretValidator is a named export, not default. Also available as SecretValidator.generate() is a static method.
type SecureStoreConfig
import type { SecureStoreConfig } from 'secure-store-redis'
import { SecureStoreConfig } from 'secure-store-redis'
SecureStoreConfig is a TypeScript interface, imported as type. Importing as a runtime value will produce an error in bundlers.

Creates an encrypted Redis store, saves and retrieves a JSON object, then disconnects. Uses auto-generated secret and default Redis connection.

import SecureStore, { SecretValidator } from "secure-store-redis"; const store = new SecureStore({ uid: "myApp", secret: SecretValidator.generate(), redis: { url: "redis://localhost:6379" }, }); await store.connect(); await store.save("key", { foo: "bar" }); const data = await store.get("key"); console.log(data); // { foo: "bar" } await store.disconnect();
Debug
Known issues
breakingIn v4.0.0 the constructor config changed: `redis` option no longer accepts a `host` string directly; use `{ url: '...' }` or `{ client: ... }`.
fix
Update config to use `redis: { url: 'redis://...' }` or pass an existing ioredis client as `redis: { client: myClient }`.
affects: >=4.0.0 <4.0.0
deprecatedThe `secret` option must be exactly 32 characters; shorter secrets will be rejected by default.
fix
Use `SecretValidator.generate()` to produce a valid 32-character secret, or set `allowWeakSecrets: true` in the constructor (not recommended).
affects: >=4.0.0
gotchaWhen using an external Redis client, calling `disconnect()` does NOT close the Redis connection. The store assumes you manage the client lifecycle.
fix
Always call `redis.quit()` after you are done with the store to cleanly close the client.
affects: >=4.0.0
gotchaThe `uid` prefix is automatically appended to all Redis keys. For example, with `uid: 'myApp'`, saving `'key'` results in Redis key `'myApp:key'`. This may conflict with other apps using the same prefix.
fix
Choose a unique `uid` for each application to avoid key collisions.
affects: >=4.0.0
breakingIn v3.x, the default export was `{ SecureStore, SecretValidator }` (named exports only). In v4.x, SecureStore became the default export and SecretValidator remains a named export.
fix
Update imports: `import SecureStore from 'secure-store-redis'` and `import { SecretValidator } from 'secure-store-redis'`.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: SecretValidator.generate is not a function
SecretValidator was imported incorrectly (e.g., as default instead of named).
fix
Use `import { SecretValidator } from 'secure-store-redis'`
Error: Secret must be exactly 32 characters long.
The provided secret is not 32 characters long and `allowWeakSecrets` is not set.
fix
Generate a valid secret: `const secret = SecretValidator.generate();` or set `allowWeakSecrets: true` in options.
Error: Redis connection refused (ECONNREFUSED)
Redis server is not running or the connection URL is incorrect.
fix
Start Redis locally or provide correct `redis.url`. Example: `redis: { url: 'redis://localhost:6379' }`
TypeError: (0 , require(...)) is not a function (CJS error)
Using CommonJS `require()` to import an ESM-only package.
fix
Switch to ESM: use `import` syntax, or use dynamic import: `const SecureStore = await import('secure-store-redis');`
Upgrade
Version history
4.1.3latest on npm
Audit
Dependencies
ioredisrequiredRequired for Redis client (used internally if not provided externally). Must be installed separately (peer dependency).
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources