Skip to content

Caching with Redis

Chris Chang edited this page Sep 25, 2017 · 1 revision
const Cacheman = require('cacheman')
const CachemanRedis = require('cacheman-redis')
const { Messenger, Text } = require('launch-vehicle-fbm')
const redisUrlParse = require('redis-url-parse')

const cacheOptions = {
  engine: new CachemanRedis(redisUrlParse(process.env.REDIS_URL)),
  prefix: process.env.FACEBOOK_APP_ID,
  ttl: 7 * 24 * 60 * 60, // 1 week in seconds
}
const cache = new Cacheman('sessions', cacheOptions)
const messenger = new Messenger({ cache })

messenger.on('text', ({ reply, text }) => {
  reply(new Text(text))
})

messenger.start()
Clone this wiki locally