/* REDIS */
const redis = require('redis');

const client = redis.createClient({
  return_buffers: true,
  host: process.env.REDIS_URL,
  port: 6379
});

const { promisify } = require('util');

const getAsync = promisify(client.get).bind(client);

/**
 * cacheImage: Puts the given image in cache. This does not return anything.
 * @param {String} key This is what you use to get the image later
 * @param {Buffer<Image>} image This is what you want the key to get
 */
exports.cacheImage = (key, image) => {
  client.set(key, image, err => {
    if (err) {
      console.error(`Unable to cache image: ${err}`);
    }
  });
};

/**
 * getImageFromCache: fetches image from cache
 * @param {String} key Which image do you want? This is typically ${concept-id}-${height}-${width}
 * @returns {Buffer<Image>} the image associated with given cache key or null if none is found
 */
exports.getImageFromCache = async key => {
  try {
    const image = await getAsync(key);

    // workaround for bad cache entries that have the string "null" for the value
    if (image && image !== 'null') {
      console.log('got image from cache');
      return image;
    }

    console.log('image is not in cache');
    return null;
  } catch (err) {
    console.error(`Could not get image from cache: ${err}`);
    return null;
  }
};

@@ -33,24 +33,208 @@
 e('redis');%0A
+const redisHost = process.env.REDIS_URL %7C%7C 'localhost';%0Aconst redisPort = process.env.REDIS_PORT %7C%7C 6379;%0Aconst redisKeyExpireSeconds = process.env.REDIS_KEY_EXPIRE_SECONDS %7C%7C 84000;%0A%0A
 %0Aconst clien
@@ -290,37 +290,25 @@
   host: 
-process.env.REDIS_URL
+redisHost
 ,%0A  port
@@ -309,20 +309,25 @@
   port: 
-6379
+redisPort
 %0A%7D);%0A%0Aco
@@ -702,16 +702,45 @@
 , image,
+ 'EX', redisKeyExpireSeconds,
  err =%3E 

Expire browse scaler keys. Config port.