{"id":46613,"library":"think-redis","title":"think-redis","description":"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.","status":"maintenance","version":"1.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/thinkjs/think-redis","tags":["javascript","think-redis"],"install":[{"cmd":"npm install think-redis","lang":"bash","label":"npm"},{"cmd":"yarn add think-redis","lang":"bash","label":"yarn"},{"cmd":"pnpm add think-redis","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"think-redis wraps ioredis for all Redis operations","package":"ioredis","optional":false}],"imports":[{"note":"Default export is the Redis constructor. Use ESM import or CJS with destructuring; the module does not have a named export 'Redis'.","wrong":"const Redis = require('think-redis').default","symbol":"Redis","correct":"import Redis from 'think-redis'"},{"note":"Configuration object passed to constructor. Options are same as ioredis: https://github.com/luin/ioredis/blob/master/lib/redis.js","wrong":"new redis({})","symbol":"new Redis(config)","correct":"const redis = new Redis({ host: 'localhost', port: 6379 })"},{"note":"For TTL in seconds, use the ioredis pattern: set(key, value, 'EX', seconds). For milliseconds, use 'PX'.","wrong":"redis.set('foo', 'bar', 'EX', 5)","symbol":"redis.set(key, value, ttl)","correct":"redis.set('foo', 'bar', 5000)"},{"note":"All methods return promises; must be awaited.","wrong":"const val = redis.get('foo')","symbol":"redis.get(key)","correct":"const val = await redis.get('foo')"}],"quickstart":{"code":"import Redis from 'think-redis';\n\nconst redis = new Redis({\n  host: process.env.REDIS_HOST ?? '127.0.0.1',\n  port: parseInt(process.env.REDIS_PORT ?? '6379'),\n  password: process.env.REDIS_PASSWORD ?? ''\n});\n\n(async () => {\n  await redis.set('key', 'value');\n  const val = await redis.get('key');\n  console.log(val); // 'value'\n  await redis.increase('counter');\n  const count = await redis.get('counter');\n  console.log(count); // '1'\n  redis.on('connect', () => console.log('connected'));\n  process.exit(0);\n})();","lang":"javascript","description":"Demonstrates constructing a Redis client, setting/getting a key, incrementing a counter, and listening for the connect event."},"warnings":[{"fix":"Use redis.set(key, value, ttl) for milliseconds, or redis.set(key, value, 'EX', seconds) for seconds.","message":"set() with TTL: think-redis recommends milliseconds but the API expects ioredis syntax for seconds ('EX') or milliseconds ('PX').","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use await or .then() on all redis calls.","message":"All methods return promises; forgetting await will return a promise object.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider using ioredis directly or a more actively maintained wrapper.","message":"think-redis has not been updated since 2017 and may not support newer ioredis features or Redis 6+.","severity":"deprecated","affected_versions":"<=1.1.4"}],"env_vars":null,"search_vec":"'1.1.4':16 'accept':90 'api':29 'base':28 'built':17 'common':31 'config':92 'configur':41 'connect':72 'constructor':88 'conveni':80 'current':14 'decreas':40,85 'delet':37,83 'differenti':74 'driven':71 'e.g':82 'event':70 'event-driven':69 'expir':62 'framework':13 'frequent':46 'friend':57 'get':36 'handl':73 'increas':38,84 'interfac':58 'ioredi':21,44,77 'javascript':94 'key':63 'like':34 'method':81 'millisecond':65 'mirror':43 'object':93 'offer':79 'oper':33 'option':42 'promis':27 'promise-bas':26 'provid':23,53 'raw':76 'redi':3,6,9,32,97 'releas':47 'second':67 'set':35 'simplifi':25 'support':60 'thin':51 'think':2,5,96 'think-redi':1,4,95 'thinkj':12,56 'thinkjs-friend':55 'top':19 'version':15 'wrapper':10,52","created_at":"2026-06-07T13:00:47.534634+00:00","updated_at":"2026-06-07T13:00:47.534634+00:00","problems":[{"fix":"Use `const Redis = require('think-redis').default;` or switch to ESM `import Redis from 'think-redis'`.","cause":"Using incorrect import syntax in CommonJS.","error":"TypeError: redis_1.default is not a constructor"},{"fix":"Start Redis server or set correct host/port in config (e.g., REDIS_HOST env var).","cause":"Redis server not running or host/port incorrect.","error":"UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379"},{"fix":"Create an instance: `const redis = new Redis(config);` then call redis.get().","cause":"Import is not the Redis instance; likely imported the class without instantiation.","error":"TypeError: redis.get 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":"https://github.com/thinkjs/think-redis#readme","github":"https://github.com/thinkjs/think-redis","docs":null,"changelog":null,"pypi":null,"npm":"think-redis","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}}