Registry / database / think-redis

think-redis

JSON →
library1.1.4jsnpmunverified

think-redis is a Redis wrapper for ThinkJS framework (current version 1.1.4) built on top of ioredis. It provides a simplified promise-based API for common Redis operations like set, get, delete, increase, and decrease. Configuration options mirror ioredis. No frequent releases; it is a thin wrapper providing a ThinkJS-friendly interface with support for expired keys in milliseconds or seconds and event-driven connection handling. Differentiates from raw ioredis by offering convenience methods (e.g., `delete`, `increase`, `decrease`) and a constructor that accepts a config object.

npm install think-redis
INSTALL
IMPORT
SIG · THINK-REDIS
T
think-redis
databasejavascriptv1.1.4
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.

Redis
✓ import Redis from 'think-redis'
✗ const Redis = require('think-redis').default
Default export is the Redis constructor. Use ESM import or CJS with destructuring; the module does not have a named export 'Redis'.
new Redis(config)
✓ const redis = new Redis({ host: 'localhost', port: 6379 })
✗ new redis({})
Configuration object passed to constructor. Options are same as ioredis: https://github.com/luin/ioredis/blob/master/lib/redis.js
redis.set(key, value, ttl)
✓ redis.set('foo', 'bar', 5000)
✗ redis.set('foo', 'bar', 'EX', 5)
For TTL in seconds, use the ioredis pattern: set(key, value, 'EX', seconds). For milliseconds, use 'PX'.
redis.get(key)
✓ const val = await redis.get('foo')
✗ const val = redis.get('foo')
All methods return promises; must be awaited.

Demonstrates constructing a Redis client, setting/getting a key, incrementing a counter, and listening for the connect event.

import Redis from 'think-redis'; const redis = new Redis({ host: process.env.REDIS_HOST ?? '127.0.0.1', port: parseInt(process.env.REDIS_PORT ?? '6379'), password: process.env.REDIS_PASSWORD ?? '' }); (async () => { await redis.set('key', 'value'); const val = await redis.get('key'); console.log(val); // 'value' await redis.increase('counter'); const count = await redis.get('counter'); console.log(count); // '1' redis.on('connect', () => console.log('connected')); process.exit(0); })();
Debug
Known issues
gotchaset() with TTL: think-redis recommends milliseconds but the API expects ioredis syntax for seconds ('EX') or milliseconds ('PX').
fix
Use redis.set(key, value, ttl) for milliseconds, or redis.set(key, value, 'EX', seconds) for seconds.
affects: >=1.0.0
gotchaAll methods return promises; forgetting await will return a promise object.
fix
Use await or .then() on all redis calls.
affects: >=1.0.0
deprecatedthink-redis has not been updated since 2017 and may not support newer ioredis features or Redis 6+.
fix
Consider using ioredis directly or a more actively maintained wrapper.
affects: <=1.1.4
Errors
Common errors & fixes
TypeError: redis_1.default is not a constructor
Using incorrect import syntax in CommonJS.
fix
Use `const Redis = require('think-redis').default;` or switch to ESM `import Redis from 'think-redis'`.
UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
Redis server not running or host/port incorrect.
fix
Start Redis server or set correct host/port in config (e.g., REDIS_HOST env var).
TypeError: redis.get is not a function
Import is not the Redis instance; likely imported the class without instantiation.
fix
Create an instance: `const redis = new Redis(config);` then call redis.get().
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
ioredisrequiredthink-redis wraps ioredis for all Redis operations
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
think-redis — npm install think-redis · libregistry