Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Zio Redis
提交
348a2ba6
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 搜索 >>
未验证
提交
348a2ba6
编写于
3月 16, 2023
作者:
A
Anatoly Sergeev
提交者:
GitHub
3月 16, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add default slot to cluster (#754)
上级
fc43d270
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
40 addition
and
31 deletion
+40
-31
redis/src/main/scala/zio/redis/ClusterExecutor.scala
redis/src/main/scala/zio/redis/ClusterExecutor.scala
+3
-7
redis/src/main/scala/zio/redis/RespArgument.scala
redis/src/main/scala/zio/redis/RespArgument.scala
+7
-0
redis/src/main/scala/zio/redis/RespValue.scala
redis/src/main/scala/zio/redis/RespValue.scala
+0
-7
redis/src/main/scala/zio/redis/options/Cluster.scala
redis/src/main/scala/zio/redis/options/Cluster.scala
+4
-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/BaseSpec.scala
redis/src/test/scala/zio/redis/BaseSpec.scala
+1
-1
redis/src/test/scala/zio/redis/RespArgumentSpec.scala
redis/src/test/scala/zio/redis/RespArgumentSpec.scala
+23
-0
redis/src/test/scala/zio/redis/RespValueSpec.scala
redis/src/test/scala/zio/redis/RespValueSpec.scala
+0
-14
未找到文件。
redis/src/main/scala/zio/redis/ClusterExecutor.scala
浏览文件 @
348a2ba6
...
...
@@ -58,8 +58,8 @@ final case class ClusterExecutor(
}
for
{
key
<-
ZIO
.
attempt
(
command
.
args
(
1
).
value
).
orElseFail
(
CusterKeyError
)
keySlot
=
Slot
((
key
.
asCRC16
%
SlotsAmount
).
toLong
)
key
Opt
<-
ZIO
.
succeed
(
command
.
args
.
collectFirst
{
case
key
:
RespArgument.Key
=>
key
}
)
keySlot
=
keyOpt
.
fold
(
Slot
.
Default
)(
key
=>
Slot
((
key
.
asCRC16
&
(
SlotsAmount
-
1
)).
toLong
)
)
result
<-
executeSafe
(
keySlot
)
}
yield
result
}
...
...
@@ -165,12 +165,8 @@ object ClusterExecutor {
for
(
i
<-
p
.
slotRange
.
start
to
p
.
slotRange
.
end
)
yield
Slot
(
i
)
->
p
.
master
.
address
}.
toMap
private
final
val
CusterKeyError
=
RedisError
.
ProtocolError
(
"Key doesn't found. No way to dispatch this command to Redis Cluster"
)
private
final
val
CusterKeyExecutorError
=
RedisError
.
IOError
(
new
IOException
(
"Executor for key doesn't found. No way to dispatch this command to Redis Cluster"
)
)
RedisError
.
IOError
(
new
IOException
(
"Executor doesn't found. No way to dispatch this command to Redis Cluster"
))
private
final
val
CusterConnectionError
=
RedisError
.
IOError
(
new
IOException
(
"The connection to cluster has been failed. Can't reach a single startup node."
))
}
redis/src/main/scala/zio/redis/RespArgument.scala
浏览文件 @
348a2ba6
...
...
@@ -18,6 +18,7 @@ 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
...
...
@@ -48,6 +49,12 @@ object RespArgument {
final
case
class
Key
(
bytes
:
Chunk
[
Byte
])
extends
RespArgument
{
lazy
val
value
:
BulkString
=
RespValue
.
BulkString
(
bytes
)
lazy
val
asCRC16
:
Int
=
{
val
betweenBraces
=
bytes
.
dropWhile
(
b
=>
b
!=
'{'
).
drop
(
1
).
takeWhile
(
b
=>
b
!=
'}'
)
val
key
=
if
(
betweenBraces
.
isEmpty
)
bytes
else
betweenBraces
CRC16
.
get
(
key
)
}
}
object
Key
{
...
...
redis/src/main/scala/zio/redis/RespValue.scala
浏览文件 @
348a2ba6
...
...
@@ -17,7 +17,6 @@
package
zio.redis
import
zio._
import
zio.redis.codecs.CRC16
import
zio.redis.options.Cluster.Slot
import
zio.stream._
...
...
@@ -75,12 +74,6 @@ object RespValue {
private
[
redis
]
def
asString
:
String
=
decode
(
value
)
private
[
redis
]
def
asLong
:
Long
=
internal
.
unsafeReadLong
(
asString
,
0
)
private
[
redis
]
def
asCRC16
:
Int
=
{
val
betweenBraces
=
value
.
dropWhile
(
b
=>
b
!=
'{'
).
drop
(
1
).
takeWhile
(
b
=>
b
!=
'}'
)
val
key
=
if
(
betweenBraces
.
isEmpty
)
value
else
betweenBraces
CRC16
.
get
(
key
)
}
}
final
case
class
Array
(
values
:
Chunk
[
RespValue
])
extends
RespValue
...
...
redis/src/main/scala/zio/redis/options/Cluster.scala
浏览文件 @
348a2ba6
...
...
@@ -38,6 +38,10 @@ object Cluster {
final
case
class
Slot
(
number
:
Long
)
extends
AnyVal
object
Slot
{
val
Default
:
Slot
=
Slot
(
1
)
}
final
case
class
Node
(
id
:
String
,
address
:
RedisUri
)
final
case
class
SlotRange
(
start
:
Long
,
end
:
Long
)
{
...
...
redis/src/test/scala/zio/redis/ApiSpec.scala
浏览文件 @
348a2ba6
...
...
@@ -51,8 +51,8 @@ object ApiSpec
sortedSetsSuite
,
hyperLogLogSuite
,
geoSuite
,
streamsSuite
@@
clusterExecutorUnsupported
,
scriptingSpec
@@
clusterExecutorUnsupported
,
streamsSuite
,
scriptingSpec
,
clusterSpec
).
provideShared
(
ClusterExecutor
.
layer
,
...
...
redis/src/test/scala/zio/redis/BaseSpec.scala
浏览文件 @
348a2ba6
...
...
@@ -27,7 +27,7 @@ trait BaseSpec extends ZIOSpecDefault {
/* TODO
* We can try to support the most unsupported commands for cluster with:
* - default connection for commands without a key and for multiple key commands with
* -
[DONE]
default connection for commands without a key and for multiple key commands with
* the limitation that all keys have to be in the same slot
* - fork/join approach for commands that operate on keys with different slots
*/
...
...
redis/src/test/scala/zio/redis/RespArgumentSpec.scala
0 → 100644
浏览文件 @
348a2ba6
package
zio.redis
import
zio.test._
object
RespArgumentSpec
extends
BaseSpec
{
def
spec
:
Spec
[
Any
,
RedisError.ProtocolError
]
=
suite
(
"RespArgument"
)(
suite
(
"BulkString.asCRC16"
)(
test
(
"key without braces"
)
{
val
key
=
RespArgument
.
Key
(
"hello world"
)
assertTrue
(
15332
==
key
.
asCRC16
)
},
test
(
"key between braces"
)
{
val
key
=
RespArgument
.
Key
(
"hello{key1}wor}ld"
)
assertTrue
(
41957
==
key
.
asCRC16
)
},
test
(
"empty key between braces"
)
{
val
key
=
RespArgument
.
Key
(
"hello{}world"
)
assertTrue
(
40253
==
key
.
asCRC16
)
}
)
)
}
redis/src/test/scala/zio/redis/RespValueSpec.scala
浏览文件 @
348a2ba6
...
...
@@ -42,20 +42,6 @@ object RespValueSpec extends BaseSpec {
.
runCollect
.
map
(
assert
(
_
)(
equalTo
(
values
)))
}
),
suite
(
"BulkString.asCRC16"
)(
test
(
"key without braces"
)
{
val
str
=
RespValue
.
bulkString
(
"hello world"
)
assertTrue
(
15332
==
str
.
asCRC16
)
},
test
(
"key between braces"
)
{
val
str
=
RespValue
.
bulkString
(
"hello{key1}wor}ld"
)
assertTrue
(
41957
==
str
.
asCRC16
)
},
test
(
"empty key between braces"
)
{
val
str
=
RespValue
.
bulkString
(
"hello{}world"
)
assertTrue
(
40253
==
str
.
asCRC16
)
}
)
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录