A configuration driven redis client


2.0.04 years ago5 years agoMinified + gzip package size for @gasbuddy/configured-redis-client in KB



A small wrapper around redis to allow configuration from confit.

  "connections": {
    "redis": {
      "module": "require:@gasbuddy/configured-redis-client",


The redis client attached to req.gb.db is an ioredis Redis object.

Additional Utilities


Common redis ttl values can be found in Ttl.

req.gb.db.redis.Ttl.oneMinute // => 60
req.gb.db.redis.Ttl.oneHour // => 3600

Redis Keys

To make a key, use makeKey()

req.gb.db.redis.makeKey('redis', 'is', 'cool') // => 'redis:is:cool'

To create a key that begins with the name of your service, use makeServiceKey()

req.gb.db.redis.makeServiceKey('redis', 'is', 'cool') // => 'my-serv:redis:is:cool'

Caching the Result of a Function Call

Use memoize() to cache the result of a function call.

const redisClient = req.gb.db.redis;

const mySlowDataFunction = async () => {
  // slow things here

// return cached value. on cache miss, cache and return result of mySlowdataFunction()
const myVal = redisClient.memoize(
    key: redisClient.makeKey('redis', 'is', 'cool'), // defaults to name of function
    ttlSeconds: redisClient.Ttl.fiveMinutes, // defaults to one minute

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.