fastify / fastify-redis

Plugin to share a common Redis connection across Fastify.
MIT License
198 stars 31 forks source link

connect to Redis via TLS #164

Closed ghost closed 1 year ago

ghost commented 1 year ago

Prerequisites

Issue

I have the following piece of code which works perfectly when connecting to Redis.

import fastifyRedis from "@fastify/redis";
fastify.register(fastifyRedis, {
        host: '',
        port: 6379,
        username: 'test',
        password: 'test',
        family: 4,
        lazyConnect: true,
        closeClient: true, //close redis connection when fastify shuts down
    });

However, the Redis server that I have has TLS configured and there doesn't seem to be a straightforward way on how to enable TLS based on the connection options.

I've tried the following 2 versions and none of them worked, I'm not using Redis Sentinel.

fastify.register(fastifyRedis, {
        username: applicationConfig.redis.username,
        password: applicationConfig.redis.password,
        family: 4,
        enableTLSForSentinelMode: true,
        tls: {
            host: '',
            port: 6379,
        },
        lazyConnect: true,
        closeClient: true, //close redis connection when fastify shuts down
    });
astify.register(fastifyRedis, {
        username: applicationConfig.redis.username,
        password: applicationConfig.redis.password,
        family: 4,
        enableTLSForSentinelMode: true,
        sentinelTLS: {
            host: '',
            port: 6379,
        },
        lazyConnect: true,
        closeClient: true, //close redis connection when fastify shuts down
    });

Anyone faced this issue before? Is there any proper way or a workaround on how to get this working?

Thank you 😃

kibertoad commented 1 year ago

tls: {} should do the trick.

jsumners commented 1 year ago

https://github.com/luin/ioredis#tls-options