{"id":44893,"library":"express-redis","title":"express-redis","description":"Express middleware that provides a shared Redis client connection (via the `redis` package) across all requests. Current stable version 2.0.1 uses `redis` ^2.6.2 (peer dependency). Release cadence is low/maintenance only. Key differentiator: simple, zero-config middleware that adds `req.db` for Redis access, with optional custom property name and support for all `redis.createClient` options. Unlike more complex caching or session middleware, it just exposes the raw Redis client per request.","status":"maintenance","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/elliotttf/express-redis","tags":["javascript"],"install":[{"cmd":"npm install express-redis","lang":"bash","label":"npm"},{"cmd":"yarn add express-redis","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-redis","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Redis client operations","package":"redis","optional":false},{"reason":"Required as a peer or installed; middleware expects Express app","package":"express","optional":true}],"imports":[{"note":"Package exports a single factory function, not a named export. Default import works in ESM with bundlers. In CommonJS, use require('express-redis')()","wrong":"const { redisMiddleware } = require('express-redis')","symbol":"default (function)","correct":"import redisMiddleware from 'express-redis'"},{"note":"CommonJS: no .default property. The module exports the factory function directly.","wrong":"const expressRedis = require('express-redis').default","symbol":"require('express-redis')","correct":"const middleware = require('express-redis')"},{"note":"Default property name is 'db'. To change, pass a custom name as fourth argument: require('express-redis')(port, host, options, 'redis') then use req.redis.","wrong":"req.redis.get('key', callback)","symbol":"req.db","correct":"req.db.get('key', callback)"}],"quickstart":{"code":"const express = require('express');\nconst redisMiddleware = require('express-redis');\n\nconst app = express();\n\n// Use middleware with default Redis connection (localhost:6379)\napp.use(redisMiddleware());\n\n// Example route using Redis\napp.get('/user/:id', (req, res, next) => {\n  req.db.get(`user:${req.params.id}`, (err, reply) => {\n    if (err) {\n      return next(err);\n    }\n    res.json({ id: req.params.id, data: reply });\n  });\n});\n\napp.listen(3000, () => console.log('Server running on port 3000'));","lang":"javascript","description":"Shows middleware setup with default Redis connection, reading a key via req.db.get()."},"warnings":[{"fix":"Specify a custom name like 'redisClient' as the fourth argument: app.use(require('express-redis')(6379, '127.0.0.1', {}, 'redisClient')) then use req.redisClient.","message":"The default property name on req is 'db', not 'redis', which may conflict with other middleware that use 'db'. Use a custom name to avoid collisions.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Either stick with `redis@^2.6.2` as peer dep, or migrate to a middleware that supports `redis@4+` (e.g., implement your own using modern async/await).","message":"The underlying `redis` package v2 is outdated. The `redis` v3+ is a major rewrite with breaking changes (returns promises, uses `createClient` differently). This middleware may not work with newer `redis` versions without compatibility issues.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use req.db (or custom property name) for Redis access. The custom name string affects both `req` and `res`, but by default only `req.db` exists.","message":"This middleware attaches to `req` only, not `res`. The README example uses `req.db`, but some users mistakenly expect `res.db`.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'2.0.1':23 '2.6.2':26 'access':46 'across':17 'add':42 'cach':61 'cadenc':30 'client':11,71 'complex':60 'config':39 'connect':12 'current':20 'custom':49 'depend':28 'differenti':35 'expos':67 'express':2,4 'express-redi':1 'javascript':74 'key':34 'low/maintenance':32 'middlewar':5,40,64 'name':51 'option':48,57 'packag':16 'peer':27 'per':72 'properti':50 'provid':7 'raw':69 'redi':3,10,15,25,45,70 'redis.createclient':56 'releas':29 'req.db':43 'request':19,73 'session':63 'share':9 'simpl':36 'stabl':21 'support':53 'unlik':58 'use':24 'version':22 'via':13 'zero':38 'zero-config':37","created_at":"2026-06-07T12:52:20.867026+00:00","updated_at":"2026-06-07T12:52:20.867026+00:00","problems":[{"fix":"Use middleware correctly: app.use(require('express-redis')());","cause":"Middleware not properly initialized, or called without parentheses: require('express-redis') returns a function, not middleware. You must execute it: require('express-redis')()","error":"TypeError: req.db.get is not a function"},{"fix":"Start Redis server (e.g., `redis-server`) or provide correct connection arguments: app.use(require('express-redis')(port, host));","cause":"Redis server not running or wrong port/host.","error":"Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED"},{"fix":"Install redis: npm install redis@^2.6.2","cause":"Missing peer dependency `redis`.","error":"Cannot find module 'redis'"}],"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/elliotttf/express-redis#readme","github":"https://github.com/elliotttf/express-redis","docs":null,"changelog":null,"pypi":null,"npm":"express-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}}