Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wotermelon/fastify-ioredisjs
Ioredis for fastify
https://github.com/wotermelon/fastify-ioredisjs
Last synced: 25 days ago
JSON representation
Ioredis for fastify
- Host: GitHub
- URL: https://github.com/wotermelon/fastify-ioredisjs
- Owner: wotermelon
- License: mit
- Created: 2017-11-02T07:07:10.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-06T05:15:16.000Z (about 7 years ago)
- Last Synced: 2024-12-04T21:38:19.088Z (29 days ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-ioredis
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/wotermelon/fastify-ioredisjs.svg?branch=master)](https://travis-ci.org/wotermelon/fastify-ioredisjs)
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](https://github.com/luin/ioredis)
```js
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](./LICENSE).