Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Zio Redis
提交
4242806b
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 搜索 >>
未验证
提交
4242806b
编写于
2月 08, 2023
作者:
D
Dragutin Marjanović
提交者:
GitHub
2月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Scripting API (scriptDebug, scriptFlush, scriptKill) (#750)
上级
519d5b14
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
171 addition
and
15 deletion
+171
-15
README.md
README.md
+1
-1
benchmarks/src/main/scala/zio/redis/benchmarks/BenchmarkRuntime.scala
...rc/main/scala/zio/redis/benchmarks/BenchmarkRuntime.scala
+1
-1
docs/index.md
docs/index.md
+1
-1
example/src/main/scala/example/Main.scala
example/src/main/scala/example/Main.scala
+2
-2
redis/src/main/scala/zio/redis/ClusterExecutor.scala
redis/src/main/scala/zio/redis/ClusterExecutor.scala
+1
-1
redis/src/main/scala/zio/redis/Input.scala
redis/src/main/scala/zio/redis/Input.scala
+5
-0
redis/src/main/scala/zio/redis/Redis.scala
redis/src/main/scala/zio/redis/Redis.scala
+9
-4
redis/src/main/scala/zio/redis/api/Scripting.scala
redis/src/main/scala/zio/redis/api/Scripting.scala
+41
-0
redis/src/main/scala/zio/redis/options/Scripting.scala
redis/src/main/scala/zio/redis/options/Scripting.scala
+13
-0
redis/src/test/scala/zio/redis/ApiSpec.scala
redis/src/test/scala/zio/redis/ApiSpec.scala
+2
-2
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala
+2
-2
redis/src/test/scala/zio/redis/InputSpec.scala
redis/src/test/scala/zio/redis/InputSpec.scala
+29
-0
redis/src/test/scala/zio/redis/KeysSpec.scala
redis/src/test/scala/zio/redis/KeysSpec.scala
+1
-1
redis/src/test/scala/zio/redis/ScriptingSpec.scala
redis/src/test/scala/zio/redis/ScriptingSpec.scala
+63
-0
未找到文件。
README.md
浏览文件 @
4242806b
...
...
@@ -61,7 +61,7 @@ object ZIORedisExample extends ZIOAppDefault {
}
yield
()
override
def
run
=
myApp
.
provide
(
Redis
Live
.
layer
,
Redis
.
layer
,
RedisExecutor
.
layer
,
ZLayer
.
succeed
(
RedisConfig
.
Default
),
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
)
...
...
benchmarks/src/main/scala/zio/redis/benchmarks/BenchmarkRuntime.scala
浏览文件 @
4242806b
...
...
@@ -36,6 +36,6 @@ object BenchmarkRuntime {
ZLayer
.
make
[
Redis
](
RedisExecutor
.
local
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
),
Redis
Live
.
layer
Redis
.
layer
)
}
docs/index.md
浏览文件 @
4242806b
...
...
@@ -61,7 +61,7 @@ object ZIORedisExample extends ZIOAppDefault {
} yield ()
override def run = myApp.provide(
Redis
Live
.layer,
Redis.layer,
RedisExecutor.layer,
ZLayer.succeed(RedisConfig.Default),
ZLayer.succeed[BinaryCodec](ProtobufCodec)
...
...
example/src/main/scala/example/Main.scala
浏览文件 @
4242806b
...
...
@@ -21,7 +21,7 @@ import example.config.AppConfig
import
sttp.client3.httpclient.zio.HttpClientZioBackend
import
zhttp.service.Server
import
zio._
import
zio.redis.
{
Redis
Executor
,
RedisLive
}
import
zio.redis.
{
Redis
,
RedisExecutor
}
import
zio.schema.codec.
{
BinaryCodec
,
ProtobufCodec
}
object
Main
extends
ZIOAppDefault
{
...
...
@@ -33,7 +33,7 @@ object Main extends ZIOAppDefault {
ContributorsCache
.
layer
,
HttpClientZioBackend
.
layer
(),
RedisExecutor
.
layer
,
Redis
Live
.
layer
,
Redis
.
layer
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
)
)
.
exitCode
...
...
redis/src/main/scala/zio/redis/ClusterExecutor.scala
浏览文件 @
4242806b
...
...
@@ -152,7 +152,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
redisLayer
=
executorLayer
++
codecLayer
>>>
Redis
Live
.
layer
val
redisLayer
=
executorLayer
++
codecLayer
>>>
Redis
.
layer
for
{
closableScope
<-
Scope
.
make
layer
<-
closableScope
.
extend
[
Any
](
redisLayer
.
memoize
)
...
...
redis/src/main/scala/zio/redis/Input.scala
浏览文件 @
4242806b
...
...
@@ -597,6 +597,11 @@ object Input {
Chunk
.
single
(
encodeString
(
data
.
stringify
))
}
case
object
ScriptFlushInput
extends
Input
[
FlushMode
]
{
def
encode
(
data
:
FlushMode
)(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
BulkString
]
=
Chunk
.
single
(
encodeString
(
data
.
stringify
))
}
case
object
WithScoresInput
extends
Input
[
WithScores
]
{
def
encode
(
data
:
WithScores
)(
implicit
codec
:
BinaryCodec
)
:
Chunk
[
RespValue.BulkString
]
=
Chunk
.
single
(
encodeString
(
data
.
stringify
))
...
...
redis/src/main/scala/zio/redis/Redis.scala
浏览文件 @
4242806b
...
...
@@ -36,9 +36,14 @@ trait Redis
def
executor
:
RedisExecutor
}
final
case
class
RedisLive
(
codec
:
BinaryCodec
,
executor
:
RedisExecutor
)
extends
Redis
object
RedisLive
{
object
Redis
{
lazy
val
layer
:
URLayer
[
RedisExecutor
with
BinaryCodec
,
Redis
]
=
ZLayer
.
fromFunction
(
RedisLive
.
apply
_
)
ZLayer
{
for
{
executor
<-
ZIO
.
service
[
RedisExecutor
]
codec
<-
ZIO
.
service
[
BinaryCodec
]
}
yield
Live
(
codec
,
executor
)
}
private
final
case
class
Live
(
codec
:
BinaryCodec
,
executor
:
RedisExecutor
)
extends
Redis
}
redis/src/main/scala/zio/redis/api/Scripting.scala
浏览文件 @
4242806b
...
...
@@ -74,6 +74,19 @@ trait Scripting extends RedisEnvironment {
}
}
/**
* Set the debug mode for executed scripts.
*
* @param mode
* mode in which scripts debug is going to work ["YES", "SYNC", "NO"]
* @return
* the Unit value.
*/
def
scriptDebug
(
mode
:
DebugMode
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ScriptDebug
,
ScriptDebugInput
,
UnitOutput
,
codec
,
executor
)
command
.
run
(
mode
)
}
/**
* Checks existence of the scripts in the script cache.
*
...
...
@@ -90,6 +103,31 @@ trait Scripting extends RedisEnvironment {
command
.
run
((
sha1
,
sha1s
.
toList
))
}
/**
* Remove all the scripts from the script cache.
*
* @param mode
* mode in which script flush is going to be executed ["ASYNC", "SYNC"] Note: "SYNC" mode is used by default (if no
* mode is provided)
* @return
* the Unit value.
*/
def
scriptFlush
(
mode
:
Option
[
FlushMode
]
=
None
)
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ScriptFlush
,
OptionalInput
(
ScriptFlushInput
),
UnitOutput
,
codec
,
executor
)
command
.
run
(
mode
)
}
/**
* Kill the currently executing EVAL script, assuming no write operation was yet performed by the script.
*
* @return
* the Unit value.
*/
def
scriptKill
:
IO
[
RedisError
,
Unit
]
=
{
val
command
=
RedisCommand
(
ScriptKill
,
NoInput
,
UnitOutput
,
codec
,
executor
)
command
.
run
(())
}
/**
* Loads a script into the scripts cache. After the script is loaded into the script cache it could be evaluated using
* the [[zio.redis.api.Scripting.evalSha]] method.
...
...
@@ -108,6 +146,9 @@ trait Scripting extends RedisEnvironment {
private
[
redis
]
object
Scripting
{
final
val
Eval
=
"EVAL"
final
val
EvalSha
=
"EVALSHA"
final
val
ScriptDebug
=
"SCRIPT DEBUG"
final
val
ScriptExists
=
"SCRIPT EXISTS"
final
val
ScriptFlush
=
"SCRIPT FLUSH"
final
val
ScriptKill
=
"SCRIPT KILL"
final
val
ScriptLoad
=
"SCRIPT LOAD"
}
redis/src/main/scala/zio/redis/options/Scripting.scala
浏览文件 @
4242806b
...
...
@@ -31,4 +31,17 @@ trait Scripting {
case
object
Sync
extends
DebugMode
case
object
No
extends
DebugMode
}
sealed
trait
FlushMode
{
self
=>
private
[
redis
]
final
def
stringify
:
String
=
self
match
{
case
FlushMode
.
Async
=>
"ASYNC"
case
FlushMode
.
Sync
=>
"SYNC"
}
}
object
FlushMode
{
case
object
Async
extends
FlushMode
case
object
Sync
extends
FlushMode
}
}
redis/src/test/scala/zio/redis/ApiSpec.scala
浏览文件 @
4242806b
...
...
@@ -40,7 +40,7 @@ object ApiSpec
scriptingSpec
)
val
Layer
:
Layer
[
Any
,
Redis
]
=
ZLayer
.
make
[
Redis
](
RedisExecutor
.
local
.
orDie
,
ZLayer
.
succeed
(
codec
),
Redis
Live
.
layer
)
val
Layer
:
Layer
[
Any
,
Redis
]
=
ZLayer
.
make
[
Redis
](
RedisExecutor
.
local
.
orDie
,
ZLayer
.
succeed
(
codec
),
Redis
.
layer
)
}
private
object
Cluster
{
...
...
@@ -65,7 +65,7 @@ object ApiSpec
ZLayer
.
succeed
(
RedisClusterConfig
(
Chunk
(
RedisUri
(
"localhost"
,
5000
)))),
ClusterExecutor
.
layer
,
ZLayer
.
succeed
(
codec
),
Redis
Live
.
layer
Redis
.
layer
)
}
...
...
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala
浏览文件 @
4242806b
...
...
@@ -70,7 +70,7 @@ object ClusterExecutorSpec extends BaseSpec {
ZLayer
.
succeed
(
RedisConfig
(
uri
.
host
,
uri
.
port
)),
RedisExecutor
.
layer
,
ZLayer
.
succeed
(
codec
),
Redis
Live
.
layer
Redis
.
layer
)
private
val
ClusterLayer
:
Layer
[
Any
,
Redis
]
=
{
...
...
@@ -80,7 +80,7 @@ object ClusterExecutorSpec extends BaseSpec {
ZLayer
.
succeed
(
RedisClusterConfig
(
Chunk
(
address1
,
address2
))),
ClusterExecutor
.
layer
.
orDie
,
ZLayer
.
succeed
(
codec
),
Redis
Live
.
layer
Redis
.
layer
)
}
}
redis/src/test/scala/zio/redis/InputSpec.scala
浏览文件 @
4242806b
...
...
@@ -817,6 +817,35 @@ object InputSpec extends BaseSpec {
}
yield
assert
(
result
)(
equalTo
(
respArgs
(
"4.2"
,
"5.2"
)))
}
),
suite
(
"ScriptDebug"
)(
test
(
"yes"
)
{
for
{
result
<-
ZIO
.
attempt
(
ScriptDebugInput
.
encode
(
DebugMode
.
Yes
))
}
yield
assert
(
result
)(
equalTo
(
respArgs
(
"YES"
)))
},
test
(
"sync"
)
{
for
{
result
<-
ZIO
.
attempt
(
ScriptDebugInput
.
encode
(
DebugMode
.
Sync
))
}
yield
assert
(
result
)(
equalTo
(
respArgs
(
"SYNC"
)))
},
test
(
"no"
)
{
for
{
result
<-
ZIO
.
attempt
(
ScriptDebugInput
.
encode
(
DebugMode
.
No
))
}
yield
assert
(
result
)(
equalTo
(
respArgs
(
"NO"
)))
}
),
suite
(
"ScriptFlush"
)(
test
(
"asynchronous"
)
{
for
{
result
<-
ZIO
.
attempt
(
ScriptFlushInput
.
encode
(
FlushMode
.
Async
))
}
yield
assert
(
result
)(
equalTo
(
respArgs
(
"ASYNC"
)))
},
test
(
"synchronous"
)
{
for
{
result
<-
ZIO
.
attempt
(
ScriptFlushInput
.
encode
(
FlushMode
.
Sync
))
}
yield
assert
(
result
)(
equalTo
(
respArgs
(
"SYNC"
)))
}
),
suite
(
"String"
)(
test
(
"non-empty value"
)
{
for
{
...
...
redis/src/test/scala/zio/redis/KeysSpec.scala
浏览文件 @
4242806b
...
...
@@ -465,7 +465,7 @@ object KeysSpec {
RedisConnectionLive
.
layer
,
SingleNodeExecutor
.
layer
,
ZLayer
.
succeed
[
BinaryCodec
](
ProtobufCodec
),
Redis
Live
.
layer
Redis
.
layer
)
.
fresh
}
redis/src/test/scala/zio/redis/ScriptingSpec.scala
浏览文件 @
4242806b
...
...
@@ -163,6 +163,26 @@ trait ScriptingSpec extends BaseSpec {
}
yield
assert
(
res
)(
isLeft
(
isSubtype
[
NoScript
](
hasField
(
"message"
,
_
.
message
,
equalTo
(
error
)))))
}
),
suite
(
"scriptDebug"
)(
test
(
"enable non-blocking asynchronous debugging"
)
{
for
{
redis
<-
ZIO
.
service
[
Redis
]
res
<-
redis
.
scriptDebug
(
DebugMode
.
Yes
)
}
yield
assert
(
res
)(
isUnit
)
},
test
(
"enable blocking synchronous debugging"
)
{
for
{
redis
<-
ZIO
.
service
[
Redis
]
res
<-
redis
.
scriptDebug
(
DebugMode
.
Sync
)
}
yield
assert
(
res
)(
isUnit
)
},
test
(
"disable debug mode"
)
{
for
{
redis
<-
ZIO
.
service
[
Redis
]
res
<-
redis
.
scriptDebug
(
DebugMode
.
No
)
}
yield
assert
(
res
)(
isUnit
)
}
),
suite
(
"scriptExists"
)(
test
(
"return true if scripts are found in the cache"
)
{
val
lua1
=
"""return "1""""
...
...
@@ -183,6 +203,49 @@ trait ScriptingSpec extends BaseSpec {
}
yield
assertTrue
(
res
==
Chunk
(
false
,
false
))
}
),
suite
(
"scriptFlush"
)(
test
(
"flush scripts in default mode"
)
{
val
lua1
=
"""return "1""""
val
lua2
=
"""return "2""""
for
{
redis
<-
ZIO
.
service
[
Redis
]
sha1
<-
redis
.
scriptLoad
(
lua1
)
sha2
<-
redis
.
scriptLoad
(
lua2
)
_
<-
redis
.
scriptFlush
()
res
<-
redis
.
scriptExists
(
sha1
,
sha2
)
}
yield
assertTrue
(
res
==
Chunk
(
false
,
false
))
},
test
(
"flush scripts in SYNC mode"
)
{
val
lua1
=
"""return "1""""
val
lua2
=
"""return "2""""
for
{
redis
<-
ZIO
.
service
[
Redis
]
sha1
<-
redis
.
scriptLoad
(
lua1
)
sha2
<-
redis
.
scriptLoad
(
lua2
)
_
<-
redis
.
scriptFlush
(
mode
=
Some
(
FlushMode
.
Sync
))
res
<-
redis
.
scriptExists
(
sha1
,
sha2
)
}
yield
assertTrue
(
res
==
Chunk
(
false
,
false
))
},
test
(
"flush scripts in ASYNC mode"
)
{
val
lua1
=
"""return "1""""
val
lua2
=
"""return "2""""
for
{
redis
<-
ZIO
.
service
[
Redis
]
sha1
<-
redis
.
scriptLoad
(
lua1
)
sha2
<-
redis
.
scriptLoad
(
lua2
)
_
<-
redis
.
scriptFlush
(
mode
=
Some
(
FlushMode
.
Async
))
res
<-
redis
.
scriptExists
(
sha1
,
sha2
)
}
yield
assertTrue
(
res
==
Chunk
(
false
,
false
))
}
),
suite
(
"scriptKill"
)(
test
(
"return NOTBUSY when there is no scripts in execution"
)
{
for
{
redis
<-
ZIO
.
service
[
Redis
]
res
<-
redis
.
scriptKill
.
either
}
yield
assert
(
res
)(
isLeft
(
isSubtype
[
RedisError.NotBusy
](
anything
)))
}
),
suite
(
"scriptLoad"
)(
test
(
"return OK"
)
{
val
lua
=
"""return "1""""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录