1.0.0 • Published 7 years ago

fastify-ioredisjs v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

fastify-ioredis

js-standard-style Build Status

Ioredis for Fastify.

Install

npm i fastify-ioredisjs --save

Usage

Add it to you project with register and you are done! You can access the Redis client via fastify.redis.

More usage see Ioredis

const fastify = require('fastify')

fastify.register(require('fastify-ioredisjs'), {
  host: '127.0.0.1'
}, err => {
  if (err) throw err
})

fastify.get('/foo', (req, reply) => {
  const { redis } = fastify
  redis.get(req.query.key, (err, val) => {
    reply.send(err || val)
  })
})

fastify.post('/foo', (req, reply) => {
  const { redis } = fastify
  redis.set(req.body.key, req.body.value, (err) => {
    reply.send(err || { status: 'ok' })
  })
})

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})

License

Licensed under MIT.