Skip to main content
Version: 2.x

Introduction to ZIO Redis

Development CI Badge Sonatype Releases Sonatype Snapshots javadoc ZIO Redis

Introductionโ€‹

ZIO Redis is a ZIO-native Redis client. It aims to provide a type-safe and performant API for accessing Redis instances.

Installationโ€‹

To use ZIO Redis, add the following line to your build.sbt:

libraryDependencies += "dev.zio" %% "zio-redis" % "1.3.2"

Featuresโ€‹

  • Type-safe commands. Results are decoded to any type with a ZIO Schema Schema; see Codecs.
  • All major command groups. Strings, keys, hashes, lists, sets, sorted sets, streams, geo, HyperLogLog and scripting; see the command reference pages.
  • Pub/Sub. Subscriptions are exposed as ZIO streams; see Pub/Sub.
  • Pipelining. AsyncRedis sends commands without waiting for replies; see AsyncRedis.
  • Cluster support. Redis.cluster follows slot redirections; see Cluster.
  • Embedded server for tests. See Testing.

Quick Exampleโ€‹

To run an effect that uses Redis, provide the Redis layer. It needs a CodecSupplier and, for a local server, nothing else. See Getting Started for the details:

import zio._
import zio.redis._

object QuickExample extends ZIOAppDefault {
val myApp: ZIO[Redis, RedisError, Unit] =
for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minute))
v <- redis.get("myKey").returning[Long]
_ <- ZIO.debug(s"Value of myKey: $v")
_ <- redis.hSet("myHash", ("k1", 6), ("k2", 2))
_ <- redis.rPush("myList", 1, 2, 3, 4)
_ <- redis.sAdd("mySet", "a", "b", "a", "c")
} yield ()

def run =
myApp.provide(Redis.local, ZLayer.succeed[CodecSupplier](CodecSupplier.utf8))
}

Resourcesโ€‹

  • ZIO Redis by Dejan Mijic โ€” Redis is one of the most commonly used in-memory data structure stores. In this talk, Dejan will introduce ZIO Redis, a purely functional, strongly typed client library backed by ZIO, with excellent performance and extensive support for nearly all of Redis' features. He will explain the library design using the bottom-up approach - from communication protocol to public APIs. Finally, he will wrap the talk by demonstrating the client's usage and discussing its performance characteristics.

ZIO Chat

Hi, fellow coder! ๐ŸŒŸ Welcome to your ZIO adventure with the ZIO Chat Bot. ๐Ÿš€ Let's master functional Scala together. From referential transparency to concurrent prowess, I've got your back. Ready to dive in? Your questions, my insights โ€“ let's conquer ZIO! ๐Ÿ’ก๐Ÿค–