Skip to content

Connecting to Redis using TLS/SSL

Pass a RedisTls to the connection pool (or a single RedisConnection).

// server certificate signed by a CA trusted by the JVM
val connPool = RedisConnectionPool(
    addr = InetSocketAddress("my-redis.example.com", 6380),
    tls = RedisTls(),
)

For a private CA, pass an SSLContext which trusts it. For mutual TLS, initialize the SSLContext with a KeyManager holding the client certificate; no further configuration is needed:

val sslContext = SSLContext.getInstance("TLS").apply {
    init(
        keyManagers,   // client certificate, mTLS only 
        trustManagers, // private CA 
        null
    )
}
val connPool = RedisConnectionPool(
    addr = InetSocketAddress("my-redis.example.com", 6380),
    tls = RedisTls(sslContext),
)

The host name of addr is verified against the server certificate, which can be switched off with RedisTls(verifyHostname = false). The TLS handshake must finish within connectTimeoutMs.