README.md 4.0 KB
Newer Older
G
github-actions[bot] 已提交
1 2 3
[//]: # (This file was autogenerated using `zio-sbt-website` plugin via `sbt generateReadme` command.)
[//]: # (So please do not edit it manually. Instead, change "docs/index.md" file or sbt setting keys)
[//]: # (e.g. "readmeDocumentation" and "readmeSupport".)
D
Dejan Mijić 已提交
4

G
github-actions[bot] 已提交
5
# ZIO Redis
D
Dejan Mijić 已提交
6

G
github-actions[bot] 已提交
7
[ZIO Redis](https://github.com/zio/zio-redis) is a ZIO native Redis client.
D
Dejan Mijić 已提交
8 9 10

> The client is still a work-in-progress. Watch this space!

G
github-actions[bot] 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|Project Stage | CI | Release | Snapshot | Discord | Github |
|--------------|----|---------|----------|---------|--------|
|[![Experimental](https://img.shields.io/badge/Project%20Stage-Experimental-yellowgreen.svg)](https://github.com/zio/zio/wiki/Project-Stages)        |![CI Badge](https://github.com/zio/zio-redis/workflows/CI/badge.svg) |[![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-redis_2.12.svg)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-redis_2.12/) |[![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-redis_2.12.svg)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-redis_2.12/) |[![Chat on Discord!](https://img.shields.io/discord/629491597070827530?logo=discord)](https://discord.gg/2ccFBr4) |[![ZIO Redis](https://img.shields.io/github/stars/zio/zio-redis?style=social)](https://github.com/zio/zio-redis) |

## Introduction

ZIO Redis is in the experimental phase of development, but its goals are:

- **Type Safety**
- **Performance**
- **Minimum Dependency**
- **ZIO Native**

## Installation

Since the ZIO Redis is in the experimental phase, it is not released yet, but we can use snapshots:

```scala
G
github-actions[bot] 已提交
29
libraryDependencies += "dev.zio" %% "zio-redis" % "<version>"
G
github-actions[bot] 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43
```

## Example

To execute our ZIO Redis effect, we should provide the `RedisExecutor` layer to that effect. To create this layer we
should also provide the following layers:

- **RedisConfig** — Using default one, will connect to the `localhost:6379` Redis instance.
- **BinaryCodec** — In this example, we are going to use the built-in `ProtobufCodec` codec from zio-schema project.

To run this example we should put following dependencies in our `build.sbt` file:

```scala
libraryDependencies ++= Seq(
G
github-actions[bot] 已提交
44
  "dev.zio" %% "zio-redis" % "<version>",
G
github-actions[bot] 已提交
45 46 47
  "dev.zio" %% "zio-schema-protobuf" % "0.3.0"
)
```
48

G
github-actions[bot] 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
```scala
import zio._
import zio.redis._
import zio.schema.codec._

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

  override def run = myApp.provide(
    RedisLive.layer,
    RedisExecutor.layer,
    ZLayer.succeed(RedisConfig.Default),
    ZLayer.succeed[BinaryCodec](ProtobufCodec)
  )
}
```

## Resources

- [ZIO Redis](https://www.youtube.com/watch?v=yqFt3b3RBkI) 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.

## Documentation

Learn more on the [ZIO Redis homepage](https://zio.dev/zio-redis/)!

## Contributing

For the general guidelines, see ZIO [contributor's guide](https://zio.dev/about/contributing).

## Code of Conduct

See the [Code of Conduct](https://zio.dev/about/code-of-conduct)
92 93 94 95 96

## Support

Come chat with us on [![Badge-Discord]][Link-Discord].

G
github-actions[bot] 已提交
97 98
[Badge-Discord]: https://img.shields.io/discord/629491597070827530?logo=discord "chat on discord"
[Link-Discord]: https://discord.gg/2ccFBr4 "Discord"
99

G
github-actions[bot] 已提交
100
## License
101

G
github-actions[bot] 已提交
102
[License](LICENSE)