0.0.2 • Published 5 years ago
fastify-redis-io v0.0.2
fastify-ioredis
ioredis wrapper for fastify
A robust, performance-focused and full-featured Redis client for Node.js.
Supports Redis >= 2.6.12 and (Node.js >= 6).
To view full docs, please visit the ioredis.
Install
npm i -S fastify-ioredis
Usage
const fastify = require('fastify')()
const Redis = require('fastify-redis-io')
fastify.register(Redis,
{
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
}, err => {
if (err) throw err
}
)
fastify.redis.set('foo', 'bar');
fastify.redis.get('foo', function (err, result) {
console.log(result)
});
// Or using a promise if the last argument isn't a function
fastify.redis.get('foo').then(function (result) {
console.log(result)
});
// Arguments to commands are flattened, so the following are the same:
fastify.redis.sadd('set', 1, 3, 5, 7)
redis.sadd('set', [1, 3, 5, 7])
// All arguments are passed directly to the redis server:
fastify.redis.set('key', 100, 'EX', 10)
fastify.get('/', async (request, reply) => {
reply.type('application/json').code(200)
return {
name: 'fastify-ioredis',
version: '0.0.1'
}
})
const start = async () => {
try {
await fastify.listen(3000)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
start()