Skip to main content
Version: 2.x

Configuration

Redis.singleNode connects to the server described by a RedisConfig; Redis.local uses RedisConfig.Local. This page lists every setting and shows how to supply it.

RedisConfigโ€‹

RedisConfig is a case class with the following fields:

FieldTypeDefaultMeaning
hostStringnoneServer host name
portIntnoneServer port
sniOption[String]NoneServer name sent during the TLS handshake
sslBooleanfalseWhether to connect over TLS
verifyCertificateBooleantrueWhether to verify the server certificate
requestQueueSizeInt16Size of the queue of requests waiting to be sent
authOption[RedisConfig.Auth]NoneCredentials, sent when the connection opens

RedisConfig.Local is RedisConfig("localhost", 6379).

Connecting to a Serverโ€‹

To connect to a named host and supply the config as a layer:

import zio._
import zio.redis._

val config: ULayer[RedisConfig] =
ZLayer.succeed(RedisConfig("redis.example.com", 6379))

val redis: ZLayer[Any, RedisError.IOError, Redis] =
ZLayer.make[Redis](
config,
ZLayer.succeed[CodecSupplier](CodecSupplier.utf8),
Redis.singleNode
)

Authentication and TLSโ€‹

To authenticate with a password, set auth to a RedisConfig.Auth. Add a username when the server uses ACL users. To use TLS, set ssl = true:

import zio._
import zio.redis._

val secure: RedisConfig =
RedisConfig(
host = "redis.example.com",
port = 6380,
ssl = true,
auth = Some(RedisConfig.Auth("secret", Some("app-user")))
)

Set verifyCertificate = false only for development servers with self-signed certificates.

RedisUriโ€‹

RedisUri identifies a node by host and port. It is used by RedisClusterConfig to list cluster addresses, and it renders as redis://host:port (or rediss:// when TLS is on). The companion offers several apply overloads:

import zio.redis._

val plain = RedisUri("localhost", 6379)
val parsed = RedisUri("localhost:6379")
val tls = RedisUri("redis.example.com:6380", ssl = true)

RedisUri.apply with a "host:port" string splits on :, so it does not accept IPv6 literals or full redis:// URLs.

ZIO Chat

Hello! ๐Ÿ˜Š I'm your ZIO Chat Bot, designed to be your go-to resource for all things ZIO! Whether you're new to this powerful functional effect system or a seasoned pro, I'm here to assist you. ZIO empowers you to build concurrent and resilient applications in Scala, offering referential transparency, composable data types, type-safety, and more. So, go ahead and ask me anything about ZIO โ€“ I'm here to provide the answers you need! ๐Ÿค–