Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Zio Redis
提交
1a89cdbb
Z
Zio Redis
项目概览
梦境迷离
/
Zio Redis
9 个月 前同步成功
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
Zio Redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
1a89cdbb
编写于
3月 28, 2023
作者:
M
Marcel Kalai
提交者:
GitHub
3月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[755] zio-schema breaking update (#785)
上级
ce5fb37b
变更
33
展开全部
隐藏空白更改
内联
并排
Showing
33 changed file
with
441 addition
and
597 deletion
+441
-597
README.md
README.md
+20
-7
benchmarks/src/main/scala/zio/redis/benchmarks/BenchmarkRuntime.scala
...rc/main/scala/zio/redis/benchmarks/BenchmarkRuntime.scala
+4
-1
build.sbt
build.sbt
+18
-15
docs/index.md
docs/index.md
+17
-4
embedded/src/test/scala/zio/redis/embedded/EmbeddedRedisSpec.scala
...src/test/scala/zio/redis/embedded/EmbeddedRedisSpec.scala
+3
-1
example/src/main/scala/example/Main.scala
example/src/main/scala/example/Main.scala
+5
-2
project/BuildHelper.scala
project/BuildHelper.scala
+3
-0
redis/src/main/scala/zio/redis/ClusterExecutor.scala
redis/src/main/scala/zio/redis/ClusterExecutor.scala
+2
-4
redis/src/main/scala/zio/redis/CodecSupplier.scala
redis/src/main/scala/zio/redis/CodecSupplier.scala
+31
-0
redis/src/main/scala/zio/redis/Input.scala
redis/src/main/scala/zio/redis/Input.scala
+109
-106
redis/src/main/scala/zio/redis/Output.scala
redis/src/main/scala/zio/redis/Output.scala
+52
-51
redis/src/main/scala/zio/redis/Redis.scala
redis/src/main/scala/zio/redis/Redis.scala
+3
-4
redis/src/main/scala/zio/redis/RedisCommand.scala
redis/src/main/scala/zio/redis/RedisCommand.scala
+3
-6
redis/src/main/scala/zio/redis/RedisEnvironment.scala
redis/src/main/scala/zio/redis/RedisEnvironment.scala
+4
-1
redis/src/main/scala/zio/redis/RespArgument.scala
redis/src/main/scala/zio/redis/RespArgument.scala
+4
-5
redis/src/main/scala/zio/redis/api/Cluster.scala
redis/src/main/scala/zio/redis/api/Cluster.scala
+5
-9
redis/src/main/scala/zio/redis/api/Connection.scala
redis/src/main/scala/zio/redis/api/Connection.scala
+19
-20
redis/src/main/scala/zio/redis/api/Geo.scala
redis/src/main/scala/zio/redis/api/Geo.scala
+1
-14
redis/src/main/scala/zio/redis/api/Hashes.scala
redis/src/main/scala/zio/redis/api/Hashes.scala
+8
-29
redis/src/main/scala/zio/redis/api/HyperLogLog.scala
redis/src/main/scala/zio/redis/api/HyperLogLog.scala
+3
-15
redis/src/main/scala/zio/redis/api/Keys.scala
redis/src/main/scala/zio/redis/api/Keys.scala
+19
-24
redis/src/main/scala/zio/redis/api/Lists.scala
redis/src/main/scala/zio/redis/api/Lists.scala
+12
-63
redis/src/main/scala/zio/redis/api/Scripting.scala
redis/src/main/scala/zio/redis/api/Scripting.scala
+7
-7
redis/src/main/scala/zio/redis/api/Sets.scala
redis/src/main/scala/zio/redis/api/Sets.scala
+8
-27
redis/src/main/scala/zio/redis/api/SortedSets.scala
redis/src/main/scala/zio/redis/api/SortedSets.scala
+10
-65
redis/src/main/scala/zio/redis/api/Streams.scala
redis/src/main/scala/zio/redis/api/Streams.scala
+10
-32
redis/src/main/scala/zio/redis/api/Strings.scala
redis/src/main/scala/zio/redis/api/Strings.scala
+20
-47
redis/src/main/scala/zio/redis/codecs/StringUtf8Codec.scala
redis/src/main/scala/zio/redis/codecs/StringUtf8Codec.scala
+22
-30
redis/src/test/scala/zio/redis/ApiSpec.scala
redis/src/test/scala/zio/redis/ApiSpec.scala
+3
-2
redis/src/test/scala/zio/redis/BaseSpec.scala
redis/src/test/scala/zio/redis/BaseSpec.scala
+2
-1
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala
+3
-3
redis/src/test/scala/zio/redis/KeysSpec.scala
redis/src/test/scala/zio/redis/KeysSpec.scala
+2
-2
redis/src/test/scala/zio/redis/codecs/ProtobufCodecSupplier.scala
...c/test/scala/zio/redis/codecs/ProtobufCodecSupplier.scala
+9
-0
未找到文件。
README.md
浏览文件 @
1a89cdbb
...
...
@@ -4,7 +4,7 @@
# ZIO Redis
[
![Development
](
https://img.shields.io/badge/Project%20Stage-Development-green.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.13.svg?label=Sonatype%20Release)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-redis_2.13/)
[
![Sonatype Snapshots
](
https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-redis_2.13.svg?label=Sonatype%20Snapshot
)
](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-redis_2.13/)
[
![javadoc
](
https://javadoc.io/badge2/dev.zio/zio-redis-docs_2.13/javadoc.svg
)
](https://javadoc.io/doc/dev.zio/zio-redis-docs_2.13
)
[
![ZIO Redis
](
https://img.shields.io/github/stars/zio/zio-redis?style=social
)
](https://github.com/zio/zio-redis)
[
![Development
](
https://img.shields.io/badge/Project%20Stage-Development-green.svg
)
](https://github.com/zio/zio/wiki/Project-Stages) !
[
CI Badge
](
https://github.com/zio/zio-redis/workflows/CI/badge.svg
)
[
![Sonatype
Snapshots
]
(https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-redis_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-redis_2.13/
)
[
![ZIO Redis
](
https://img.shields.io/github/stars/zio/zio-redis?style=social
)
](https://github.com/zio/zio-redis)
## Introduction
...
...
@@ -17,7 +17,7 @@ instances.
To use ZIO Redis, add the following line to your
`build.sbt`
:
```
scala
libraryDependencies
+=
"dev.zio"
%%
"zio-redis"
%
"
0.1.0
"
libraryDependencies
+=
"dev.zio"
%%
"zio-redis"
%
"
<version>
"
```
## Example
...
...
@@ -32,17 +32,23 @@ To run this example we should put following dependencies in our `build.sbt` file
```
scala
libraryDependencies
++=
Seq
(
"dev.zio"
%%
"zio-redis"
%
"
0.1.0
"
,
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.
3.0
"
"dev.zio"
%%
"zio-redis"
%
"
<version>
"
,
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.
4.9
"
)
```
```
scala
import
zio._
import
zio.redis._
import
zio.schema._
import
zio.schema.codec._
object
ZIORedisExample
extends
ZIOAppDefault
{
object
ProtobufCodecSupplier
extends
CodecSupplier
{
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
ProtobufCodec
.
protobufCodec
}
val
myApp
:
ZIO
[
Redis
,
RedisError
,
Unit
]
=
for
{
redis
<-
ZIO
.
service
[
Redis
]
_
<-
redis
.
set
(
"myKey"
,
8L
,
Some
(
1.
minutes
))
...
...
@@ -57,7 +63,7 @@ object ZIORedisExample extends ZIOAppDefault {
Redis
.
layer
,
RedisExecutor
.
layer
,
ZLayer
.
succeed
(
RedisConfig
.
Default
),
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
)
ZLayer
.
succeed
[
CodecSupplier
](
ProtobufCodecSupplier
)
)
}
```
...
...
@@ -67,7 +73,7 @@ object ZIORedisExample extends ZIOAppDefault {
To test you can use the embedded redis instance by adding to your build:
```
scala
libraryDependencies
:=
"dev.zio"
%%
"zio-redis-embedded"
%
"
0.1.0
"
libraryDependencies
:=
"dev.zio"
%%
"zio-redis-embedded"
%
"
<version>
"
```
Then you can supply
`EmbeddedRedis.layer.orDie`
as your
`RedisConfig`
and you're good to go!
...
...
@@ -75,16 +81,23 @@ Then you can supply `EmbeddedRedis.layer.orDie` as your `RedisConfig` and you're
```
scala
import
zio._
import
zio.redis._
import
zio.redis.embedded.EmbeddedRedis
import
zio.schema.
{
DeriveSchema
,
Schema
}
import
zio.schema.codec.
{
BinaryCodec
,
ProtobufCodec
}
import
zio.test._
import
zio.test.Assertion._
import
java.util.UUID
object
EmbeddedRedisSpec
extends
ZIOSpecDefault
{
object
ProtobufCodecSupplier
extends
CodecSupplier
{
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
ProtobufCodec
.
protobufCodec
}
final
case
class
Item
private
(
id
:
UUID
,
name
:
String
,
quantity
:
Int
)
object
Item
{
implicit
val
itemSchema
:
Schema
[
Item
]
=
DeriveSchema
.
gen
[
Item
]
}
def
spec
=
suite
(
"EmbeddedRedis should"
)(
test
(
"set and get values"
)
{
for
{
...
...
@@ -97,7 +110,7 @@ object EmbeddedRedisSpec extends ZIOSpecDefault {
).
provideShared
(
EmbeddedRedis
.
layer
.
orDie
,
RedisExecutor
.
layer
.
orDie
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
),
ZLayer
.
succeed
[
CodecSupplier
](
ProtobufCodecSupplier
),
Redis
.
layer
)
@@
TestAspect
.
silentLogging
}
...
...
benchmarks/src/main/scala/zio/redis/benchmarks/BenchmarkRuntime.scala
浏览文件 @
1a89cdbb
...
...
@@ -19,6 +19,7 @@ package zio.redis.benchmarks
import
cats.effect.
{
IO
=>
CIO
}
import
zio._
import
zio.redis._
import
zio.schema.Schema
import
zio.schema.codec.
{
BinaryCodec
,
ProtobufCodec
}
trait
BenchmarkRuntime
{
...
...
@@ -35,7 +36,9 @@ object BenchmarkRuntime {
private
final
val
Layer
=
ZLayer
.
make
[
Redis
](
RedisExecutor
.
local
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
),
ZLayer
.
succeed
[
CodecSupplier
](
new
CodecSupplier
{
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
ProtobufCodec
.
protobufCodec
}),
Redis
.
layer
)
}
build.sbt
浏览文件 @
1a89cdbb
...
...
@@ -44,12 +44,12 @@ lazy val redis =
.
settings
(
stdSettings
(
"zio-redis"
))
.
settings
(
libraryDependencies
++=
List
(
"dev.zio"
%%
"zio-streams"
%
"2.0.10"
,
"dev.zio"
%%
"zio-streams"
%
zioVersion
,
"dev.zio"
%%
"zio-logging"
%
"2.1.11"
,
"dev.zio"
%%
"zio-schema"
%
"0.3.1"
,
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.3.1"
%
Test
,
"dev.zio"
%%
"zio-test"
%
"2.0.10"
%
Test
,
"dev.zio"
%%
"zio-test-sbt"
%
"2.0.10"
%
Test
,
"dev.zio"
%%
"zio-schema"
%
zioSchemaVersion
,
"dev.zio"
%%
"zio-schema-protobuf"
%
zioSchemaVersion
%
Test
,
"dev.zio"
%%
"zio-test"
%
zioVersion
%
Test
,
"dev.zio"
%%
"zio-test-sbt"
%
zioVersion
%
Test
,
"org.scala-lang.modules"
%%
"scala-collection-compat"
%
"2.9.0"
),
testFrameworks
:=
List
(
new
TestFramework
(
"zio.test.sbt.ZTestFramework"
))
...
...
@@ -64,12 +64,12 @@ lazy val embedded =
.
settings
(
stdSettings
(
"zio-redis-embedded"
))
.
settings
(
libraryDependencies
++=
List
(
"dev.zio"
%%
"zio"
%
"2.0.10"
,
"dev.zio"
%%
"zio"
%
zioVersion
,
"com.github.kstyrc"
%
"embedded-redis"
%
"0.6"
,
"dev.zio"
%%
"zio-schema"
%
"0.3.1"
%
Test
,
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.3.1"
%
Test
,
"dev.zio"
%%
"zio-test"
%
"2.0.8"
%
Test
,
"dev.zio"
%%
"zio-test-sbt"
%
"2.0.8"
%
Test
"dev.zio"
%%
"zio-schema"
%
zioSchemaVersion
%
Test
,
"dev.zio"
%%
"zio-schema-protobuf"
%
zioSchemaVersion
%
Test
,
"dev.zio"
%%
"zio-test"
%
zioVersion
%
Test
,
"dev.zio"
%%
"zio-test-sbt"
%
zioVersion
%
Test
),
testFrameworks
:=
List
(
new
TestFramework
(
"zio.test.sbt.ZTestFramework"
))
)
...
...
@@ -88,7 +88,7 @@ lazy val benchmarks =
"dev.profunktor"
%%
"redis4cats-effects"
%
"1.4.0"
,
"io.chrisdavenport"
%%
"rediculous"
%
"0.4.0"
,
"io.laserdisc"
%%
"laserdisc-fs2"
%
"0.6.0"
,
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.3.1"
"dev.zio"
%%
"zio-schema-protobuf"
%
zioSchemaVersion
)
)
...
...
@@ -102,10 +102,10 @@ lazy val example =
libraryDependencies
++=
List
(
"com.softwaremill.sttp.client3"
%%
"zio"
%
"3.8.13"
,
"com.softwaremill.sttp.client3"
%%
"zio-json"
%
"3.8.13"
,
"dev.zio"
%%
"zio-streams"
%
"2.0.10"
,
"dev.zio"
%%
"zio-streams"
%
zioVersion
,
"dev.zio"
%%
"zio-config-magnolia"
%
"3.0.7"
,
"dev.zio"
%%
"zio-config-typesafe"
%
"3.0.7"
,
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.3.1"
,
"dev.zio"
%%
"zio-schema-protobuf"
%
zioSchemaVersion
,
"dev.zio"
%%
"zio-json"
%
"0.5.0"
,
"io.d11"
%%
"zhttp"
%
"2.0.0-RC11"
)
...
...
@@ -123,7 +123,10 @@ lazy val docs = project
projectStage
:=
ProjectStage
.
Development
,
ScalaUnidoc
/
unidoc
/
unidocProjectFilter
:=
inProjects
(
redis
),
docsPublishBranch
:=
"master"
,
libraryDependencies
+=
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.3.1"
libraryDependencies
++=
List
(
"dev.zio"
%%
"zio-schema-protobuf"
%
zioSchemaVersion
,
"dev.zio"
%%
"zio-test"
%
zioVersion
)
)
.
dependsOn
(
redis
)
.
dependsOn
(
redis
,
embedded
)
.
enablePlugins
(
WebsitePlugin
)
docs/index.md
浏览文件 @
1a89cdbb
...
...
@@ -33,16 +33,22 @@ To run this example we should put following dependencies in our `build.sbt` file
```
scala
libraryDependencies
++=
Seq
(
"dev.zio"
%%
"zio-redis"
%
"@VERSION@"
,
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.
3.0
"
"dev.zio"
%%
"zio-schema-protobuf"
%
"0.
4.9
"
)
```
```
scala mdoc:compile-only
import zio._
import zio.redis._
import zio.schema._
import zio.schema.codec._
object ZIORedisExample extends ZIOAppDefault {
object ProtobufCodecSupplier extends CodecSupplier {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}
val myApp: ZIO[Redis, RedisError, Unit] = for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minutes))
...
...
@@ -57,7 +63,7 @@ object ZIORedisExample extends ZIOAppDefault {
Redis.layer,
RedisExecutor.layer,
ZLayer.succeed(RedisConfig.Default),
ZLayer.succeed[
BinaryCodec](ProtobufCodec
)
ZLayer.succeed[
CodecSupplier](ProtobufCodecSupplier
)
)
}
```
...
...
@@ -72,19 +78,26 @@ libraryDependencies := "dev.zio" %% "zio-redis-embedded" % "@VERSION@"
Then you can supply
`EmbeddedRedis.layer.orDie`
as your
`RedisConfig`
and you're good to go!
```
scala
```
scala
mdoc:compile-only
import zio._
import zio.redis._
import zio.redis.embedded.EmbeddedRedis
import zio.schema.{DeriveSchema, Schema}
import zio.schema.codec.{BinaryCodec, ProtobufCodec}
import zio.test._
import zio.test.Assertion._
import java.util.UUID
object EmbeddedRedisSpec extends ZIOSpecDefault {
object ProtobufCodecSupplier extends CodecSupplier {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}
final case class Item private (id: UUID, name: String, quantity: Int)
object Item {
implicit val itemSchema: Schema[Item] = DeriveSchema.gen[Item]
}
def spec = suite("EmbeddedRedis should")(
test("set and get values") {
for {
...
...
@@ -97,7 +110,7 @@ object EmbeddedRedisSpec extends ZIOSpecDefault {
).provideShared(
EmbeddedRedis.layer.orDie,
RedisExecutor.layer.orDie,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
),
ZLayer.succeed[
CodecSupplier](ProtobufCodecSupplier
),
Redis.layer
) @@ TestAspect.silentLogging
}
...
...
embedded/src/test/scala/zio/redis/embedded/EmbeddedRedisSpec.scala
浏览文件 @
1a89cdbb
...
...
@@ -44,7 +44,9 @@ object EmbeddedRedisSpec extends ZIOSpecDefault {
).
provideShared
(
EmbeddedRedis
.
layer
.
orDie
,
RedisExecutor
.
layer
.
orDie
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
),
ZLayer
.
succeed
[
CodecSupplier
](
new
CodecSupplier
{
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
ProtobufCodec
.
protobufCodec
}),
Redis
.
layer
)
@@
TestAspect
.
silentLogging
...
...
example/src/main/scala/example/Main.scala
浏览文件 @
1a89cdbb
...
...
@@ -21,7 +21,8 @@ import example.config.AppConfig
import
sttp.client3.httpclient.zio.HttpClientZioBackend
import
zhttp.service.Server
import
zio._
import
zio.redis.
{
Redis
,
RedisExecutor
}
import
zio.redis.
{
CodecSupplier
,
Redis
,
RedisExecutor
}
import
zio.schema.Schema
import
zio.schema.codec.
{
BinaryCodec
,
ProtobufCodec
}
object
Main
extends
ZIOAppDefault
{
...
...
@@ -34,7 +35,9 @@ object Main extends ZIOAppDefault {
HttpClientZioBackend
.
layer
(),
RedisExecutor
.
layer
,
Redis
.
layer
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
)
ZLayer
.
succeed
[
CodecSupplier
](
new
CodecSupplier
{
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
ProtobufCodec
.
protobufCodec
})
)
.
exitCode
}
project/BuildHelper.scala
浏览文件 @
1a89cdbb
...
...
@@ -30,6 +30,9 @@ object BuildHelper {
val
Scala213
=
versions
(
"2.13"
)
val
Scala3
=
versions
(
"3"
)
val
zioVersion
=
"2.0.10"
val
zioSchemaVersion
=
"0.4.9"
def
buildInfoSettings
(
packageName
:
String
)
=
List
(
buildInfoKeys
:=
List
[
BuildInfoKey
](
name
,
version
,
scalaVersion
,
sbtVersion
,
isSnapshot
),
...
...
redis/src/main/scala/zio/redis/ClusterExecutor.scala
浏览文件 @
1a89cdbb
...
...
@@ -19,9 +19,7 @@ package zio.redis
import
zio._
import
zio.redis.ClusterExecutor._
import
zio.redis.api.Cluster.AskingCommand
import
zio.redis.codecs.StringUtf8Codec
import
zio.redis.options.Cluster._
import
zio.schema.codec.BinaryCodec
import
java.io.IOException
...
...
@@ -42,7 +40,7 @@ final case class ClusterExecutor(
def
executeAsk
(
address
:
RedisUri
)
=
for
{
executor
<-
executor
(
address
)
_
<-
executor
.
execute
(
AskingCommand
(
StringUtf8Codec
,
this
).
resp
(()))
_
<-
executor
.
execute
(
AskingCommand
(
this
).
resp
(()))
res
<-
executor
.
execute
(
command
)
}
yield
res
...
...
@@ -151,7 +149,7 @@ object ClusterExecutor {
private
def
redis
(
address
:
RedisUri
)
=
{
val
executorLayer
=
ZLayer
.
succeed
(
RedisConfig
(
address
.
host
,
address
.
port
))
>>>
RedisExecutor
.
layer
val
codecLayer
=
ZLayer
.
succeed
[
BinaryCodec
](
StringUtf8Codec
)
val
codecLayer
=
ZLayer
.
succeed
[
CodecSupplier
](
CodecSupplier
.
utf8string
)
val
redisLayer
=
executorLayer
++
codecLayer
>>>
Redis
.
layer
for
{
closableScope
<-
Scope
.
make
...
...
redis/src/main/scala/zio/redis/CodecSupplier.scala
0 → 100644
浏览文件 @
1a89cdbb
/*
* Copyright 2021 John A. De Goes and the ZIO contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
zio.redis
import
zio.redis.codecs.StringUtf8Codec
import
zio.schema.Schema
import
zio.schema.codec.BinaryCodec
trait
CodecSupplier
{
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
}
object
CodecSupplier
{
def
utf8string
:
CodecSupplier
=
new
CodecSupplier
{
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
StringUtf8Codec
.
codec
}
}
redis/src/main/scala/zio/redis/Input.scala
浏览文件 @
1a89cdbb
此差异已折叠。
点击以展开。
redis/src/main/scala/zio/redis/Output.scala
浏览文件 @
1a89cdbb
...
...
@@ -24,17 +24,17 @@ import zio.schema.codec.BinaryCodec
sealed
trait
Output
[
+A
]
{
self
=>
private
[
redis
]
final
def
unsafeDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
A
=
private
[
redis
]
final
def
unsafeDecode
(
respValue
:
RespValue
)
:
A
=
respValue
match
{
case
error
:
RespValue.Error
=>
throw
error
.
toRedisError
case
success
=>
tryDecode
(
success
)
}
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
A
protected
def
tryDecode
(
respValue
:
RespValue
)
:
A
final
def
map
[
B
](
f
:
A
=>
B
)
:
Output
[
B
]
=
new
Output
[
B
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
B
=
f
(
self
.
tryDecode
(
respValue
))
protected
def
tryDecode
(
respValue
:
RespValue
)
:
B
=
f
(
self
.
tryDecode
(
respValue
))
}
}
...
...
@@ -46,11 +46,11 @@ object Output {
def
apply
[
A
](
implicit
output
:
Output
[
A
])
:
Output
[
A
]
=
output
case
object
RespValueOutput
extends
Output
[
RespValue
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
RespValue
=
respValue
protected
def
tryDecode
(
respValue
:
RespValue
)
:
RespValue
=
respValue
}
case
object
BoolOutput
extends
Output
[
Boolean
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Boolean
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Boolean
=
respValue
match
{
case
RespValue
.
Integer
(
0
)
=>
false
case
RespValue
.
Integer
(
1
)
=>
true
...
...
@@ -59,7 +59,7 @@ object Output {
}
final
case
class
ChunkOutput
[
+A
](
output
:
Output
[
A
])
extends
Output
[
Chunk
[
A
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
A
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
A
]
=
respValue
match
{
case
RespValue
.
NullArray
=>
Chunk
.
empty
case
RespValue
.
Array
(
values
)
=>
values
.
map
(
output
.
tryDecode
)
...
...
@@ -68,7 +68,7 @@ object Output {
}
final
case
class
ZRandMemberOutput
[
+A
](
output
:
Output
[
A
])
extends
Output
[
Chunk
[
A
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
A
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
A
]
=
respValue
match
{
case
RespValue
.
NullBulkString
=>
Chunk
.
empty
case
RespValue
.
NullArray
=>
Chunk
.
empty
...
...
@@ -78,7 +78,7 @@ object Output {
}
final
case
class
ChunkTuple2Output
[
+A
,
+B
](
_1
:
Output
[
A
],
_2
:
Output
[
B
])
extends
Output
[
Chunk
[(
A
,
B
)]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[(
A
,
B
)]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[(
A
,
B
)]
=
respValue
match
{
case
RespValue
.
NullArray
=>
Chunk
.
empty
...
...
@@ -92,7 +92,7 @@ object Output {
}
final
case
class
ZRandMemberTuple2Output
[
+A
,
+B
](
_1
:
Output
[
A
],
_2
:
Output
[
B
])
extends
Output
[
Chunk
[(
A
,
B
)]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[(
A
,
B
)]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[(
A
,
B
)]
=
respValue
match
{
case
RespValue
.
NullBulkString
=>
Chunk
.
empty
case
RespValue
.
NullArray
=>
Chunk
.
empty
...
...
@@ -106,7 +106,7 @@ object Output {
}
case
object
DoubleOutput
extends
Output
[
Double
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Double
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Double
=
respValue
match
{
case
RespValue
.
BulkString
(
bytes
)
=>
decodeDouble
(
bytes
)
case
other
=>
throw
ProtocolError
(
s
"$other isn't a double."
)
...
...
@@ -114,7 +114,7 @@ object Output {
}
private
object
DurationOutput
extends
Output
[
Long
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Long
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Long
=
respValue
match
{
case
RespValue
.
Integer
(-
2L
)
=>
throw
ProtocolError
(
"Key not found."
)
case
RespValue
.
Integer
(-
1L
)
=>
throw
ProtocolError
(
"Key has no expire."
)
...
...
@@ -128,7 +128,7 @@ object Output {
final
val
DurationSecondsOutput
:
Output
[
Duration
]
=
DurationOutput
.
map
(
_
.
seconds
)
case
object
LongOutput
extends
Output
[
Long
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Long
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Long
=
respValue
match
{
case
RespValue
.
Integer
(
v
)
=>
v
case
other
=>
throw
ProtocolError
(
s
"$other isn't an integer"
)
...
...
@@ -136,7 +136,7 @@ object Output {
}
final
case
class
OptionalOutput
[
+A
](
output
:
Output
[
A
])
extends
Output
[
Option
[
A
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Option
[
A
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Option
[
A
]
=
respValue
match
{
case
RespValue
.
NullBulkString
|
RespValue
.
NullArray
=>
None
case
RespValue
.
BulkString
(
value
)
if
value
.
isEmpty
=>
None
...
...
@@ -145,7 +145,7 @@ object Output {
}
final
case
class
ScanOutput
[
+A
](
output
:
Output
[
A
])
extends
Output
[(
Long
,
Chunk
[
A
])]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
(
Long
,
Chunk
[
A
])
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
(
Long
,
Chunk
[
A
])
=
respValue
match
{
case
RespValue
.
ArrayValues
(
cursor
@
RespValue
.
BulkString
(
_
),
RespValue
.
Array
(
items
))
=>
(
cursor
.
asLong
,
items
.
map
(
output
.
tryDecode
))
...
...
@@ -155,7 +155,7 @@ object Output {
}
case
object
KeyElemOutput
extends
Output
[
Option
[(
String
,
String
)]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Option
[(
String
,
String
)]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Option
[(
String
,
String
)]
=
respValue
match
{
case
RespValue
.
NullArray
=>
None
...
...
@@ -166,7 +166,7 @@ object Output {
}
case
object
StringOutput
extends
Output
[
String
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
String
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
String
=
respValue
match
{
case
RespValue
.
SimpleString
(
s
)
=>
s
case
other
=>
throw
ProtocolError
(
s
"$other isn't a simple string"
)
...
...
@@ -174,7 +174,7 @@ object Output {
}
case
object
MultiStringOutput
extends
Output
[
String
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
String
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
String
=
respValue
match
{
case
s
@
RespValue
.
BulkString
(
_
)
=>
s
.
asString
case
other
=>
throw
ProtocolError
(
s
"$other isn't a bulk string"
)
...
...
@@ -182,23 +182,23 @@ object Output {
}
case
object
BulkStringOutput
extends
Output
[
Chunk
[
Byte
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
Byte
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
Byte
]
=
respValue
match
{
case
RespValue
.
BulkString
(
value
)
=>
value
case
other
=>
throw
ProtocolError
(
s
"$other isn't a bulk string"
)
}
}
final
case
class
ArbitraryOutput
[
A
]()(
implicit
schema
:
Schema
[
A
])
extends
Output
[
A
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
A
=
final
case
class
ArbitraryOutput
[
A
]()(
implicit
codec
:
BinaryCodec
[
A
])
extends
Output
[
A
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
:
A
=
respValue
match
{
case
RespValue
.
BulkString
(
s
)
=>
codec
.
decode
(
s
chema
)(
s
).
fold
(
e
=>
throw
CodecError
(
e
.
message
),
identity
)
case
RespValue
.
BulkString
(
s
)
=>
codec
.
decode
(
s
).
fold
(
e
=>
throw
CodecError
(
e
.
message
),
identity
)
case
other
=>
throw
ProtocolError
(
s
"$other isn't a bulk string"
)
}
}
final
case
class
Tuple2Output
[
+A
,
+B
](
_1
:
Output
[
A
],
_2
:
Output
[
B
])
extends
Output
[(
A
,
B
)]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
(
A
,
B
)
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
(
A
,
B
)
=
respValue
match
{
case
RespValue
.
ArrayValues
(
a
:
RespValue
,
b
:
RespValue
)
=>
(
_1
.
tryDecode
(
a
),
_2
.
tryDecode
(
b
))
case
other
=>
throw
ProtocolError
(
s
"$other isn't a tuple2"
)
...
...
@@ -206,7 +206,7 @@ object Output {
}
final
case
class
Tuple3Output
[
+A
,
+B
,
+C
](
_1
:
Output
[
A
],
_2
:
Output
[
B
],
_3
:
Output
[
C
])
extends
Output
[(
A
,
B
,
C
)]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
(
A
,
B
,
C
)
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
(
A
,
B
,
C
)
=
respValue
match
{
case
RespValue
.
ArrayValues
(
a
:
RespValue
,
b
:
RespValue
,
c
:
RespValue
)
=>
(
_1
.
tryDecode
(
a
),
_2
.
tryDecode
(
b
),
_3
.
tryDecode
(
c
))
...
...
@@ -215,7 +215,7 @@ object Output {
}
case
object
SingleOrMultiStringOutput
extends
Output
[
String
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
String
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
String
=
respValue
match
{
case
RespValue
.
SimpleString
(
s
)
=>
s
case
s
@
RespValue
.
BulkString
(
_
)
=>
s
.
asString
...
...
@@ -224,7 +224,7 @@ object Output {
}
final
case
class
MultiStringChunkOutput
[
+A
](
output
:
Output
[
A
])
extends
Output
[
Chunk
[
A
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
A
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
A
]
=
respValue
match
{
case
RespValue
.
NullBulkString
=>
Chunk
.
empty
case
s
@
RespValue
.
BulkString
(
_
)
=>
Chunk
.
single
(
output
.
tryDecode
(
s
))
...
...
@@ -234,7 +234,7 @@ object Output {
}
case
object
TypeOutput
extends
Output
[
RedisType
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
RedisType
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
RedisType
=
respValue
match
{
case
RespValue
.
SimpleString
(
"string"
)
=>
RedisType
.
String
case
RespValue
.
SimpleString
(
"list"
)
=>
RedisType
.
List
...
...
@@ -247,7 +247,7 @@ object Output {
}
case
object
UnitOutput
extends
Output
[
Unit
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Unit
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Unit
=
respValue
match
{
case
RespValue
.
SimpleString
(
"OK"
)
=>
()
case
other
=>
throw
ProtocolError
(
s
"$other isn't unit."
)
...
...
@@ -255,7 +255,7 @@ object Output {
}
case
object
ResetOutput
extends
Output
[
Unit
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Unit
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Unit
=
respValue
match
{
case
RespValue
.
SimpleString
(
"RESET"
)
=>
()
case
other
=>
throw
ProtocolError
(
s
"$other isn't unit."
)
...
...
@@ -263,7 +263,7 @@ object Output {
}
case
object
GeoOutput
extends
Output
[
Chunk
[
Option
[
LongLat
]]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
Option
[
LongLat
]]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
Option
[
LongLat
]]
=
respValue
match
{
case
RespValue
.
NullArray
=>
Chunk
.
empty
...
...
@@ -281,7 +281,7 @@ object Output {
}
case
object
GeoRadiusOutput
extends
Output
[
Chunk
[
GeoView
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
GeoView
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
GeoView
]
=
respValue
match
{
case
RespValue
.
Array
(
elements
)
=>
elements
.
map
{
...
...
@@ -307,7 +307,7 @@ object Output {
}
final
case
class
KeyValueOutput
[
K
,
V
](
outK
:
Output
[
K
],
outV
:
Output
[
V
])
extends
Output
[
Map
[
K
,
V
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Map
[
K
,
V
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Map
[
K
,
V
]
=
respValue
match
{
case
RespValue
.
NullArray
=>
Map
.
empty
[
K
,
V
]
...
...
@@ -331,12 +331,12 @@ object Output {
}
}
final
case
class
StreamEntryOutput
[
I
,
K
,
V
]()(
implicit
final
case
class
StreamEntryOutput
[
I
:
BinaryCodec
,
K:
BinaryCodec
,
V:
BinaryCodec
]()(
implicit
idSchema
:
Schema
[
I
],
keySchema
:
Schema
[
K
],
valueSchema
:
Schema
[
V
]
)
extends
Output
[
StreamEntry
[
I
,
K
,
V
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
StreamEntry
[
I
,
K
,
V
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
StreamEntry
[
I
,
K
,
V
]
=
respValue
match
{
case
RespValue
.
Array
(
Seq
(
id
@
RespValue
.
BulkString
(
_
),
value
))
=>
val
entryId
=
ArbitraryOutput
[
I
]().
unsafeDecode
(
id
)
...
...
@@ -347,29 +347,29 @@ object Output {
}
}
final
case
class
StreamEntriesOutput
[
I
,
K
,
V
]()(
implicit
final
case
class
StreamEntriesOutput
[
I
:
BinaryCodec
,
K:
BinaryCodec
,
V:
BinaryCodec
]()(
implicit
idSchema
:
Schema
[
I
],
keySchema
:
Schema
[
K
],
valueSchema
:
Schema
[
V
]
)
extends
Output
[
Chunk
[
StreamEntry
[
I
,
K
,
V
]]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
StreamEntry
[
I
,
K
,
V
]]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
StreamEntry
[
I
,
K
,
V
]]
=
ChunkOutput
(
StreamEntryOutput
[
I
,
K
,
V
]()).
unsafeDecode
(
respValue
)
}
final
case
class
StreamOutput
[
N
,
I
,
K
,
V
]()(
implicit
final
case
class
StreamOutput
[
N
:
BinaryCodec
,
I:
BinaryCodec
,
K:
BinaryCodec
,
V:
BinaryCodec
]()(
implicit
nameSchema
:
Schema
[
N
],
idSchema
:
Schema
[
I
],
keySchema
:
Schema
[
K
],
valueSchema
:
Schema
[
V
]
)
extends
Output
[
StreamChunk
[
N
,
I
,
K
,
V
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
StreamChunk
[
N
,
I
,
K
,
V
]
=
{
protected
def
tryDecode
(
respValue
:
RespValue
)
:
StreamChunk
[
N
,
I
,
K
,
V
]
=
{
val
(
name
,
entries
)
=
Tuple2Output
(
ArbitraryOutput
[
N
](),
StreamEntriesOutput
[
I
,
K
,
V
]()).
unsafeDecode
(
respValue
)
StreamChunk
(
name
,
entries
)
}
}
case
object
StreamGroupsInfoOutput
extends
Output
[
Chunk
[
StreamGroupsInfo
]]
{
override
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
StreamGroupsInfo
]
=
override
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
StreamGroupsInfo
]
=
respValue
match
{
case
RespValue
.
NullArray
=>
Chunk
.
empty
case
RespValue
.
Array
(
messages
)
=>
...
...
@@ -408,7 +408,7 @@ object Output {
}
case
object
StreamConsumersInfoOutput
extends
Output
[
Chunk
[
StreamConsumersInfo
]]
{
override
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
StreamConsumersInfo
]
=
override
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
StreamConsumersInfo
]
=
respValue
match
{
case
RespValue
.
NullArray
=>
Chunk
.
empty
case
RespValue
.
Array
(
messages
)
=>
...
...
@@ -444,11 +444,11 @@ object Output {
}
}
final
case
class
StreamInfoFullOutput
[
I:
Schema
,
K:
Schema
,
V:
Schema
]()
final
case
class
StreamInfoFullOutput
[
I:
Schema
:
BinaryCodec
,
K:
Schema:
BinaryCodec
,
V:
Schema:
BinaryCodec
]()
extends
Output
[
StreamInfoWithFull.FullStreamInfo
[
I
,
K
,
V
]]
{
override
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
StreamInfoWithFull.FullStreamInfo
[
I
,
K
,
V
]
=
{
)
:
StreamInfoWithFull.FullStreamInfo
[
I
,
K
,
V
]
=
{
var
streamInfoFull
:
StreamInfoWithFull.FullStreamInfo
[
I
,
K
,
V
]
=
StreamInfoWithFull
.
FullStreamInfo
.
empty
respValue
match
{
// Note that you should not rely on the fields exact position. see https://redis.io/commands/xinfo
...
...
@@ -583,8 +583,9 @@ object Output {
}
}
final
case
class
StreamInfoOutput
[
I:
Schema
,
K:
Schema
,
V:
Schema
]()
extends
Output
[
StreamInfo
[
I
,
K
,
V
]]
{
override
protected
def
tryDecode
(
respValue
:
RespValue
)(
implicit
codec
:
BinaryCodec
)
:
StreamInfo
[
I
,
K
,
V
]
=
{
final
case
class
StreamInfoOutput
[
I:
Schema:
BinaryCodec
,
K:
Schema:
BinaryCodec
,
V:
Schema:
BinaryCodec
]()
extends
Output
[
StreamInfo
[
I
,
K
,
V
]]
{
override
protected
def
tryDecode
(
respValue
:
RespValue
)
:
StreamInfo
[
I
,
K
,
V
]
=
{
var
streamInfo
:
StreamInfo
[
I
,
K
,
V
]
=
StreamInfo
.
empty
respValue
match
{
// Note that you should not rely on the fields exact position. see https://redis.io/commands/xinfo
...
...
@@ -625,7 +626,7 @@ object Output {
}
case
object
XPendingOutput
extends
Output
[
PendingInfo
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
PendingInfo
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
PendingInfo
=
respValue
match
{
case
RespValue
.
Array
(
Seq
(
RespValue
.
Integer
(
total
),
f
,
l
,
ps
))
=>
val
first
=
OptionalOutput
(
MultiStringOutput
).
unsafeDecode
(
f
)
...
...
@@ -657,7 +658,7 @@ object Output {
}
case
object
PendingMessagesOutput
extends
Output
[
Chunk
[
PendingMessage
]]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
PendingMessage
]
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Chunk
[
PendingMessage
]
=
respValue
match
{
case
RespValue
.
Array
(
messages
)
=>
messages
.
collect
{
...
...
@@ -680,7 +681,7 @@ object Output {
}
case
object
SetOutput
extends
Output
[
Boolean
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Boolean
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Boolean
=
respValue
match
{
case
RespValue
.
NullBulkString
=>
false
case
RespValue
.
SimpleString
(
_
)
=>
true
...
...
@@ -689,7 +690,7 @@ object Output {
}
case
object
StrAlgoLcsOutput
extends
Output
[
LcsOutput
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
LcsOutput
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
LcsOutput
=
respValue
match
{
case
result
@
RespValue
.
BulkString
(
_
)
=>
LcsOutput
.
Lcs
(
result
.
asString
)
case
RespValue
.
Integer
(
length
)
=>
LcsOutput
.
Length
(
length
)
...
...
@@ -728,7 +729,7 @@ object Output {
}
case
object
ClientTrackingInfoOutput
extends
Output
[
ClientTrackingInfo
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
ClientTrackingInfo
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
ClientTrackingInfo
=
respValue
match
{
case
RespValue
.
NullArray
=>
throw
ProtocolError
(
s
"Array must not be empty"
)
case
RespValue
.
Array
(
values
)
if
values
.
length
%
2
==
0
=>
...
...
@@ -792,7 +793,7 @@ object Output {
}
case
object
ClientTrackingRedirectOutput
extends
Output
[
ClientTrackingRedirect
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
ClientTrackingRedirect
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
ClientTrackingRedirect
=
respValue
match
{
case
RespValue
.
Integer
(-
1L
)
=>
ClientTrackingRedirect
.
NotEnabled
case
RespValue
.
Integer
(
0L
)
=>
ClientTrackingRedirect
.
NotRedirected
...
...
@@ -802,7 +803,7 @@ object Output {
}
case
object
ClusterPartitionOutput
extends
Output
[
Partition
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Partition
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Partition
=
respValue
match
{
case
RespValue
.
NullArray
=>
throw
ProtocolError
(
s
"Array must not be empty"
)
case
RespValue
.
Array
(
values
)
=>
...
...
@@ -816,7 +817,7 @@ object Output {
}
case
object
ClusterPartitionNodeOutput
extends
Output
[
Node
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
(
implicit
codec
:
BinaryCodec
)
:
Node
=
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Node
=
respValue
match
{
case
RespValue
.
NullArray
=>
throw
ProtocolError
(
s
"Array must not be empty"
)
case
RespValue
.
Array
(
values
)
=>
...
...
redis/src/main/scala/zio/redis/Redis.scala
浏览文件 @
1a89cdbb
...
...
@@ -17,7 +17,6 @@
package
zio.redis
import
zio._
import
zio.schema.codec.BinaryCodec
trait
Redis
extends
api
.
Connection
...
...
@@ -34,13 +33,13 @@ trait Redis
with
api
.
Cluster
object
Redis
{
lazy
val
layer
:
URLayer
[
RedisExecutor
with
BinaryCodec
,
Redis
]
=
lazy
val
layer
:
URLayer
[
RedisExecutor
with
CodecSupplier
,
Redis
]
=
ZLayer
{
for
{
executor
<-
ZIO
.
service
[
RedisExecutor
]
codec
<-
ZIO
.
service
[
BinaryCodec
]
codec
<-
ZIO
.
service
[
CodecSupplier
]
}
yield
Live
(
codec
,
executor
)
}
private
final
case
class
Live
(
codec
:
BinaryCodec
,
executor
:
RedisExecutor
)
extends
Redis
private
final
case
class
Live
(
codec
:
CodecSupplier
,
executor
:
RedisExecutor
)
extends
Redis
}
redis/src/main/scala/zio/redis/RedisCommand.scala
浏览文件 @
1a89cdbb
...
...
@@ -18,24 +18,22 @@ package zio.redis
import
zio._
import
zio.redis.Input.
{
CommandNameInput
,
Varargs
}
import
zio.schema.codec.BinaryCodec
final
class
RedisCommand
[
-In
,
+Out
]
private
(
val
name
:
String
,
val
input
:
Input
[
In
],
val
output
:
Output
[
Out
],
val
codec
:
BinaryCodec
,
val
executor
:
RedisExecutor
)
{
private
[
redis
]
def
run
(
in
:
In
)
:
IO
[
RedisError
,
Out
]
=
executor
.
execute
(
resp
(
in
))
.
flatMap
[
Any
,
Throwable
,
Out
](
out
=>
ZIO
.
attempt
(
output
.
unsafeDecode
(
out
)
(
codec
)
))
.
flatMap
[
Any
,
Throwable
,
Out
](
out
=>
ZIO
.
attempt
(
output
.
unsafeDecode
(
out
)))
.
refineToOrDie
[
RedisError
]
private
[
redis
]
def
resp
(
in
:
In
)
:
RespCommand
=
Varargs
(
CommandNameInput
).
encode
(
name
.
split
(
" "
))
(
codec
)
++
input
.
encode
(
in
)(
codec
)
Varargs
(
CommandNameInput
).
encode
(
name
.
split
(
" "
))
++
input
.
encode
(
in
)
}
object
RedisCommand
{
...
...
@@ -43,8 +41,7 @@ object RedisCommand {
name
:
String
,
input
:
Input
[
In
],
output
:
Output
[
Out
],
codec
:
BinaryCodec
,
executor
:
RedisExecutor
)
:
RedisCommand
[
In
,
Out
]
=
new
RedisCommand
(
name
,
input
,
output
,
codec
,
executor
)
new
RedisCommand
(
name
,
input
,
output
,
executor
)
}
redis/src/main/scala/zio/redis/RedisEnvironment.scala
浏览文件 @
1a89cdbb
...
...
@@ -16,9 +16,12 @@
package
zio.redis
import
zio.schema.Schema
import
zio.schema.codec.BinaryCodec
private
[
redis
]
trait
RedisEnvironment
{
protected
def
codec
:
BinaryCodec
protected
def
codec
:
CodecSupplier
protected
def
executor
:
RedisExecutor
implicit
def
summonCodec
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
codec
.
get
}
redis/src/main/scala/zio/redis/RespArgument.scala
浏览文件 @
1a89cdbb
...
...
@@ -19,7 +19,6 @@ package zio.redis
import
zio.Chunk
import
zio.redis.RespValue.BulkString
import
zio.redis.codecs.CRC16
import
zio.schema.Schema
import
zio.schema.codec.BinaryCodec
import
java.nio.charset.StandardCharsets
...
...
@@ -35,8 +34,8 @@ object RespArgument {
}
object
Unknown
{
def
apply
(
str
:
String
)
:
Unknown
=
Unknown
(
Chunk
.
fromArray
(
str
.
getBytes
(
StandardCharsets
.
UTF_8
)))
def
apply
[
A
](
data
:
A
)(
implicit
codec
:
BinaryCodec
,
schema
:
Schema
[
A
])
:
Unknown
=
Unknown
(
codec
.
encode
(
schema
)
(
data
))
def
apply
(
str
:
String
)
:
Unknown
=
Unknown
(
Chunk
.
fromArray
(
str
.
getBytes
(
StandardCharsets
.
UTF_8
)))
def
apply
[
A
](
data
:
A
)(
implicit
codec
:
BinaryCodec
[
A
])
:
Unknown
=
Unknown
(
codec
.
encode
(
data
))
}
final
case
class
CommandName
(
str
:
String
)
extends
RespArgument
{
...
...
@@ -58,7 +57,7 @@ object RespArgument {
}
object
Key
{
def
apply
[
A
](
data
:
A
)(
implicit
codec
:
BinaryCodec
,
schema
:
Schema
[
A
])
:
Key
=
Key
(
codec
.
encode
(
schema
)
(
data
))
def
apply
[
A
](
data
:
A
)(
implicit
codec
:
BinaryCodec
[
A
])
:
Key
=
Key
(
codec
.
encode
(
data
))
}
final
case
class
Value
(
bytes
:
Chunk
[
Byte
])
extends
RespArgument
{
...
...
@@ -66,6 +65,6 @@ object RespArgument {
}
object
Value
{
def
apply
[
A
](
data
:
A
)(
implicit
codec
:
BinaryCodec
,
schema
:
Schema
[
A
])
:
Value
=
Value
(
codec
.
encode
(
schema
)
(
data
))
def
apply
[
A
](
data
:
A
)(
implicit
codec
:
BinaryCodec
[
A
])
:
Value
=
Value
(
codec
.
encode
(
data
))
}
}
redis/src/main/scala/zio/redis/api/Cluster.scala
浏览文件 @
1a89cdbb
...
...
@@ -22,7 +22,6 @@ import zio.redis._
import
zio.redis.api.Cluster.
{
AskingCommand
,
ClusterSetSlots
,
ClusterSlots
}
import
zio.redis.options.Cluster.SetSlotSubCommand._
import
zio.redis.options.Cluster.
{
Partition
,
Slot
}
import
zio.schema.codec.BinaryCodec
import
zio.
{
Chunk
,
IO
}
trait
Cluster
extends
RedisEnvironment
{
...
...
@@ -35,7 +34,7 @@ trait Cluster extends RedisEnvironment {
* the Unit value.
*/
final
def
asking
:
IO
[
RedisError
,
Unit
]
=
AskingCommand
(
codec
,
executor
).
run
(())
AskingCommand
(
executor
).
run
(())
/**
* Returns details about which cluster slots map to which Redis instances.
...
...
@@ -44,7 +43,7 @@ trait Cluster extends RedisEnvironment {
* details about which cluster
*/
final
def
slots
:
IO
[
RedisError
,
Chunk
[
Partition
]]
=
{
val
command
=
RedisCommand
(
ClusterSlots
,
NoInput
,
ChunkOutput
(
ClusterPartitionOutput
),
codec
,
executor
)
val
command
=
RedisCommand
(
ClusterSlots
,
NoInput
,
ChunkOutput
(
ClusterPartitionOutput
),
executor
)
command
.
run
(())
}
...
...
@@ -58,7 +57,7 @@ trait Cluster extends RedisEnvironment {
*/
final
def
setSlotStable
(
slot
:
Slot
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ClusterSetSlots
,
Tuple2
(
LongInput
,
ArbitraryValueInput
[
String
]()),
UnitOutput
,
codec
,
executor
)
RedisCommand
(
ClusterSetSlots
,
Tuple2
(
LongInput
,
ArbitraryValueInput
[
String
]()),
UnitOutput
,
executor
)
command
.
run
((
slot
.
number
,
Stable
.
stringify
))
}
...
...
@@ -78,7 +77,6 @@ trait Cluster extends RedisEnvironment {
ClusterSetSlots
,
Tuple3
(
LongInput
,
ArbitraryValueInput
[
String
](),
ArbitraryValueInput
[
String
]()),
UnitOutput
,
codec
,
executor
)
command
.
run
((
slot
.
number
,
Migrating
.
stringify
,
nodeId
))
...
...
@@ -100,7 +98,6 @@ trait Cluster extends RedisEnvironment {
ClusterSetSlots
,
Tuple3
(
LongInput
,
ArbitraryValueInput
[
String
](),
ArbitraryValueInput
[
String
]()),
UnitOutput
,
codec
,
executor
)
command
.
run
((
slot
.
number
,
Importing
.
stringify
,
nodeId
))
...
...
@@ -122,7 +119,6 @@ trait Cluster extends RedisEnvironment {
ClusterSetSlots
,
Tuple3
(
LongInput
,
ArbitraryValueInput
[
String
](),
ArbitraryValueInput
[
String
]()),
UnitOutput
,
codec
,
executor
)
command
.
run
((
slot
.
number
,
Node
.
stringify
,
nodeId
))
...
...
@@ -134,6 +130,6 @@ private[redis] object Cluster {
final
val
ClusterSlots
=
"CLUSTER SLOTS"
final
val
ClusterSetSlots
=
"CLUSTER SETSLOT"
final
val
AskingCommand
:
(
BinaryCodec
,
RedisExecutor
)
=>
RedisCommand
[
Unit
,
Unit
]
=
RedisCommand
(
Asking
,
NoInput
,
UnitOutput
,
_
,
_
)
final
val
AskingCommand
:
(
RedisExecutor
)
=>
RedisCommand
[
Unit
,
Unit
]
=
(
executor
:
RedisExecutor
)
=>
RedisCommand
(
Asking
,
NoInput
,
UnitOutput
,
executor
)
}
redis/src/main/scala/zio/redis/api/Connection.scala
浏览文件 @
1a89cdbb
...
...
@@ -37,7 +37,7 @@ trait Connection extends RedisEnvironment {
* the server starts accepting commands. Otherwise, an error is returned and the client needs to try a new password.
*/
final
def
auth
(
password
:
String
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
Connection
.
Auth
,
AuthInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Connection
.
Auth
,
AuthInput
,
UnitOutput
,
executor
)
command
.
run
(
Auth
(
None
,
password
))
}
...
...
@@ -54,7 +54,7 @@ trait Connection extends RedisEnvironment {
* the server starts accepting commands. Otherwise, an error is returned and the client needs to try a new password.
*/
final
def
auth
(
username
:
String
,
password
:
String
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
Connection
.
Auth
,
AuthInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Connection
.
Auth
,
AuthInput
,
UnitOutput
,
executor
)
command
.
run
(
Auth
(
Some
(
username
),
password
))
}
...
...
@@ -69,7 +69,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
clientCaching
(
track
:
Boolean
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ClientCaching
,
YesNoInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientCaching
,
YesNoInput
,
UnitOutput
,
executor
)
command
.
run
(
track
)
}
...
...
@@ -85,7 +85,7 @@ trait Connection extends RedisEnvironment {
* the ID of the current connection.
*/
final
def
clientId
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
ClientId
,
NoInput
,
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientId
,
NoInput
,
LongOutput
,
executor
)
command
.
run
(())
}
...
...
@@ -99,7 +99,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
clientKill
(
address
:
Address
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ClientKill
,
AddressInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientKill
,
AddressInput
,
UnitOutput
,
executor
)
command
.
run
(
address
)
}
...
...
@@ -125,7 +125,7 @@ trait Connection extends RedisEnvironment {
* the number of clients killed.
*/
final
def
clientKill
(
filters
:
ClientKillFilter*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
ClientKill
,
Varargs
(
ClientKillInput
),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientKill
,
Varargs
(
ClientKillInput
),
LongOutput
,
executor
)
command
.
run
(
filters
)
}
...
...
@@ -137,7 +137,7 @@ trait Connection extends RedisEnvironment {
* the connection name, or None if a name wasn't set.
*/
final
def
clientGetName
:
IO
[
RedisError
,
Option
[
String
]]
=
{
val
command
=
RedisCommand
(
ClientGetName
,
NoInput
,
OptionalOutput
(
MultiStringOutput
),
codec
,
executor
)
val
command
=
RedisCommand
(
ClientGetName
,
NoInput
,
OptionalOutput
(
MultiStringOutput
),
executor
)
command
.
run
(())
}
...
...
@@ -149,7 +149,7 @@ trait Connection extends RedisEnvironment {
* the client ID if the tracking is enabled and the notifications are being redirected
*/
final
def
clientGetRedir
:
IO
[
RedisError
,
ClientTrackingRedirect
]
=
{
val
command
=
RedisCommand
(
ClientGetRedir
,
NoInput
,
ClientTrackingRedirectOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientGetRedir
,
NoInput
,
ClientTrackingRedirectOutput
,
executor
)
command
.
run
(())
}
...
...
@@ -160,7 +160,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
clientUnpause
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ClientUnpause
,
NoInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientUnpause
,
NoInput
,
UnitOutput
,
executor
)
command
.
run
(())
}
...
...
@@ -186,7 +186,6 @@ trait Connection extends RedisEnvironment {
ClientPause
,
Tuple2
(
DurationMillisecondsInput
,
OptionalInput
(
ClientPauseModeInput
)),
UnitOutput
,
codec
,
executor
)
...
...
@@ -202,7 +201,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
clientSetName
(
name
:
String
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ClientSetName
,
StringInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientSetName
,
StringInput
,
UnitOutput
,
executor
)
command
.
run
(
name
)
}
...
...
@@ -228,7 +227,7 @@ trait Connection extends RedisEnvironment {
noLoop
:
Boolean
=
false
,
prefixes
:
Set
[
String
]
=
Set
.
empty
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ClientTracking
,
ClientTrackingInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientTracking
,
ClientTrackingInput
,
UnitOutput
,
executor
)
command
.
run
(
Some
((
redirect
,
trackingMode
,
noLoop
,
Chunk
.
fromIterable
(
prefixes
))))
}
...
...
@@ -239,7 +238,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
clientTrackingOff
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ClientTracking
,
ClientTrackingInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientTracking
,
ClientTrackingInput
,
UnitOutput
,
executor
)
command
.
run
(
None
)
}
...
...
@@ -250,7 +249,7 @@ trait Connection extends RedisEnvironment {
* tracking information.
*/
final
def
clientTrackingInfo
:
IO
[
RedisError
,
ClientTrackingInfo
]
=
{
val
command
=
RedisCommand
(
ClientTrackingInfo
,
NoInput
,
ClientTrackingInfoOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ClientTrackingInfo
,
NoInput
,
ClientTrackingInfoOutput
,
executor
)
command
.
run
(())
}
...
...
@@ -270,7 +269,7 @@ trait Connection extends RedisEnvironment {
error
:
Option
[
UnblockBehavior
]
=
None
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
ClientUnblock
,
Tuple2
(
LongInput
,
OptionalInput
(
UnblockBehaviorInput
)),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
ClientUnblock
,
Tuple2
(
LongInput
,
OptionalInput
(
UnblockBehaviorInput
)),
BoolOutput
,
executor
)
command
.
run
((
clientId
,
error
))
}
...
...
@@ -284,7 +283,7 @@ trait Connection extends RedisEnvironment {
* the message.
*/
final
def
echo
(
message
:
String
)
:
IO
[
RedisError
,
String
]
=
{
val
command
=
RedisCommand
(
Echo
,
StringInput
,
MultiStringOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Echo
,
StringInput
,
MultiStringOutput
,
executor
)
command
.
run
(
message
)
}
...
...
@@ -299,7 +298,7 @@ trait Connection extends RedisEnvironment {
* test if a connection is still alive, or to measure latency.
*/
final
def
ping
(
message
:
Option
[
String
]
=
None
)
:
IO
[
RedisError
,
String
]
=
{
val
command
=
RedisCommand
(
Ping
,
OptionalInput
(
StringInput
),
SingleOrMultiStringOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Ping
,
OptionalInput
(
StringInput
),
SingleOrMultiStringOutput
,
executor
)
command
.
run
(
message
)
}
...
...
@@ -312,7 +311,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
quit
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
Quit
,
NoInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Quit
,
NoInput
,
UnitOutput
,
executor
)
command
.
run
(())
}
...
...
@@ -325,7 +324,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
reset
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
Reset
,
NoInput
,
ResetOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Reset
,
NoInput
,
ResetOutput
,
executor
)
command
.
run
(())
}
...
...
@@ -341,7 +340,7 @@ trait Connection extends RedisEnvironment {
* the Unit value.
*/
final
def
select
(
index
:
Long
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
Select
,
LongInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Select
,
LongInput
,
UnitOutput
,
executor
)
command
.
run
(
index
)
}
...
...
redis/src/main/scala/zio/redis/api/Geo.scala
浏览文件 @
1a89cdbb
...
...
@@ -46,7 +46,6 @@ trait Geo extends RedisEnvironment {
GeoAdd
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
Tuple2
(
LongLatInput
,
ArbitraryValueInput
[
M
]()))),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
(
item
,
items
.
toList
)))
...
...
@@ -81,7 +80,6 @@ trait Geo extends RedisEnvironment {
OptionalInput
(
RadiusUnitInput
)
),
OptionalOutput
(
DoubleOutput
),
codec
,
executor
)
command
.
run
((
key
,
member1
,
member2
,
radiusUnit
))
...
...
@@ -109,7 +107,6 @@ trait Geo extends RedisEnvironment {
GeoHash
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
ChunkOutput
(
OptionalOutput
(
MultiStringOutput
)),
codec
,
executor
)
command
.
run
((
key
,
(
member
,
members
.
toList
)))
...
...
@@ -134,13 +131,7 @@ trait Geo extends RedisEnvironment {
members
:
M*
)
:
IO
[
RedisError
,
Chunk
[
Option
[
LongLat
]]]
=
{
val
command
=
RedisCommand
(
GeoPos
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
GeoOutput
,
codec
,
executor
)
RedisCommand
(
GeoPos
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
GeoOutput
,
executor
)
command
.
run
((
key
,
(
member
,
members
.
toList
)))
}
...
...
@@ -194,7 +185,6 @@ trait Geo extends RedisEnvironment {
OptionalInput
(
OrderInput
)
),
GeoRadiusOutput
,
codec
,
executor
)
command
.
run
((
key
,
center
,
radius
,
radiusUnit
,
withCoord
,
withDist
,
withHash
,
count
,
order
))
...
...
@@ -259,7 +249,6 @@ trait Geo extends RedisEnvironment {
OptionalInput
(
StoreDistInput
)
),
LongOutput
,
codec
,
executor
)
command
.
run
(
...
...
@@ -317,7 +306,6 @@ trait Geo extends RedisEnvironment {
OptionalInput
(
OrderInput
)
),
GeoRadiusOutput
,
codec
,
executor
)
command
.
run
((
key
,
member
,
radius
,
radiusUnit
,
withCoord
,
withDist
,
withHash
,
count
,
order
))
...
...
@@ -382,7 +370,6 @@ trait Geo extends RedisEnvironment {
OptionalInput
(
StoreDistInput
)
),
LongOutput
,
codec
,
executor
)
command
.
run
(
...
...
redis/src/main/scala/zio/redis/api/Hashes.scala
浏览文件 @
1a89cdbb
...
...
@@ -40,13 +40,7 @@ trait Hashes extends RedisEnvironment {
*/
final
def
hDel
[
K:
Schema
,
F:
Schema
](
key
:
K
,
field
:
F
,
fields
:
F*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
HDel
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
F
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
HDel
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
F
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
field
,
fields
.
toList
)))
}
...
...
@@ -62,7 +56,7 @@ trait Hashes extends RedisEnvironment {
*/
final
def
hExists
[
K:
Schema
,
F:
Schema
](
key
:
K
,
field
:
F
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
HExists
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
]()),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
HExists
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
]()),
BoolOutput
,
executor
)
command
.
run
((
key
,
field
))
}
...
...
@@ -83,7 +77,6 @@ trait Hashes extends RedisEnvironment {
HGet
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
]()),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
.
run
((
key
,
field
))
...
...
@@ -104,7 +97,6 @@ trait Hashes extends RedisEnvironment {
HGetAll
,
ArbitraryKeyInput
[
K
](),
KeyValueOutput
(
ArbitraryOutput
[
F
](),
ArbitraryOutput
[
V
]()),
codec
,
executor
)
command
.
run
(
key
)
...
...
@@ -126,13 +118,7 @@ trait Hashes extends RedisEnvironment {
*/
final
def
hIncrBy
[
K:
Schema
,
F:
Schema
](
key
:
K
,
field
:
F
,
increment
:
Long
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
HIncrBy
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
](),
LongInput
),
LongOutput
,
codec
,
executor
)
RedisCommand
(
HIncrBy
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
](),
LongInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
field
,
increment
))
}
...
...
@@ -159,7 +145,6 @@ trait Hashes extends RedisEnvironment {
HIncrByFloat
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
](),
DoubleInput
),
DoubleOutput
,
codec
,
executor
)
command
.
run
((
key
,
field
,
increment
))
...
...
@@ -176,7 +161,7 @@ trait Hashes extends RedisEnvironment {
final
def
hKeys
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
F:
Schema
]
:
IO
[
RedisError
,
Chunk
[
F
]]
=
RedisCommand
(
HKeys
,
ArbitraryKeyInput
[
K
](),
ChunkOutput
(
ArbitraryOutput
[
F
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
HKeys
,
ArbitraryKeyInput
[
K
](),
ChunkOutput
(
ArbitraryOutput
[
F
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -188,7 +173,7 @@ trait Hashes extends RedisEnvironment {
* number of fields.
*/
final
def
hLen
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
HLen
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
HLen
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -215,7 +200,6 @@ trait Hashes extends RedisEnvironment {
HmGet
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
F
]())),
ChunkOutput
(
OptionalOutput
(
ArbitraryOutput
[
V
]())),
codec
,
executor
)
command
.
run
((
key
,
(
field
,
fields
.
toList
)))
...
...
@@ -244,7 +228,6 @@ trait Hashes extends RedisEnvironment {
HmSet
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
Tuple2
(
ArbitraryValueInput
[
F
](),
ArbitraryValueInput
[
V
]()))),
UnitOutput
,
codec
,
executor
)
command
.
run
((
key
,
(
pair
,
pairs
.
toList
)))
...
...
@@ -276,7 +259,6 @@ trait Hashes extends RedisEnvironment {
HScan
,
Tuple4
(
ArbitraryKeyInput
[
K
](),
LongInput
,
OptionalInput
(
PatternInput
),
OptionalInput
(
CountInput
)),
Tuple2Output
(
ArbitraryOutput
[
Long
](),
ChunkTuple2Output
(
ArbitraryOutput
[
F
](),
ArbitraryOutput
[
V
]())),
codec
,
executor
)
command
.
run
((
key
,
cursor
,
pattern
.
map
(
Pattern
(
_
)),
count
))
...
...
@@ -304,7 +286,6 @@ trait Hashes extends RedisEnvironment {
HSet
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
Tuple2
(
ArbitraryValueInput
[
F
](),
ArbitraryValueInput
[
V
]()))),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
(
pair
,
pairs
.
toList
)))
...
...
@@ -332,7 +313,6 @@ trait Hashes extends RedisEnvironment {
HSetNx
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
](),
ArbitraryValueInput
[
V
]()),
BoolOutput
,
codec
,
executor
)
command
.
run
((
key
,
field
,
value
))
...
...
@@ -350,7 +330,7 @@ trait Hashes extends RedisEnvironment {
*/
final
def
hStrLen
[
K:
Schema
,
F:
Schema
](
key
:
K
,
field
:
F
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
HStrLen
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
]()),
LongOutput
,
codec
,
executor
)
RedisCommand
(
HStrLen
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
F
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
field
))
}
...
...
@@ -365,7 +345,7 @@ trait Hashes extends RedisEnvironment {
final
def
hVals
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Chunk
[
V
]]
=
RedisCommand
(
HVals
,
ArbitraryKeyInput
[
K
](),
ChunkOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
HVals
,
ArbitraryKeyInput
[
K
](),
ChunkOutput
(
ArbitraryOutput
[
V
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -379,7 +359,7 @@ trait Hashes extends RedisEnvironment {
final
def
hRandField
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Option
[
V
]]
=
RedisCommand
(
HRandField
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
HRandField
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -403,7 +383,6 @@ trait Hashes extends RedisEnvironment {
HRandField
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
OptionalInput
(
StringInput
)),
ChunkOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
command
.
run
((
key
,
count
,
if
(
withValues
)
Some
(
"WITHVALUES"
)
else
None
))
...
...
redis/src/main/scala/zio/redis/api/HyperLogLog.scala
浏览文件 @
1a89cdbb
...
...
@@ -39,13 +39,7 @@ trait HyperLogLog extends RedisEnvironment {
*/
final
def
pfAdd
[
K:
Schema
,
V:
Schema
](
key
:
K
,
element
:
V
,
elements
:
V*
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
PfAdd
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
PfAdd
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
BoolOutput
,
executor
)
command
.
run
((
key
,
(
element
,
elements
.
toList
)))
}
...
...
@@ -60,7 +54,7 @@ trait HyperLogLog extends RedisEnvironment {
* approximate number of unique elements observed via PFADD.
*/
final
def
pfCount
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
PfCount
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
PfCount
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -76,13 +70,7 @@ trait HyperLogLog extends RedisEnvironment {
*/
final
def
pfMerge
[
K:
Schema
](
destKey
:
K
,
sourceKey
:
K
,
sourceKeys
:
K*
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
PfMerge
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryKeyInput
[
K
]())),
UnitOutput
,
codec
,
executor
)
RedisCommand
(
PfMerge
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryKeyInput
[
K
]())),
UnitOutput
,
executor
)
command
.
run
((
destKey
,
(
sourceKey
,
sourceKeys
.
toList
)))
}
}
...
...
redis/src/main/scala/zio/redis/api/Keys.scala
浏览文件 @
1a89cdbb
...
...
@@ -42,7 +42,7 @@ trait Keys extends RedisEnvironment {
* [[unlink]]
*/
final
def
del
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Del
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Del
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -55,7 +55,7 @@ trait Keys extends RedisEnvironment {
* bytes for value stored at key.
*/
final
def
dump
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Chunk
[
Byte
]]
=
{
val
command
=
RedisCommand
(
Dump
,
ArbitraryKeyInput
[
K
](),
BulkStringOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Dump
,
ArbitraryKeyInput
[
K
](),
BulkStringOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -71,7 +71,7 @@ trait Keys extends RedisEnvironment {
* The number of keys existing.
*/
final
def
exists
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Exists
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Exists
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -90,7 +90,7 @@ trait Keys extends RedisEnvironment {
*/
final
def
expire
[
K:
Schema
](
key
:
K
,
timeout
:
Duration
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
Expire
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
DurationSecondsInput
),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
Expire
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
DurationSecondsInput
),
BoolOutput
,
executor
)
command
.
run
((
key
,
timeout
))
}
...
...
@@ -108,7 +108,7 @@ trait Keys extends RedisEnvironment {
* [[expire]]
*/
final
def
expireAt
[
K:
Schema
](
key
:
K
,
timestamp
:
Instant
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
ExpireAt
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
TimeSecondsInput
),
BoolOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ExpireAt
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
TimeSecondsInput
),
BoolOutput
,
executor
)
command
.
run
((
key
,
timestamp
))
}
...
...
@@ -123,7 +123,7 @@ trait Keys extends RedisEnvironment {
final
def
keys
(
pattern
:
String
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Chunk
[
V
]]
=
RedisCommand
(
Keys
.
Keys
,
StringInput
,
ChunkOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
).
run
(
pattern
)
RedisCommand
(
Keys
.
Keys
,
StringInput
,
ChunkOutput
(
ArbitraryOutput
[
V
]()),
executor
).
run
(
pattern
)
}
/**
...
...
@@ -176,7 +176,6 @@ trait Keys extends RedisEnvironment {
OptionalInput
(
NonEmptyList
(
ArbitraryKeyInput
[
K
]()))
),
StringOutput
,
codec
,
executor
)
command
.
run
((
host
,
port
,
key
,
destinationDb
,
timeout
.
toMillis
,
copy
,
replace
,
auth
,
keys
))
...
...
@@ -194,7 +193,7 @@ trait Keys extends RedisEnvironment {
* true if the key was moved.
*/
final
def
move
[
K:
Schema
](
key
:
K
,
destinationDb
:
Long
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
Move
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
BoolOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Move
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
BoolOutput
,
executor
)
command
.
run
((
key
,
destinationDb
))
}
...
...
@@ -207,7 +206,7 @@ trait Keys extends RedisEnvironment {
* true if timeout was removed, false if key does not exist or does not have an associated timeout.
*/
final
def
persist
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
Persist
,
ArbitraryKeyInput
[
K
](),
BoolOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Persist
,
ArbitraryKeyInput
[
K
](),
BoolOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -226,7 +225,7 @@ trait Keys extends RedisEnvironment {
*/
final
def
pExpire
[
K:
Schema
](
key
:
K
,
timeout
:
Duration
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
PExpire
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
DurationMillisecondsInput
),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
PExpire
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
DurationMillisecondsInput
),
BoolOutput
,
executor
)
command
.
run
((
key
,
timeout
))
}
...
...
@@ -245,7 +244,7 @@ trait Keys extends RedisEnvironment {
*/
final
def
pExpireAt
[
K:
Schema
](
key
:
K
,
timestamp
:
Instant
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
PExpireAt
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
TimeMillisecondsInput
),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
PExpireAt
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
TimeMillisecondsInput
),
BoolOutput
,
executor
)
command
.
run
((
key
,
timestamp
))
}
...
...
@@ -258,7 +257,7 @@ trait Keys extends RedisEnvironment {
* remaining time to live of a key that has a timeout, error otherwise.
*/
final
def
pTtl
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Duration
]
=
{
val
command
=
RedisCommand
(
PTtl
,
ArbitraryKeyInput
[
K
](),
DurationMillisecondsOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
PTtl
,
ArbitraryKeyInput
[
K
](),
DurationMillisecondsOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -271,7 +270,7 @@ trait Keys extends RedisEnvironment {
final
def
randomKey
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Option
[
V
]]
=
RedisCommand
(
RandomKey
,
NoInput
,
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
).
run
(())
RedisCommand
(
RandomKey
,
NoInput
,
OptionalOutput
(
ArbitraryOutput
[
V
]()),
executor
).
run
(())
}
/**
...
...
@@ -286,7 +285,7 @@ trait Keys extends RedisEnvironment {
*/
final
def
rename
[
K:
Schema
](
key
:
K
,
newKey
:
K
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
Rename
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryKeyInput
[
K
]()),
UnitOutput
,
codec
,
executor
)
RedisCommand
(
Rename
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryKeyInput
[
K
]()),
UnitOutput
,
executor
)
command
.
run
((
key
,
newKey
))
}
...
...
@@ -302,7 +301,7 @@ trait Keys extends RedisEnvironment {
*/
final
def
renameNx
[
K:
Schema
](
key
:
K
,
newKey
:
K
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
RenameNx
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryKeyInput
[
K
]()),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
RenameNx
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryKeyInput
[
K
]()),
BoolOutput
,
executor
)
command
.
run
((
key
,
newKey
))
}
...
...
@@ -349,7 +348,6 @@ trait Keys extends RedisEnvironment {
OptionalInput
(
FreqInput
)
),
UnitOutput
,
codec
,
executor
)
command
.
run
((
key
,
ttl
,
value
,
replace
,
absTtl
,
idleTime
,
freq
))
...
...
@@ -383,7 +381,6 @@ trait Keys extends RedisEnvironment {
Scan
,
Tuple4
(
LongInput
,
OptionalInput
(
PatternInput
),
OptionalInput
(
CountInput
),
OptionalInput
(
RedisTypeInput
)),
Tuple2Output
(
ArbitraryOutput
[
Long
](),
ChunkOutput
(
ArbitraryOutput
[
K
]())),
codec
,
executor
)
command
.
run
((
cursor
,
pattern
.
map
(
Pattern
(
_
)),
count
,
`type`
))
...
...
@@ -429,7 +426,6 @@ trait Keys extends RedisEnvironment {
OptionalInput
(
AlphaInput
)
),
ChunkOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
command
.
run
((
key
,
by
,
limit
,
get
,
order
,
alpha
))
...
...
@@ -481,7 +477,6 @@ trait Keys extends RedisEnvironment {
StoreInput
),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
by
,
limit
,
get
,
order
,
alpha
,
storeAt
))
...
...
@@ -498,7 +493,7 @@ trait Keys extends RedisEnvironment {
* The number of keys that were touched.
*/
final
def
touch
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Touch
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Touch
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -511,7 +506,7 @@ trait Keys extends RedisEnvironment {
* remaining time to live of a key that has a timeout, error otherwise.
*/
final
def
ttl
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Duration
]
=
{
val
command
=
RedisCommand
(
Ttl
,
ArbitraryKeyInput
[
K
](),
DurationSecondsOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Ttl
,
ArbitraryKeyInput
[
K
](),
DurationSecondsOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -524,7 +519,7 @@ trait Keys extends RedisEnvironment {
* type of the value stored at key.
*/
final
def
typeOf
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
RedisType
]
=
{
val
command
=
RedisCommand
(
TypeOf
,
ArbitraryKeyInput
[
K
](),
TypeOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
TypeOf
,
ArbitraryKeyInput
[
K
](),
TypeOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -543,7 +538,7 @@ trait Keys extends RedisEnvironment {
* [[del]]
*/
final
def
unlink
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Unlink
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Unlink
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -559,7 +554,7 @@ trait Keys extends RedisEnvironment {
* the number of replicas reached both in case of failure and success.
*/
final
def
wait_
(
replicas
:
Long
,
timeout
:
Duration
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Wait
,
Tuple2
(
LongInput
,
LongInput
),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Wait
,
Tuple2
(
LongInput
,
LongInput
),
LongOutput
,
executor
)
command
.
run
((
replicas
,
timeout
.
toMillis
))
}
}
...
...
redis/src/main/scala/zio/redis/api/Lists.scala
浏览文件 @
1a89cdbb
...
...
@@ -51,7 +51,6 @@ trait Lists extends RedisEnvironment {
BrPopLPush
,
Tuple3
(
ArbitraryValueInput
[
S
](),
ArbitraryValueInput
[
D
](),
DurationSecondsInput
),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
...
...
@@ -73,13 +72,7 @@ trait Lists extends RedisEnvironment {
final
def
lIndex
[
K:
Schema
](
key
:
K
,
index
:
Long
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Option
[
V
]]
=
RedisCommand
(
LIndex
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
RedisCommand
(
LIndex
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
executor
)
.
run
((
key
,
index
))
}
...
...
@@ -92,7 +85,7 @@ trait Lists extends RedisEnvironment {
* the length of the list at key.
*/
final
def
lLen
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
LLen
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
LLen
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -107,7 +100,7 @@ trait Lists extends RedisEnvironment {
final
def
lPop
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Option
[
V
]]
=
RedisCommand
(
LPop
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
LPop
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -125,13 +118,7 @@ trait Lists extends RedisEnvironment {
*/
final
def
lPush
[
K:
Schema
,
V:
Schema
](
key
:
K
,
element
:
V
,
elements
:
V*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
LPush
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
LPush
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
element
,
elements
.
toList
)))
}
...
...
@@ -150,13 +137,7 @@ trait Lists extends RedisEnvironment {
*/
final
def
lPushX
[
K:
Schema
,
V:
Schema
](
key
:
K
,
element
:
V
,
elements
:
V*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
LPushX
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
LPushX
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
element
,
elements
.
toList
)))
}
...
...
@@ -174,13 +155,7 @@ trait Lists extends RedisEnvironment {
final
def
lRange
[
K:
Schema
](
key
:
K
,
range
:
Range
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Chunk
[
V
]]
=
RedisCommand
(
LRange
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
ChunkOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
RedisCommand
(
LRange
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
ChunkOutput
(
ArbitraryOutput
[
V
]()),
executor
)
.
run
((
key
,
range
))
}
...
...
@@ -203,7 +178,7 @@ trait Lists extends RedisEnvironment {
*/
final
def
lRem
[
K:
Schema
](
key
:
K
,
count
:
Long
,
element
:
String
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
LRem
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
StringInput
),
LongOutput
,
codec
,
executor
)
RedisCommand
(
LRem
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
StringInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
count
,
element
))
}
...
...
@@ -221,13 +196,7 @@ trait Lists extends RedisEnvironment {
*/
final
def
lSet
[
K:
Schema
,
V:
Schema
](
key
:
K
,
index
:
Long
,
element
:
V
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
LSet
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
ArbitraryValueInput
[
V
]()),
UnitOutput
,
codec
,
executor
)
RedisCommand
(
LSet
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
ArbitraryValueInput
[
V
]()),
UnitOutput
,
executor
)
command
.
run
((
key
,
index
,
element
))
}
...
...
@@ -243,7 +212,7 @@ trait Lists extends RedisEnvironment {
* the Unit value.
*/
final
def
lTrim
[
K:
Schema
](
key
:
K
,
range
:
Range
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
LTrim
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
LTrim
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
UnitOutput
,
executor
)
command
.
run
((
key
,
range
))
}
...
...
@@ -258,7 +227,7 @@ trait Lists extends RedisEnvironment {
final
def
rPop
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
V:
Schema
]
:
IO
[
RedisError
,
Option
[
V
]]
=
RedisCommand
(
RPop
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
RPop
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -280,7 +249,6 @@ trait Lists extends RedisEnvironment {
RPopLPush
,
Tuple2
(
ArbitraryValueInput
[
S
](),
ArbitraryValueInput
[
D
]()),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
.
run
((
source
,
destination
))
...
...
@@ -301,13 +269,7 @@ trait Lists extends RedisEnvironment {
*/
final
def
rPush
[
K:
Schema
,
V:
Schema
](
key
:
K
,
element
:
V
,
elements
:
V*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
RPush
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
RPush
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
element
,
elements
.
toList
)))
}
...
...
@@ -326,13 +288,7 @@ trait Lists extends RedisEnvironment {
*/
final
def
rPushX
[
K:
Schema
,
V:
Schema
](
key
:
K
,
element
:
V
,
elements
:
V*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
RPushX
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
RPushX
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
V
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
element
,
elements
.
toList
)))
}
...
...
@@ -360,7 +316,6 @@ trait Lists extends RedisEnvironment {
BlPop
,
Tuple2
(
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
DurationSecondsInput
),
OptionalOutput
(
Tuple2Output
(
ArbitraryOutput
[
K
](),
ArbitraryOutput
[
V
]())),
codec
,
executor
)
command
.
run
(((
key
,
keys
.
toList
),
timeout
))
...
...
@@ -391,7 +346,6 @@ trait Lists extends RedisEnvironment {
BrPop
,
Tuple2
(
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
DurationSecondsInput
),
OptionalOutput
(
Tuple2Output
(
ArbitraryOutput
[
K
](),
ArbitraryOutput
[
V
]())),
codec
,
executor
)
command
.
run
(((
key
,
keys
.
toList
),
timeout
))
...
...
@@ -422,7 +376,6 @@ trait Lists extends RedisEnvironment {
LInsert
,
Tuple4
(
ArbitraryKeyInput
[
K
](),
PositionInput
,
ArbitraryValueInput
[
V
](),
ArbitraryValueInput
[
V
]()),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
position
,
pivot
,
element
))
...
...
@@ -456,7 +409,6 @@ trait Lists extends RedisEnvironment {
LMove
,
Tuple4
(
ArbitraryValueInput
[
S
](),
ArbitraryValueInput
[
D
](),
SideInput
,
SideInput
),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
command
.
run
((
source
,
destination
,
sourceSide
,
destinationSide
))
...
...
@@ -495,7 +447,6 @@ trait Lists extends RedisEnvironment {
BlMove
,
Tuple5
(
ArbitraryValueInput
[
S
](),
ArbitraryValueInput
[
D
](),
SideInput
,
SideInput
,
DurationSecondsInput
),
OptionalOutput
(
ArbitraryOutput
[
V
]()),
codec
,
executor
)
...
...
@@ -534,7 +485,6 @@ trait Lists extends RedisEnvironment {
OptionalInput
(
ListMaxLenInput
)
),
OptionalOutput
(
LongOutput
),
codec
,
executor
)
...
...
@@ -576,7 +526,6 @@ trait Lists extends RedisEnvironment {
OptionalInput
(
ListMaxLenInput
)
),
ChunkOutput
(
LongOutput
),
codec
,
executor
)
...
...
redis/src/main/scala/zio/redis/api/Scripting.scala
浏览文件 @
1a89cdbb
...
...
@@ -44,7 +44,7 @@ trait Scripting extends RedisEnvironment {
args
:
Chunk
[
A
]
)
:
ResultOutputBuilder
=
new
ResultOutputBuilder
{
def
returning
[
R:
Output
]
:
IO
[
RedisError
,
R
]
=
{
val
command
=
RedisCommand
(
Eval
,
EvalInput
(
Input
[
K
],
Input
[
A
]),
Output
[
R
],
codec
,
executor
)
val
command
=
RedisCommand
(
Eval
,
EvalInput
(
Input
[
K
],
Input
[
A
]),
Output
[
R
],
executor
)
command
.
run
((
script
,
keys
,
args
))
}
}
...
...
@@ -69,7 +69,7 @@ trait Scripting extends RedisEnvironment {
args
:
Chunk
[
A
]
)
:
ResultOutputBuilder
=
new
ResultOutputBuilder
{
def
returning
[
R:
Output
]
:
IO
[
RedisError
,
R
]
=
{
val
command
=
RedisCommand
(
EvalSha
,
EvalInput
(
Input
[
K
],
Input
[
A
]),
Output
[
R
],
codec
,
executor
)
val
command
=
RedisCommand
(
EvalSha
,
EvalInput
(
Input
[
K
],
Input
[
A
]),
Output
[
R
],
executor
)
command
.
run
((
sha1
,
keys
,
args
))
}
}
...
...
@@ -85,7 +85,7 @@ trait Scripting extends RedisEnvironment {
* the Unit value.
*/
final
def
scriptDebug
(
mode
:
DebugMode
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ScriptDebug
,
ScriptDebugInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ScriptDebug
,
ScriptDebugInput
,
UnitOutput
,
executor
)
command
.
run
(
mode
)
}
...
...
@@ -101,7 +101,7 @@ trait Scripting extends RedisEnvironment {
* otherwise false is returned.
*/
final
def
scriptExists
(
sha1
:
String
,
sha1s
:
String*
)
:
IO
[
RedisError
,
Chunk
[
Boolean
]]
=
{
val
command
=
RedisCommand
(
ScriptExists
,
NonEmptyList
(
StringInput
),
ChunkOutput
(
BoolOutput
),
codec
,
executor
)
val
command
=
RedisCommand
(
ScriptExists
,
NonEmptyList
(
StringInput
),
ChunkOutput
(
BoolOutput
),
executor
)
command
.
run
((
sha1
,
sha1s
.
toList
))
}
...
...
@@ -119,7 +119,7 @@ trait Scripting extends RedisEnvironment {
* the Unit value.
*/
final
def
scriptFlush
(
mode
:
Option
[
FlushMode
]
=
None
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ScriptFlush
,
OptionalInput
(
ScriptFlushInput
),
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ScriptFlush
,
OptionalInput
(
ScriptFlushInput
),
UnitOutput
,
executor
)
command
.
run
(
mode
)
}
...
...
@@ -131,7 +131,7 @@ trait Scripting extends RedisEnvironment {
* the Unit value.
*/
final
def
scriptKill
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ScriptKill
,
NoInput
,
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ScriptKill
,
NoInput
,
UnitOutput
,
executor
)
command
.
run
(())
}
...
...
@@ -145,7 +145,7 @@ trait Scripting extends RedisEnvironment {
* the SHA1 digest of the script added into the script cache.
*/
final
def
scriptLoad
(
script
:
String
)
:
IO
[
RedisError
,
String
]
=
{
val
command
=
RedisCommand
(
ScriptLoad
,
StringInput
,
MultiStringOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ScriptLoad
,
StringInput
,
MultiStringOutput
,
executor
)
command
.
run
(
script
)
}
}
...
...
redis/src/main/scala/zio/redis/api/Sets.scala
浏览文件 @
1a89cdbb
...
...
@@ -41,13 +41,7 @@ trait Sets extends RedisEnvironment {
*/
final
def
sAdd
[
K:
Schema
,
M:
Schema
](
key
:
K
,
member
:
M
,
members
:
M*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
SAdd
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
SAdd
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
member
,
members
.
toList
)))
}
...
...
@@ -60,7 +54,7 @@ trait Sets extends RedisEnvironment {
* Returns the cardinality (number of elements) of the set, or 0 if key does not exist.
*/
final
def
sCard
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
SCard
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
SCard
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -77,7 +71,7 @@ trait Sets extends RedisEnvironment {
final
def
sDiff
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Chunk
[
R
]]
=
RedisCommand
(
SDiff
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
RedisCommand
(
SDiff
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
executor
)
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -98,7 +92,6 @@ trait Sets extends RedisEnvironment {
SDiffStore
,
Tuple2
(
ArbitraryValueInput
[
D
](),
NonEmptyList
(
ArbitraryKeyInput
[
K
]())),
LongOutput
,
codec
,
executor
)
command
.
run
((
destination
,
(
key
,
keys
.
toList
)))
...
...
@@ -117,7 +110,7 @@ trait Sets extends RedisEnvironment {
final
def
sInter
[
K:
Schema
](
destination
:
K
,
keys
:
K*
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Chunk
[
R
]]
=
RedisCommand
(
SInter
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
RedisCommand
(
SInter
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
executor
)
.
run
((
destination
,
keys
.
toList
))
}
...
...
@@ -142,7 +135,6 @@ trait Sets extends RedisEnvironment {
SInterStore
,
Tuple2
(
ArbitraryValueInput
[
D
](),
NonEmptyList
(
ArbitraryKeyInput
[
K
]())),
LongOutput
,
codec
,
executor
)
command
.
run
((
destination
,
(
key
,
keys
.
toList
)))
...
...
@@ -161,7 +153,7 @@ trait Sets extends RedisEnvironment {
*/
final
def
sIsMember
[
K:
Schema
,
M:
Schema
](
key
:
K
,
member
:
M
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
SIsMember
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
M
]()),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
SIsMember
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
M
]()),
BoolOutput
,
executor
)
command
.
run
((
key
,
member
))
}
...
...
@@ -176,7 +168,7 @@ trait Sets extends RedisEnvironment {
final
def
sMembers
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Chunk
[
R
]]
=
RedisCommand
(
SMembers
,
ArbitraryKeyInput
[
K
](),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
SMembers
,
ArbitraryKeyInput
[
K
](),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -200,7 +192,6 @@ trait Sets extends RedisEnvironment {
SMove
,
Tuple3
(
ArbitraryValueInput
[
S
](),
ArbitraryValueInput
[
D
](),
ArbitraryValueInput
[
M
]()),
BoolOutput
,
codec
,
executor
)
command
.
run
((
source
,
destination
,
member
))
...
...
@@ -223,7 +214,6 @@ trait Sets extends RedisEnvironment {
SPop
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
OptionalInput
(
LongInput
)),
MultiStringChunkOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
command
.
run
((
key
,
count
))
...
...
@@ -247,7 +237,6 @@ trait Sets extends RedisEnvironment {
SRandMember
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
OptionalInput
(
LongInput
)),
MultiStringChunkOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
command
.
run
((
key
,
count
))
...
...
@@ -268,13 +257,7 @@ trait Sets extends RedisEnvironment {
*/
final
def
sRem
[
K:
Schema
,
M:
Schema
](
key
:
K
,
member
:
M
,
members
:
M*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
SRem
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
SRem
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
member
,
members
.
toList
)))
}
...
...
@@ -307,7 +290,6 @@ trait Sets extends RedisEnvironment {
SScan
,
Tuple4
(
ArbitraryKeyInput
[
K
](),
LongInput
,
OptionalInput
(
PatternInput
),
OptionalInput
(
CountInput
)),
Tuple2Output
(
MultiStringOutput
.
map
(
_
.
toLong
),
ChunkOutput
(
ArbitraryOutput
[
R
]())),
codec
,
executor
)
command
.
run
((
key
,
cursor
,
pattern
.
map
(
Pattern
(
_
)),
count
))
...
...
@@ -327,7 +309,7 @@ trait Sets extends RedisEnvironment {
final
def
sUnion
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Chunk
[
R
]]
=
RedisCommand
(
SUnion
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
RedisCommand
(
SUnion
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
executor
)
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -352,7 +334,6 @@ trait Sets extends RedisEnvironment {
SUnionStore
,
Tuple2
(
ArbitraryValueInput
[
D
](),
NonEmptyList
(
ArbitraryKeyInput
[
K
]())),
LongOutput
,
codec
,
executor
)
command
.
run
((
destination
,
(
key
,
keys
.
toList
)))
...
...
redis/src/main/scala/zio/redis/api/SortedSets.scala
浏览文件 @
1a89cdbb
...
...
@@ -55,7 +55,6 @@ trait SortedSets extends RedisEnvironment {
BzPopMax
,
Tuple2
(
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
DurationSecondsInput
),
OptionalOutput
(
memberScoreOutput
),
codec
,
executor
)
command
.
run
(((
key
,
keys
.
toList
),
timeout
))
...
...
@@ -91,7 +90,6 @@ trait SortedSets extends RedisEnvironment {
BzPopMin
,
Tuple2
(
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
DurationSecondsInput
),
OptionalOutput
(
memberScoreOutput
),
codec
,
executor
)
command
.
run
(((
key
,
keys
.
toList
),
timeout
))
...
...
@@ -128,7 +126,6 @@ trait SortedSets extends RedisEnvironment {
NonEmptyList
(
MemberScoreInput
[
M
]())
),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
update
,
change
,
(
memberScore
,
memberScores
.
toList
)))
...
...
@@ -168,7 +165,6 @@ trait SortedSets extends RedisEnvironment {
NonEmptyList
(
MemberScoreInput
[
M
]())
),
OptionalOutput
(
DoubleOutput
),
codec
,
executor
)
command
.
run
((
key
,
update
,
change
,
increment
,
(
memberScore
,
memberScores
.
toList
)))
...
...
@@ -183,7 +179,7 @@ trait SortedSets extends RedisEnvironment {
* The cardinality (number of elements) of the sorted set, or 0 if key does not exist.
*/
final
def
zCard
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
ZCard
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ZCard
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -198,7 +194,7 @@ trait SortedSets extends RedisEnvironment {
* the number of elements in the specified score range.
*/
final
def
zCount
[
K:
Schema
](
key
:
K
,
range
:
Range
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
ZCount
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ZCount
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
range
))
}
...
...
@@ -229,7 +225,6 @@ trait SortedSets extends RedisEnvironment {
NonEmptyList
(
ArbitraryKeyInput
[
K
]())
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
inputKeysNum
,
(
key
,
keys
.
toList
)))
...
...
@@ -265,7 +260,6 @@ trait SortedSets extends RedisEnvironment {
),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
inputKeysNum
,
(
key
,
keys
.
toList
),
WithScores
.
stringify
))
...
...
@@ -301,7 +295,6 @@ trait SortedSets extends RedisEnvironment {
NonEmptyList
(
ArbitraryKeyInput
[
K
]())
),
LongOutput
,
codec
,
executor
)
command
.
run
((
destination
,
inputKeysNum
,
(
key
,
keys
.
toList
)))
...
...
@@ -325,13 +318,7 @@ trait SortedSets extends RedisEnvironment {
member
:
M
)
:
IO
[
RedisError
,
Double
]
=
{
val
command
=
RedisCommand
(
ZIncrBy
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
ArbitraryValueInput
[
M
]()),
DoubleOutput
,
codec
,
executor
)
RedisCommand
(
ZIncrBy
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
ArbitraryValueInput
[
M
]()),
DoubleOutput
,
executor
)
command
.
run
((
key
,
increment
,
member
))
}
...
...
@@ -368,7 +355,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
WeightsInput
)
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
inputKeysNum
,
(
key
,
keys
.
toList
),
aggregate
,
weights
))
...
...
@@ -410,7 +396,6 @@ trait SortedSets extends RedisEnvironment {
),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
inputKeysNum
,
(
key
,
keys
.
toList
),
aggregate
,
weights
,
WithScores
.
stringify
))
...
...
@@ -451,7 +436,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
WeightsInput
)
),
LongOutput
,
codec
,
executor
)
command
.
run
((
destination
,
inputKeysNum
,
(
key
,
keys
.
toList
),
aggregate
,
weights
))
...
...
@@ -472,7 +456,6 @@ trait SortedSets extends RedisEnvironment {
ZLexCount
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
String
](),
ArbitraryValueInput
[
String
]()),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
lexRange
.
min
.
stringify
,
lexRange
.
max
.
stringify
))
...
...
@@ -501,7 +484,6 @@ trait SortedSets extends RedisEnvironment {
Tuple2
(
ArbitraryKeyInput
[
K
](),
OptionalInput
(
LongInput
)),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
key
,
count
))
...
...
@@ -531,7 +513,6 @@ trait SortedSets extends RedisEnvironment {
Tuple2
(
ArbitraryKeyInput
[
K
](),
OptionalInput
(
LongInput
)),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
key
,
count
))
...
...
@@ -551,13 +532,8 @@ trait SortedSets extends RedisEnvironment {
final
def
zRange
[
K:
Schema
](
key
:
K
,
range
:
Range
)
:
ResultBuilder1
[
Chunk
]
=
new
ResultBuilder1
[
Chunk
]
{
def
returning
[
M:
Schema
]
:
IO
[
RedisError
,
Chunk
[
M
]]
=
{
val
command
=
RedisCommand
(
ZRange
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
val
command
=
RedisCommand
(
ZRange
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
executor
)
command
.
run
((
key
,
range
))
}
}
...
...
@@ -583,7 +559,6 @@ trait SortedSets extends RedisEnvironment {
Tuple3
(
ArbitraryKeyInput
[
K
](),
RangeInput
,
ArbitraryValueInput
[
String
]()),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
key
,
range
,
WithScores
.
stringify
))
...
...
@@ -619,7 +594,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
LimitInput
)
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
key
,
lexRange
.
min
.
stringify
,
lexRange
.
max
.
stringify
,
limit
))
...
...
@@ -655,7 +629,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
LimitInput
)
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
key
,
scoreRange
.
min
.
stringify
,
scoreRange
.
max
.
stringify
,
limit
))
...
...
@@ -693,7 +666,6 @@ trait SortedSets extends RedisEnvironment {
),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
key
,
scoreRange
.
min
.
stringify
,
scoreRange
.
max
.
stringify
,
WithScores
.
stringify
,
limit
))
...
...
@@ -716,7 +688,6 @@ trait SortedSets extends RedisEnvironment {
ZRank
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
M
]()),
OptionalOutput
(
LongOutput
),
codec
,
executor
)
command
.
run
((
key
,
member
))
...
...
@@ -740,13 +711,7 @@ trait SortedSets extends RedisEnvironment {
restMembers
:
M*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
ZRem
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
ZRem
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
ArbitraryValueInput
[
M
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
firstMember
,
restMembers
.
toList
)))
}
...
...
@@ -765,7 +730,6 @@ trait SortedSets extends RedisEnvironment {
ZRemRangeByLex
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
String
](),
ArbitraryValueInput
[
String
]()),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
lexRange
.
min
.
stringify
,
lexRange
.
max
.
stringify
))
...
...
@@ -782,7 +746,7 @@ trait SortedSets extends RedisEnvironment {
* The number of elements removed.
*/
final
def
zRemRangeByRank
[
K:
Schema
](
key
:
K
,
range
:
Range
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
ZRemRangeByRank
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
ZRemRangeByRank
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
range
))
}
...
...
@@ -801,7 +765,6 @@ trait SortedSets extends RedisEnvironment {
ZRemRangeByScore
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
String
](),
ArbitraryValueInput
[
String
]()),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
scoreRange
.
min
.
stringify
,
scoreRange
.
max
.
stringify
))
...
...
@@ -824,7 +787,6 @@ trait SortedSets extends RedisEnvironment {
ZRevRange
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
key
,
range
))
...
...
@@ -852,7 +814,6 @@ trait SortedSets extends RedisEnvironment {
Tuple3
(
ArbitraryKeyInput
[
K
](),
RangeInput
,
ArbitraryValueInput
[
String
]()),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
key
,
range
,
WithScores
.
stringify
))
...
...
@@ -888,7 +849,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
LimitInput
)
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
key
,
lexRange
.
max
.
stringify
,
lexRange
.
min
.
stringify
,
limit
))
...
...
@@ -924,7 +884,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
LimitInput
)
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
key
,
scoreRange
.
max
.
stringify
,
scoreRange
.
min
.
stringify
,
limit
))
...
...
@@ -962,7 +921,6 @@ trait SortedSets extends RedisEnvironment {
),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
key
,
scoreRange
.
max
.
stringify
,
scoreRange
.
min
.
stringify
,
WithScores
.
stringify
,
limit
))
...
...
@@ -984,7 +942,6 @@ trait SortedSets extends RedisEnvironment {
ZRevRank
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
M
]()),
OptionalOutput
(
LongOutput
),
codec
,
executor
)
command
.
run
((
key
,
member
))
...
...
@@ -1018,7 +975,6 @@ trait SortedSets extends RedisEnvironment {
ZScan
,
Tuple4
(
ArbitraryKeyInput
[
K
](),
LongInput
,
OptionalInput
(
PatternInput
),
OptionalInput
(
CountInput
)),
Tuple2Output
(
MultiStringOutput
.
map
(
_
.
toLong
),
memberScoresOutput
),
codec
,
executor
)
command
.
run
((
key
,
cursor
,
pattern
.
map
(
Pattern
(
_
)),
count
))
...
...
@@ -1040,7 +996,6 @@ trait SortedSets extends RedisEnvironment {
ZScore
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
M
]()),
OptionalOutput
(
DoubleOutput
),
codec
,
executor
)
command
.
run
((
key
,
member
))
...
...
@@ -1080,7 +1035,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
AggregateInput
)
),
ChunkOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
inputKeysNum
,
(
key
,
keys
.
toList
),
weights
,
aggregate
))
...
...
@@ -1123,7 +1077,6 @@ trait SortedSets extends RedisEnvironment {
),
ChunkTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
command
.
run
((
inputKeysNum
,
(
key
,
keys
.
toList
),
weights
,
aggregate
,
WithScores
.
stringify
))
...
...
@@ -1164,7 +1117,6 @@ trait SortedSets extends RedisEnvironment {
OptionalInput
(
AggregateInput
)
),
LongOutput
,
codec
,
executor
)
command
.
run
((
destination
,
inputKeysNum
,
(
key
,
keys
.
toList
),
weights
,
aggregate
))
...
...
@@ -1181,13 +1133,8 @@ trait SortedSets extends RedisEnvironment {
* List of scores or None associated with the specified member values (a double precision floating point number).
*/
final
def
zMScore
[
K:
Schema
](
key
:
K
,
keys
:
K*
)
:
IO
[
RedisError
,
Chunk
[
Option
[
Double
]]]
=
{
val
command
=
RedisCommand
(
ZMScore
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
OptionalOutput
(
DoubleOutput
)),
codec
,
executor
)
val
command
=
RedisCommand
(
ZMScore
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
OptionalOutput
(
DoubleOutput
)),
executor
)
command
.
run
((
key
,
keys
.
toList
))
}
...
...
@@ -1202,7 +1149,7 @@ trait SortedSets extends RedisEnvironment {
final
def
zRandMember
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Option
[
R
]]
=
RedisCommand
(
ZRandMember
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
RedisCommand
(
ZRandMember
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
executor
)
.
run
(
key
)
}
...
...
@@ -1227,7 +1174,6 @@ trait SortedSets extends RedisEnvironment {
ZRandMember
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
ZRandMemberOutput
(
ArbitraryOutput
[
M
]()),
codec
,
executor
)
command
.
run
((
key
,
count
))
...
...
@@ -1258,7 +1204,6 @@ trait SortedSets extends RedisEnvironment {
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
ArbitraryValueInput
[
String
]()),
ZRandMemberTuple2Output
(
ArbitraryOutput
[
M
](),
DoubleOutput
)
.
map
(
_
.
map
{
case
(
m
,
s
)
=>
MemberScore
(
s
,
m
)
}),
codec
,
executor
)
...
...
redis/src/main/scala/zio/redis/api/Streams.scala
浏览文件 @
1a89cdbb
...
...
@@ -52,7 +52,6 @@ trait Streams extends RedisEnvironment {
XAck
,
Tuple3
(
ArbitraryKeyInput
[
SK
](),
ArbitraryValueInput
[
G
](),
NonEmptyList
(
ArbitraryValueInput
[
I
]())),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
group
,
(
id
,
ids
.
toList
)))
...
...
@@ -89,7 +88,6 @@ trait Streams extends RedisEnvironment {
NonEmptyList
(
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]()))
),
ArbitraryOutput
[
R
](),
codec
,
executor
)
command
.
run
((
key
,
None
,
id
,
(
pair
,
pairs
.
toList
)))
...
...
@@ -108,7 +106,7 @@ trait Streams extends RedisEnvironment {
key
:
SK
)
:
ResultBuilder3
[
StreamInfo
]
=
new
ResultBuilder3
[
StreamInfo
]
{
def
returning
[
RI:
Schema
,
RK:
Schema
,
RV:
Schema
]
:
IO
[
RedisError
,
StreamInfo
[
RI
,
RK
,
RV
]]
=
{
val
command
=
RedisCommand
(
XInfoStream
,
ArbitraryKeyInput
[
SK
](),
StreamInfoOutput
[
RI
,
RK
,
RV
](),
codec
,
executor
)
val
command
=
RedisCommand
(
XInfoStream
,
ArbitraryKeyInput
[
SK
](),
StreamInfoOutput
[
RI
,
RK
,
RV
](),
executor
)
command
.
run
(
key
)
}
}
...
...
@@ -129,7 +127,6 @@ trait Streams extends RedisEnvironment {
XInfoStream
,
Tuple2
(
ArbitraryKeyInput
[
SK
](),
ArbitraryValueInput
[
String
]()),
StreamInfoFullOutput
[
RI
,
RK
,
RV
](),
codec
,
executor
)
command
.
run
((
key
,
"FULL"
))
...
...
@@ -155,7 +152,6 @@ trait Streams extends RedisEnvironment {
XInfoStream
,
Tuple3
(
ArbitraryKeyInput
[
SK
](),
ArbitraryValueInput
[
String
](),
CountInput
),
StreamInfoFullOutput
[
RI
,
RK
,
RV
](),
codec
,
executor
)
command
.
run
((
key
,
"FULL"
,
Count
(
count
)))
...
...
@@ -171,7 +167,7 @@ trait Streams extends RedisEnvironment {
* List of consumer groups associated with the stream stored at the specified key.
*/
final
def
xInfoGroups
[
SK:
Schema
](
key
:
SK
)
:
IO
[
RedisError
,
Chunk
[
StreamGroupsInfo
]]
=
{
val
command
=
RedisCommand
(
XInfoGroups
,
ArbitraryKeyInput
[
SK
](),
StreamGroupsInfoOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
XInfoGroups
,
ArbitraryKeyInput
[
SK
](),
StreamGroupsInfoOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -194,7 +190,6 @@ trait Streams extends RedisEnvironment {
XInfoConsumers
,
Tuple2
(
ArbitraryKeyInput
[
SK
](),
ArbitraryValueInput
[
SG
]()),
StreamConsumersInfoOutput
,
codec
,
executor
)
command
.
run
((
key
,
group
))
...
...
@@ -238,7 +233,6 @@ trait Streams extends RedisEnvironment {
NonEmptyList
(
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]()))
),
ArbitraryOutput
[
R
](),
codec
,
executor
)
command
.
run
((
key
,
Some
(
StreamMaxLen
(
approximate
,
count
)),
id
,
(
pair
,
pairs
.
toList
)))
...
...
@@ -298,7 +292,6 @@ trait Streams extends RedisEnvironment {
OptionalInput
(
WithForceInput
)
),
StreamEntriesOutput
[
I
,
RK
,
RV
](),
codec
,
executor
)
val
forceOpt
=
if
(
force
)
Some
(
WithForce
)
else
None
...
...
@@ -360,7 +353,6 @@ trait Streams extends RedisEnvironment {
WithJustIdInput
),
ChunkOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
val
forceOpt
=
if
(
force
)
Some
(
WithForce
)
else
None
...
...
@@ -382,13 +374,7 @@ trait Streams extends RedisEnvironment {
*/
final
def
xDel
[
SK:
Schema
,
I:
Schema
](
key
:
SK
,
id
:
I
,
ids
:
I*
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
XDel
,
Tuple2
(
ArbitraryKeyInput
[
SK
](),
NonEmptyList
(
ArbitraryValueInput
[
I
]())),
LongOutput
,
codec
,
executor
)
RedisCommand
(
XDel
,
Tuple2
(
ArbitraryKeyInput
[
SK
](),
NonEmptyList
(
ArbitraryValueInput
[
I
]())),
LongOutput
,
executor
)
command
.
run
((
key
,
(
id
,
ids
.
toList
)))
}
...
...
@@ -410,7 +396,7 @@ trait Streams extends RedisEnvironment {
id
:
I
,
mkStream
:
Boolean
=
false
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
XGroup
,
XGroupCreateInput
[
SK
,
SG
,
I
](),
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
XGroup
,
XGroupCreateInput
[
SK
,
SG
,
I
](),
UnitOutput
,
executor
)
command
.
run
(
Create
(
key
,
group
,
id
,
mkStream
))
}
...
...
@@ -429,7 +415,7 @@ trait Streams extends RedisEnvironment {
group
:
SG
,
id
:
I
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
XGroup
,
XGroupSetIdInput
[
SK
,
SG
,
I
](),
UnitOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
XGroup
,
XGroupSetIdInput
[
SK
,
SG
,
I
](),
UnitOutput
,
executor
)
command
.
run
(
SetId
(
key
,
group
,
id
))
}
...
...
@@ -444,7 +430,7 @@ trait Streams extends RedisEnvironment {
* flag that indicates if the deletion was successful.
*/
final
def
xGroupDestroy
[
SK:
Schema
,
SG:
Schema
](
key
:
SK
,
group
:
SG
)
:
IO
[
RedisError
,
Boolean
]
=
RedisCommand
(
XGroup
,
XGroupDestroyInput
[
SK
,
SG
](),
BoolOutput
,
codec
,
executor
).
run
(
Destroy
(
key
,
group
))
RedisCommand
(
XGroup
,
XGroupDestroyInput
[
SK
,
SG
](),
BoolOutput
,
executor
).
run
(
Destroy
(
key
,
group
))
/**
* Create a new consumer associated with a consumer group.
...
...
@@ -463,7 +449,7 @@ trait Streams extends RedisEnvironment {
group
:
SG
,
consumer
:
SC
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
XGroup
,
XGroupCreateConsumerInput
[
SK
,
SG
,
SC
](),
BoolOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
XGroup
,
XGroupCreateConsumerInput
[
SK
,
SG
,
SC
](),
BoolOutput
,
executor
)
command
.
run
(
CreateConsumer
(
key
,
group
,
consumer
))
}
...
...
@@ -484,7 +470,7 @@ trait Streams extends RedisEnvironment {
group
:
SG
,
consumer
:
SC
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
XGroup
,
XGroupDelConsumerInput
[
SK
,
SG
,
SC
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
XGroup
,
XGroupDelConsumerInput
[
SK
,
SG
,
SC
](),
LongOutput
,
executor
)
command
.
run
(
DelConsumer
(
key
,
group
,
consumer
))
}
...
...
@@ -497,7 +483,7 @@ trait Streams extends RedisEnvironment {
* the number of entries inside a stream.
*/
final
def
xLen
[
SK:
Schema
](
key
:
SK
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
XLen
,
ArbitraryKeyInput
[
SK
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
XLen
,
ArbitraryKeyInput
[
SK
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -516,7 +502,6 @@ trait Streams extends RedisEnvironment {
XPending
,
Tuple3
(
ArbitraryKeyInput
[
SK
](),
ArbitraryValueInput
[
SG
](),
OptionalInput
(
IdleInput
)),
XPendingOutput
,
codec
,
executor
)
command
.
run
((
key
,
group
,
None
))
...
...
@@ -563,7 +548,6 @@ trait Streams extends RedisEnvironment {
OptionalInput
(
ArbitraryValueInput
[
SC
]())
),
PendingMessagesOutput
,
codec
,
executor
)
command
.
run
((
key
,
group
,
idle
,
start
,
end
,
count
,
consumer
))
...
...
@@ -597,7 +581,6 @@ trait Streams extends RedisEnvironment {
OptionalInput
(
CountInput
)
),
StreamEntriesOutput
[
I
,
RK
,
RV
](),
codec
,
executor
)
command
.
run
((
key
,
start
,
end
,
None
))
...
...
@@ -635,7 +618,6 @@ trait Streams extends RedisEnvironment {
OptionalInput
(
CountInput
)
),
StreamEntriesOutput
[
I
,
RK
,
RV
](),
codec
,
executor
)
command
.
run
((
key
,
start
,
end
,
Some
(
Count
(
count
))))
...
...
@@ -669,7 +651,6 @@ trait Streams extends RedisEnvironment {
XRead
,
Tuple3
(
OptionalInput
(
CountInput
),
OptionalInput
(
BlockInput
),
StreamsInput
[
SK
,
I
]()),
ChunkOutput
(
StreamOutput
[
SK
,
I
,
RK
,
RV
]()),
codec
,
executor
)
command
.
run
((
count
.
map
(
Count
(
_
)),
block
,
(
stream
,
Chunk
.
fromIterable
(
streams
))))
...
...
@@ -719,7 +700,6 @@ trait Streams extends RedisEnvironment {
StreamsInput
[
SK
,
I
]()
),
ChunkOutput
(
StreamOutput
[
SK
,
I
,
RK
,
RV
]()),
codec
,
executor
)
val
noAckOpt
=
if
(
noAck
)
Some
(
NoAck
)
else
None
...
...
@@ -755,7 +735,6 @@ trait Streams extends RedisEnvironment {
OptionalInput
(
CountInput
)
),
StreamEntriesOutput
[
I
,
RK
,
RV
](),
codec
,
executor
)
command
.
run
((
key
,
end
,
start
,
None
))
...
...
@@ -793,7 +772,6 @@ trait Streams extends RedisEnvironment {
OptionalInput
(
CountInput
)
),
StreamEntriesOutput
[
I
,
RK
,
RV
](),
codec
,
executor
)
command
.
run
((
key
,
end
,
start
,
Some
(
Count
(
count
))))
...
...
@@ -817,7 +795,7 @@ trait Streams extends RedisEnvironment {
count
:
Long
,
approximate
:
Boolean
=
false
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
XTrim
,
Tuple2
(
ArbitraryKeyInput
[
SK
](),
StreamMaxLenInput
),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
XTrim
,
Tuple2
(
ArbitraryKeyInput
[
SK
](),
StreamMaxLenInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
StreamMaxLen
(
approximate
,
count
)))
}
}
...
...
redis/src/main/scala/zio/redis/api/Strings.scala
浏览文件 @
1a89cdbb
...
...
@@ -40,7 +40,7 @@ trait Strings extends RedisEnvironment {
*/
final
def
append
[
K:
Schema
,
V:
Schema
](
key
:
K
,
value
:
V
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Append
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]()),
LongOutput
,
codec
,
executor
)
RedisCommand
(
Append
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
value
))
}
...
...
@@ -56,7 +56,7 @@ trait Strings extends RedisEnvironment {
*/
final
def
bitCount
[
K:
Schema
](
key
:
K
,
range
:
Option
[
Range
]
=
None
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
BitCount
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
OptionalInput
(
RangeInput
)),
LongOutput
,
codec
,
executor
)
RedisCommand
(
BitCount
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
OptionalInput
(
RangeInput
)),
LongOutput
,
executor
)
command
.
run
((
key
,
range
))
}
...
...
@@ -81,7 +81,6 @@ trait Strings extends RedisEnvironment {
BitField
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
NonEmptyList
(
BitFieldCommandInput
)),
ChunkOutput
(
OptionalOutput
(
LongOutput
)),
codec
,
executor
)
command
.
run
((
key
,
(
bitFieldCommand
,
bitFieldCommands
.
toList
)))
...
...
@@ -112,7 +111,6 @@ trait Strings extends RedisEnvironment {
BitOp
,
Tuple3
(
BitOperationInput
,
ArbitraryValueInput
[
D
](),
NonEmptyList
(
ArbitraryValueInput
[
S
]())),
LongOutput
,
codec
,
executor
)
command
.
run
((
operation
,
destKey
,
(
srcKey
,
srcKeys
.
toList
)))
...
...
@@ -140,7 +138,6 @@ trait Strings extends RedisEnvironment {
BitPos
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
BoolInput
,
OptionalInput
(
BitPosRangeInput
)),
LongOutput
,
codec
,
executor
)
command
.
run
((
key
,
bit
,
range
))
...
...
@@ -155,7 +152,7 @@ trait Strings extends RedisEnvironment {
* Returns the value of key after the decrement.
*/
final
def
decr
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Decr
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Decr
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -170,7 +167,7 @@ trait Strings extends RedisEnvironment {
* Returns the value of key after the decrement.
*/
final
def
decrBy
[
K:
Schema
](
key
:
K
,
decrement
:
Long
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
DecrBy
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
DecrBy
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
decrement
))
}
...
...
@@ -185,7 +182,7 @@ trait Strings extends RedisEnvironment {
final
def
get
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Option
[
R
]]
=
RedisCommand
(
Get
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
Get
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -199,7 +196,7 @@ trait Strings extends RedisEnvironment {
* Returns the bit value stored at offset.
*/
final
def
getBit
[
K:
Schema
](
key
:
K
,
offset
:
Long
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
GetBit
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
GetBit
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
offset
))
}
...
...
@@ -220,7 +217,6 @@ trait Strings extends RedisEnvironment {
GetRange
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
RangeInput
),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
.
run
((
key
,
range
))
...
...
@@ -243,7 +239,6 @@ trait Strings extends RedisEnvironment {
GetSet
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]()),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
.
run
((
key
,
value
))
...
...
@@ -260,7 +255,7 @@ trait Strings extends RedisEnvironment {
final
def
getDel
[
K:
Schema
](
key
:
K
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Option
[
R
]]
=
RedisCommand
(
GetDel
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
).
run
(
key
)
RedisCommand
(
GetDel
,
ArbitraryKeyInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
executor
).
run
(
key
)
}
/**
...
...
@@ -279,7 +274,7 @@ trait Strings extends RedisEnvironment {
final
def
getEx
[
K:
Schema
](
key
:
K
,
expire
:
Expire
,
expireTime
:
Duration
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Option
[
R
]]
=
RedisCommand
(
GetEx
,
GetExInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
RedisCommand
(
GetEx
,
GetExInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
executor
)
.
run
((
key
,
expire
,
expireTime
))
}
...
...
@@ -299,7 +294,7 @@ trait Strings extends RedisEnvironment {
final
def
getEx
[
K:
Schema
](
key
:
K
,
expiredAt
:
ExpiredAt
,
timestamp
:
Instant
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Option
[
R
]]
=
RedisCommand
(
GetEx
,
GetExAtInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
RedisCommand
(
GetEx
,
GetExAtInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
executor
)
.
run
((
key
,
expiredAt
,
timestamp
))
}
...
...
@@ -316,7 +311,7 @@ trait Strings extends RedisEnvironment {
final
def
getEx
[
K:
Schema
](
key
:
K
,
persist
:
Boolean
)
:
ResultBuilder1
[
Option
]
=
new
ResultBuilder1
[
Option
]
{
def
returning
[
R:
Schema
]
:
IO
[
RedisError
,
Option
[
R
]]
=
RedisCommand
(
GetEx
,
GetExPersistInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
codec
,
executor
)
RedisCommand
(
GetEx
,
GetExPersistInput
[
K
](),
OptionalOutput
(
ArbitraryOutput
[
R
]()),
executor
)
.
run
((
key
,
persist
))
}
...
...
@@ -329,7 +324,7 @@ trait Strings extends RedisEnvironment {
* Returns the value of key after the increment.
*/
final
def
incr
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
Incr
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Incr
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -345,7 +340,7 @@ trait Strings extends RedisEnvironment {
*/
final
def
incrBy
[
K:
Schema
](
key
:
K
,
increment
:
Long
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
IncrBy
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
LongOutput
,
codec
,
executor
)
RedisCommand
(
IncrBy
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
LongInput
),
LongOutput
,
executor
)
command
.
run
((
key
,
increment
))
}
...
...
@@ -360,7 +355,7 @@ trait Strings extends RedisEnvironment {
* Returns the value of key after the increment.
*/
final
def
incrByFloat
[
K:
Schema
](
key
:
K
,
increment
:
Double
)
:
IO
[
RedisError
,
Double
]
=
{
val
command
=
RedisCommand
(
IncrByFloat
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
DoubleInput
),
DoubleOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
IncrByFloat
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
DoubleInput
),
DoubleOutput
,
executor
)
command
.
run
((
key
,
increment
))
}
...
...
@@ -385,7 +380,6 @@ trait Strings extends RedisEnvironment {
MGet
,
NonEmptyList
(
ArbitraryKeyInput
[
K
]()),
ChunkOutput
(
OptionalOutput
(
ArbitraryOutput
[
V
]())),
codec
,
executor
)
command
.
run
((
key
,
keys
.
toList
))
...
...
@@ -402,13 +396,7 @@ trait Strings extends RedisEnvironment {
*/
final
def
mSet
[
K:
Schema
,
V:
Schema
](
keyValue
:
(
K
,
V
),
keyValues
:
(
K
,
V
)*)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
MSet
,
NonEmptyList
(
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]())),
UnitOutput
,
codec
,
executor
)
RedisCommand
(
MSet
,
NonEmptyList
(
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]())),
UnitOutput
,
executor
)
command
.
run
((
keyValue
,
keyValues
.
toList
))
}
...
...
@@ -427,13 +415,7 @@ trait Strings extends RedisEnvironment {
keyValues
:
(
K
,
V
)*
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
MSetNx
,
NonEmptyList
(
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]())),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
MSetNx
,
NonEmptyList
(
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]())),
BoolOutput
,
executor
)
command
.
run
((
keyValue
,
keyValues
.
toList
))
}
...
...
@@ -457,7 +439,6 @@ trait Strings extends RedisEnvironment {
PSetEx
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
DurationMillisecondsInput
,
ArbitraryValueInput
[
V
]()),
UnitOutput
,
codec
,
executor
)
command
.
run
((
key
,
milliseconds
,
value
))
...
...
@@ -494,7 +475,7 @@ trait Strings extends RedisEnvironment {
OptionalInput
(
UpdateInput
),
OptionalInput
(
KeepTtlInput
)
)
val
command
=
RedisCommand
(
Set
,
input
,
SetOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
Set
,
input
,
SetOutput
,
executor
)
command
.
run
((
key
,
value
,
expireTime
,
update
,
keepTtl
))
}
...
...
@@ -512,7 +493,7 @@ trait Strings extends RedisEnvironment {
*/
final
def
setBit
[
K:
Schema
](
key
:
K
,
offset
:
Long
,
value
:
Boolean
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
SetBit
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
BoolInput
),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
SetBit
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
BoolInput
),
BoolOutput
,
executor
)
command
.
run
((
key
,
offset
,
value
))
}
...
...
@@ -536,7 +517,6 @@ trait Strings extends RedisEnvironment {
SetEx
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
DurationSecondsInput
,
ArbitraryValueInput
[
V
]()),
UnitOutput
,
codec
,
executor
)
command
.
run
((
key
,
expiration
,
value
))
...
...
@@ -554,7 +534,7 @@ trait Strings extends RedisEnvironment {
*/
final
def
setNx
[
K:
Schema
,
V:
Schema
](
key
:
K
,
value
:
V
)
:
IO
[
RedisError
,
Boolean
]
=
{
val
command
=
RedisCommand
(
SetNx
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]()),
BoolOutput
,
codec
,
executor
)
RedisCommand
(
SetNx
,
Tuple2
(
ArbitraryKeyInput
[
K
](),
ArbitraryValueInput
[
V
]()),
BoolOutput
,
executor
)
command
.
run
((
key
,
value
))
}
...
...
@@ -572,13 +552,7 @@ trait Strings extends RedisEnvironment {
*/
final
def
setRange
[
K:
Schema
,
V:
Schema
](
key
:
K
,
offset
:
Long
,
value
:
V
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
SetRange
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
ArbitraryValueInput
[
V
]()),
LongOutput
,
codec
,
executor
)
RedisCommand
(
SetRange
,
Tuple3
(
ArbitraryKeyInput
[
K
](),
LongInput
,
ArbitraryValueInput
[
V
]()),
LongOutput
,
executor
)
command
.
run
((
key
,
offset
,
value
))
}
...
...
@@ -591,7 +565,7 @@ trait Strings extends RedisEnvironment {
* Returns the length of the string.
*/
final
def
strLen
[
K:
Schema
](
key
:
K
)
:
IO
[
RedisError
,
Long
]
=
{
val
command
=
RedisCommand
(
StrLen
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
codec
,
executor
)
val
command
=
RedisCommand
(
StrLen
,
ArbitraryKeyInput
[
K
](),
LongOutput
,
executor
)
command
.
run
(
key
)
}
...
...
@@ -627,7 +601,6 @@ trait Strings extends RedisEnvironment {
OptionalInput
(
StralgoLcsQueryTypeInput
)
),
StrAlgoLcsOutput
,
codec
,
executor
)
redisCommand
.
run
((
command
.
stringify
,
keyA
,
keyB
,
lcsQueryType
))
...
...
redis/src/main/scala/zio/redis/codecs/StringUtf8Codec.scala
浏览文件 @
1a89cdbb
...
...
@@ -19,46 +19,38 @@ package zio.redis.codecs
import
zio.redis.RedisError.CodecError
import
zio.schema.Schema
import
zio.schema.StandardType.
{
DoubleType
,
IntType
,
LongType
}
import
zio.schema.codec.BinaryCodec.
{
Binary
Decoder
,
BinaryEncoder
,
Binary
StreamDecoder
,
BinaryStreamEncoder
}
import
zio.schema.codec.BinaryCodec.
{
BinaryStreamDecoder
,
BinaryStreamEncoder
}
import
zio.schema.codec.
{
BinaryCodec
,
DecodeError
}
import
zio.stream.ZPipeline
import
zio.
{
Cause
,
Chunk
,
ZIO
}
import
java.nio.charset.StandardCharsets
private
[
redis
]
object
StringUtf8Codec
extends
BinaryCodec
{
private
[
redis
]
object
StringUtf8Codec
{
def
encoderFor
[
A
](
schema
:
Schema
[
A
])
:
BinaryEncoder
[
A
]
=
new
BinaryEncoder
[
A
]
{
override
def
encode
(
value
:
A
)
:
Chunk
[
Byte
]
=
schema
match
{
case
Schema
.
Primitive
(
_
,
_
)
=>
Chunk
.
fromArray
(
value
.
toString
.
getBytes
(
StandardCharsets
.
UTF_8
))
case
_
=>
throw
CodecError
(
"the codec support only primitives"
)
}
override
def
streamEncoder
:
BinaryStreamEncoder
[
A
]
=
ZPipeline
.
mapChunks
(
_
.
flatMap
(
encode
))
}
implicit
def
codec
[
A
](
implicit
schema
:
Schema
[
A
])
:
BinaryCodec
[
A
]
=
new
BinaryCodec
[
A
]
{
override
def
encode
(
value
:
A
)
:
Chunk
[
Byte
]
=
schema
match
{
case
Schema
.
Primitive
(
_
,
_
)
=>
Chunk
.
fromArray
(
value
.
toString
.
getBytes
(
StandardCharsets
.
UTF_8
))
case
_
=>
throw
CodecError
(
"the codec support only primitives"
)
}
def
decoderFor
[
A
](
schema
:
Schema
[
A
])
:
BinaryDe
coder
[
A
]
=
new
BinaryDecoder
[
A
]
{
override
def
streamEncoder
:
BinaryStreamEn
coder
[
A
]
=
ZPipeline
.
mapChunks
(
_
.
flatMap
(
encode
))
override
def
decode
(
chunk
:
Chunk
[
Byte
])
:
Either
[
DecodeError
,
A
]
=
{
def
utf8String
=
new
String
(
chunk
.
toArray
,
StandardCharsets
.
UTF_8
)
override
def
decode
(
chunk
:
Chunk
[
Byte
])
:
Either
[
DecodeError
,
A
]
=
{
def
utf8String
=
new
String
(
chunk
.
toArray
,
StandardCharsets
.
UTF_8
)
schema
match
{
case
Schema
.
Primitive
(
IntType
,
_
)
=>
Right
(
utf8String
.
toInt
.
asInstanceOf
[
A
])
case
Schema
.
Primitive
(
LongType
,
_
)
=>
Right
(
utf8String
.
toLong
.
asInstanceOf
[
A
])
case
Schema
.
Primitive
(
DoubleType
,
_
)
=>
Right
(
utf8String
.
toDouble
.
asInstanceOf
[
A
])
case
Schema
.
Primitive
(
_
,
_
)
=>
Right
(
utf8String
.
asInstanceOf
[
A
])
case
_
=>
Left
(
DecodeError
.
ReadError
(
Cause
.
empty
,
"the codec support only primitives"
))
}
schema
match
{
case
Schema
.
Primitive
(
IntType
,
_
)
=>
Right
(
utf8String
.
toInt
.
asInstanceOf
[
A
])
case
Schema
.
Primitive
(
LongType
,
_
)
=>
Right
(
utf8String
.
toLong
.
asInstanceOf
[
A
])
case
Schema
.
Primitive
(
DoubleType
,
_
)
=>
Right
(
utf8String
.
toDouble
.
asInstanceOf
[
A
])
case
Schema
.
Primitive
(
_
,
_
)
=>
Right
(
utf8String
.
asInstanceOf
[
A
])
case
_
=>
Left
(
DecodeError
.
ReadError
(
Cause
.
empty
,
"the codec support only primitives"
))
}
override
def
streamDecoder
:
BinaryStreamDecoder
[
A
]
=
ZPipeline
.
mapChunksZIO
(
chunk
=>
ZIO
.
fromEither
(
decode
(
chunk
).
map
(
Chunk
(
_
))))
}
override
def
streamDecoder
:
BinaryStreamDecoder
[
A
]
=
ZPipeline
.
mapChunksZIO
(
chunk
=>
ZIO
.
fromEither
(
decode
(
chunk
).
map
(
Chunk
(
_
))))
}
}
redis/src/test/scala/zio/redis/ApiSpec.scala
浏览文件 @
1a89cdbb
package
zio.redis
import
zio._
import
zio.redis.codecs.ProtobufCodecSupplier
import
zio.test.TestAspect._
import
zio.test._
...
...
@@ -37,7 +38,7 @@ object ApiSpec
).
provideShared
(
RedisExecutor
.
local
,
Redis
.
layer
,
ZLayer
.
succeed
(
codec
)
ZLayer
.
succeed
(
ProtobufCodecSupplier
)
)
private
val
clusterSuite
=
...
...
@@ -57,7 +58,7 @@ object ApiSpec
).
provideShared
(
ClusterExecutor
.
layer
,
Redis
.
layer
,
ZLayer
.
succeed
(
codec
),
ZLayer
.
succeed
(
ProtobufCodecSupplier
),
ZLayer
.
succeed
(
RedisClusterConfig
(
Chunk
(
RedisUri
(
"localhost"
,
5000
))))
).
filterNotTags
(
_
.
contains
(
BaseSpec
.
ClusterExecutorUnsupported
))
.
getOrElse
(
Spec
.
empty
)
...
...
redis/src/test/scala/zio/redis/BaseSpec.scala
浏览文件 @
1a89cdbb
package
zio.redis
import
zio._
import
zio.schema.Schema
import
zio.schema.codec.
{
BinaryCodec
,
ProtobufCodec
}
import
zio.test.TestAspect.
{
fibers
,
silentLogging
,
tag
,
timeout
}
import
zio.test._
...
...
@@ -8,7 +9,7 @@ import zio.test._
import
java.util.UUID
trait
BaseSpec
extends
ZIOSpecDefault
{
implicit
val
codec
:
BinaryCodec
=
P
rotobufCodec
implicit
def
summonCodec
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
ProtobufCodec
.
p
rotobufCodec
override
def
aspects
:
Chunk
[
TestAspectAtLeastR
[
Live
]]
=
Chunk
(
fibers
,
silentLogging
,
timeout
(
10.
seconds
))
...
...
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala
浏览文件 @
1a89cdbb
package
zio.redis
import
zio.redis.codecs.
CRC16
import
zio.redis.codecs.
{
CRC16
,
ProtobufCodecSupplier
}
import
zio.redis.options.Cluster.
{
Slot
,
SlotsAmount
}
import
zio.test._
import
zio.
{
Chunk
,
Layer
,
ZIO
,
ZLayer
,
durationInt
}
...
...
@@ -69,7 +69,7 @@ object ClusterExecutorSpec extends BaseSpec {
ZLayer
.
make
[
Redis
](
ZLayer
.
succeed
(
RedisConfig
(
uri
.
host
,
uri
.
port
)),
RedisExecutor
.
layer
,
ZLayer
.
succeed
(
codec
),
ZLayer
.
succeed
(
ProtobufCodecSupplier
),
Redis
.
layer
)
...
...
@@ -79,7 +79,7 @@ object ClusterExecutorSpec extends BaseSpec {
ZLayer
.
make
[
Redis
](
ZLayer
.
succeed
(
RedisClusterConfig
(
Chunk
(
address1
,
address2
))),
ClusterExecutor
.
layer
.
orDie
,
ZLayer
.
succeed
(
codec
),
ZLayer
.
succeed
(
ProtobufCodecSupplier
),
Redis
.
layer
)
}
...
...
redis/src/test/scala/zio/redis/KeysSpec.scala
浏览文件 @
1a89cdbb
...
...
@@ -2,7 +2,7 @@ package zio.redis
import
zio._
import
zio.redis.RedisError.ProtocolError
import
zio.
schema.codec.
{
BinaryCodec
,
ProtobufCodec
}
import
zio.
redis.codecs.ProtobufCodecSupplier
import
zio.test.Assertion.
{
exists
=>
_
,
_
}
import
zio.test.TestAspect.
{
restore
=>
_
,
_
}
import
zio.test._
...
...
@@ -484,7 +484,7 @@ object KeysSpec {
ZLayer
.
succeed
(
RedisConfig
(
"localhost"
,
6380
)),
RedisConnectionLive
.
layer
,
SingleNodeExecutor
.
layer
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
),
ZLayer
.
succeed
[
CodecSupplier
](
ProtobufCodecSupplier
),
Redis
.
layer
)
.
fresh
...
...
redis/src/test/scala/zio/redis/codecs/ProtobufCodecSupplier.scala
0 → 100644
浏览文件 @
1a89cdbb
package
zio.redis.codecs
import
zio.redis.CodecSupplier
import
zio.schema.Schema
import
zio.schema.codec.
{
BinaryCodec
,
ProtobufCodec
}
object
ProtobufCodecSupplier
extends
CodecSupplier
{
implicit
def
get
[
A:
Schema
]
:
BinaryCodec
[
A
]
=
ProtobufCodec
.
protobufCodec
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录