Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "daily"
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI workflow
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
services:
redis:
image: redis
ports:
- 6379:6379
options: --entrypoint redis-server
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install --ignore-scripts
- name: Test
run: npm test
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fastify-redis

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/fastify/fastify-redis.svg?branch=master)](https://travis-ci.org/fastify/fastify-redis) [![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-redis.svg)](https://greenkeeper.io/)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![CI workflow](https://github.com/fastify/fastify-redis/workflows/CI%20workflow/badge.svg)

Fastify Redis connection plugin, with this you can share the same Redis connection in every part of your server.

Expand Down
24 changes: 5 additions & 19 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import * as Fastify from 'fastify';
import Fastify, { FastifyPlugin } from 'fastify';
import { Redis, RedisOptions } from 'ioredis';

import { Server, IncomingMessage, ServerResponse } from 'http';
import { Http2Server, Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from 'http2';

declare module 'fastify' {
interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> {
interface FastifyInstance {
redis: Redis;
}
}

declare interface FastifyRedisPlugin<HttpServer, HttpRequest, HttpResponse>
extends Fastify.Plugin<
HttpServer,
HttpRequest,
HttpResponse,
RedisOptions | { client: Redis }
> {}

export type FastifyRedisPlugin = RedisOptions | { client: Redis }

declare const fastifyRedis: FastifyRedisPlugin<
Server | Http2Server | Http2SecureServer,
IncomingMessage | Http2ServerRequest,
ServerResponse | Http2ServerResponse
>;
declare const fastifyRedis: FastifyPlugin<FastifyRedisPlugin>;

export = fastifyRedis;
export default fastifyRedis;
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "npm run lint && npm run unit && npm run typescript",
"lint": "standard",
"unit": "tap test/test.js",
"typescript": "tsc --project ./test/types/tsconfig.json",
"typescript": "tsd",
"redis": "docker run -p 6379:6379 --rm redis:5"
},
"repository": {
Expand All @@ -32,19 +32,18 @@
"devDependencies": {
"@types/ioredis": "^4.0.18",
"@types/node": "^12.11.1",
"fastify": "^2.5.0",
"fastify": "^3.0.0-rc.1",
"proxyquire": "^2.1.3",
"redis": "^2.8.0",
"standard": "^14.0.2",
"tap": "^12.7.0"
"tap": "^12.7.0",
"tsd": "^0.11.0"
},
"dependencies": {
"fastify-plugin": "^1.6.0",
"fastify-plugin": "^2.0.0",
"ioredis": "^4.10.0"
},
"greenkeeper": {
"ignore": [
"tap"
]
"tsd": {
"directory": "test/types"
}
}
26 changes: 13 additions & 13 deletions test/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import * as Fastify from 'fastify';
import * as fastifyRedis from '../..';
import Fastify, { FastifyRequest } from 'fastify';
import fastifyRedis from '../..';
import * as IORedis from 'ioredis';

import * as http from 'http';
import * as http2 from 'http2';

const app: Fastify.FastifyInstance<
http.Server | http2.Http2Server | http2.Http2SecureServer,
http.IncomingMessage | http2.Http2ServerRequest,
http.ServerResponse | http2.Http2ServerResponse
> = Fastify();
const app = Fastify();
const redis = new IORedis({ host: 'localhost', port: 6379 });

app.register(fastifyRedis, { host: '127.0.0.1' });
app.register(fastifyRedis, { client: redis });

app.get('/foo', (req, reply) => {
app.get('/foo', (req: FastifyRequest, reply) => {
const { redis } = app;
redis.get(req.query.key, (err, val) => {
const query = req.query as {
key: string
}
redis.get(query.key, (err, val) => {
reply.send(err || val);
});
});

app.post('/foo', (req, reply) => {
const { redis } = app;
redis.set(req.body.key, req.body.value, err => {
const body = req.body as {
key: string,
value: string
}
redis.set(body.key, body.value, err => {
reply.send(err || { status: 'ok' });
});
});
9 changes: 0 additions & 9 deletions test/types/tsconfig.json

This file was deleted.