Skip to content

Commit

Permalink
Added IORedis connection status with node_redis connected
Browse files Browse the repository at this point in the history
  • Loading branch information
sidgujrathi committed Feb 8, 2021
1 parent f27cb2b commit 48b269d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/apicache.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ function ApiCache() {
function cacheResponse(key, value, duration) {
var redis = globalOptions.redisClient
var expireCallback = globalOptions.events.expire

if (redis && redis.connected) {
// Check if redis client is availeble and
// Also checks if redis.connected in case of node_redis and redis.status for ioredis
var isRedisAndConnected = redis ? redis.connected || redis.status === 'ready' : false
if (isRedisAndConnected) {
try {
redis.hset(key, 'response', JSON.stringify(value))
redis.hset(key, 'duration', duration)
Expand Down

0 comments on commit 48b269d

Please sign in to comment.