1.3.0 • Published 3 years ago
@empy/express-redis v1.3.0
@empy/express-redis
Install
npm install @empy/express-redis
Usage
Configuration options
Key | Type | Default | Description |
---|---|---|---|
ttl | number | 86400 | Duration, in seconds, to retain the cached value. |
debug | boolean | false | Enable debug messages. |
Redis Client
This module is not meant to manage the redis connection. It is expected that the app using it to manage the redis configuration.
It is written to work with the node-redis client. See the documentation for the client-configuration.
Express app
const redis = require('redis')
const expressRedis = require('@empy/express-redis')
const client = redis.createClient()
await client.connect()
const config = {} // See configuration options
const { cacheMiddleware } = expressRedis(config, redisClient)
Routing
General routing
It can be used to cache all matching express routes, identified by a path
or a regexp
.
const app = express()
app.use('/path/to/cache', cacheMiddleware)
app.use('/regexp_to_match/', cacheMiddleware)
Specific caching
It can also be used route by route, by chaining the middleware in the route declaration.
const app = express()
app.get('/route_to_cache', cacheMiddleware, (req, res, next) => {...})
Test
We use Mocha and Should for the tests. You can invoke tests like this:
npm run test