Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Zio Redis
提交
ce380903
Z
Zio Redis
项目概览
梦境迷离
/
Zio Redis
10 个月 前同步成功
通知
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 搜索 >>
未验证
提交
ce380903
编写于
1月 01, 2021
作者:
D
Dejan Mijić
提交者:
GitHub
1月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve array serialization (#265)
上级
e259e911
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
31 deletion
+82
-31
benchmarks/src/main/scala/zio/redis/SMembersBenchmarks.scala
benchmarks/src/main/scala/zio/redis/SMembersBenchmarks.scala
+55
-0
redis/src/main/scala/zio/redis/Output.scala
redis/src/main/scala/zio/redis/Output.scala
+8
-8
redis/src/main/scala/zio/redis/RedisExecutor.scala
redis/src/main/scala/zio/redis/RedisExecutor.scala
+1
-1
redis/src/main/scala/zio/redis/RespValue.scala
redis/src/main/scala/zio/redis/RespValue.scala
+17
-21
redis/src/test/scala/zio/redis/RespValueSpec.scala
redis/src/test/scala/zio/redis/RespValueSpec.scala
+1
-1
未找到文件。
benchmarks/src/main/scala/zio/redis/SMembersBenchmarks.scala
0 → 100644
浏览文件 @
ce380903
package
zio.redis
import
java.util.concurrent.TimeUnit
import
org.openjdk.jmh.annotations._
import
zio.ZIO
@State
(
Scope
.
Thread
)
@BenchmarkMode
(
Array
(
Mode
.
Throughput
))
@OutputTimeUnit
(
TimeUnit
.
SECONDS
)
@Measurement
(
iterations
=
15
)
@Warmup
(
iterations
=
15
)
@Fork
(
2
)
class
SMembersBenchmarks
extends
BenchmarkRuntime
{
@Param
(
Array
(
"500"
))
private
var
size
:
Int
=
_
private
var
items
:
List
[
String
]
=
_
private
val
key
=
"test-set"
@Setup
(
Level
.
Trial
)
def
setup
()
:
Unit
=
{
items
=
(
0
to
size
).
toList
.
map
(
_
.
toString
)
zioUnsafeRun
(
sAdd
(
key
,
items
.
head
,
items
.
tail
:
_
*
).
unit
)
}
@Benchmark
def
laserdisc
()
:
Unit
=
{
import
_root_.laserdisc.fs2._
import
_root_.laserdisc.
{
all
=>
cmd
,
_
}
import
cats.instances.list._
import
cats.syntax.foldable._
unsafeRun
[
LaserDiscClient
](
c
=>
items
.
traverse_
(
_
=>
c
.
send
(
cmd
.
smembers
(
Key
.
unsafeFrom
(
key
)))))
}
@Benchmark
def
rediculous
()
:
Unit
=
{
import
cats.implicits._
import
io.chrisdavenport.rediculous._
unsafeRun
[
RediculousClient
](
c
=>
items
.
traverse_
(
_
=>
RedisCommands
.
smembers
[
RedisIO
](
key
).
run
(
c
)))
}
@Benchmark
def
redis4cats
()
:
Unit
=
{
import
cats.instances.list._
import
cats.syntax.foldable._
unsafeRun
[
Redis4CatsClient
[
String
]](
c
=>
items
.
traverse_
(
_
=>
c
.
sMembers
(
key
)))
}
@Benchmark
def
zio
()
:
Unit
=
zioUnsafeRun
(
ZIO
.
foreach_
(
items
)(
_
=>
sMembers
(
key
)))
}
redis/src/main/scala/zio/redis/Output.scala
浏览文件 @
ce380903
...
...
@@ -36,14 +36,6 @@ object Output {
import
RedisError._
private
def
decodeDouble
(
bytes
:
Chunk
[
Byte
])
:
Double
=
{
val
text
=
RespValue
.
decodeString
(
bytes
)
try
text
.
toDouble
catch
{
case
_:
NumberFormatException
=>
throw
ProtocolError
(
s
"'$text' isn't a double."
)
}
}
case
object
BoolOutput
extends
Output
[
Boolean
]
{
protected
def
tryDecode
(
respValue
:
RespValue
)
:
Boolean
=
respValue
match
{
...
...
@@ -402,4 +394,12 @@ object Output {
case
other
=>
throw
ProtocolError
(
s
"$other isn't a valid set response"
)
}
}
private
def
decodeDouble
(
bytes
:
Chunk
[
Byte
])
:
Double
=
{
val
text
=
RespValue
.
decode
(
bytes
)
try
text
.
toDouble
catch
{
case
_:
NumberFormatException
=>
throw
ProtocolError
(
s
"'$text' isn't a double."
)
}
}
}
redis/src/main/scala/zio/redis/RedisExecutor.scala
浏览文件 @
ce380903
...
...
@@ -82,7 +82,7 @@ object RedisExecutor {
private
def
receive
:
IO
[
RedisError
,
Unit
]
=
byteStream
.
read
.
mapError
(
RedisError
.
IOError
)
.
transduce
(
RespValue
.
De
serializ
er
)
.
transduce
(
RespValue
.
De
cod
er
)
.
foreach
(
response
=>
resQueue
.
take
.
flatMap
(
_
.
succeed
(
response
)))
}
...
...
redis/src/main/scala/zio/redis/RespValue.scala
浏览文件 @
ce380903
...
...
@@ -36,7 +36,7 @@ object RespValue {
final
case
class
Integer
(
value
:
Long
)
extends
RespValue
final
case
class
BulkString
(
value
:
Chunk
[
Byte
])
extends
RespValue
{
private
[
redis
]
def
asString
:
String
=
decode
String
(
value
)
private
[
redis
]
def
asString
:
String
=
decode
(
value
)
private
[
redis
]
def
asLong
:
Long
=
internal
.
unsafeReadLong
(
asString
,
0
)
}
...
...
@@ -53,17 +53,7 @@ object RespValue {
}
}
def
array
(
values
:
RespValue*
)
:
Array
=
Array
(
Chunk
.
fromIterable
(
values
))
def
bulkString
(
s
:
String
)
:
BulkString
=
BulkString
(
Chunk
.
fromArray
(
s
.
getBytes
(
StandardCharsets
.
UTF_8
)))
def
decodeString
(
bytes
:
Chunk
[
Byte
])
:
String
=
new
String
(
bytes
.
toArray
,
StandardCharsets
.
UTF_8
)
private
[
redis
]
final
val
Cr
:
Byte
=
'\r'
private
[
redis
]
final
val
Lf
:
Byte
=
'\n'
private
[
redis
]
final
val
Deserializer
:
Transducer
[
RedisError.ProtocolError
,
Byte
,
RespValue
]
=
{
private
[
redis
]
final
val
Decoder
:
Transducer
[
RedisError.ProtocolError
,
Byte
,
RespValue
]
=
{
import
internal.State
val
processLine
=
...
...
@@ -78,6 +68,12 @@ object RespValue {
Transducer
.
utf8Decode
>>>
Transducer
.
splitLines
>>>
processLine
}
private
[
redis
]
def
array
(
values
:
RespValue*
)
:
Array
=
Array
(
Chunk
.
fromIterable
(
values
))
private
[
redis
]
def
bulkString
(
s
:
String
)
:
BulkString
=
BulkString
(
Chunk
.
fromArray
(
s
.
getBytes
(
StandardCharsets
.
UTF_8
)))
private
[
redis
]
def
decode
(
bytes
:
Chunk
[
Byte
])
:
String
=
new
String
(
bytes
.
toArray
,
StandardCharsets
.
UTF_8
)
private
object
internal
{
object
Headers
{
final
val
SimpleString
:
Byte
=
'+'
...
...
@@ -87,7 +83,7 @@ object RespValue {
final
val
Array
:
Byte
=
'*'
}
final
val
CrLf
:
Chunk
[
Byte
]
=
Chunk
(
Cr
,
Lf
)
final
val
CrLf
:
Chunk
[
Byte
]
=
Chunk
(
'\r'
,
'\n'
)
final
val
NullArray
:
String
=
"*-1"
final
val
NullValue
:
String
=
"$-1"
final
val
NullString
:
Chunk
[
Byte
]
=
Chunk
.
fromArray
(
"$-1\r\n"
.
getBytes
(
StandardCharsets
.
US_ASCII
))
...
...
@@ -115,15 +111,15 @@ object RespValue {
val
size
=
unsafeReadLong
(
line
,
1
).
toInt
if
(
size
>
0
)
CollectingArray
(
size
,
Chunk
.
empty
,
Start
.
feed
)
CollectingArray
(
size
,
Chunk
Builder
.
make
(
size
)
,
Start
.
feed
)
else
Done
(
Array
(
Chunk
.
empty
))
}
case
CollectingArray
(
rem
,
vals
,
next
)
=>
next
(
line
)
match
{
case
Done
(
v
)
if
rem
>
1
=>
CollectingArray
(
rem
-
1
,
vals
:+
v
,
Start
.
feed
)
case
Done
(
v
)
=>
Done
(
Array
(
vals
:+
v
))
case
Done
(
v
)
if
rem
>
1
=>
CollectingArray
(
rem
-
1
,
vals
+=
v
,
Start
.
feed
)
case
Done
(
v
)
=>
Done
(
Array
(
(
vals
+=
v
).
result
()
))
case
state
=>
CollectingArray
(
rem
,
vals
,
state
.
feed
)
}
...
...
@@ -133,11 +129,11 @@ object RespValue {
}
object
State
{
case
object
Start
extends
State
case
object
ExpectingBulk
extends
State
case
object
Failed
extends
State
final
case
class
CollectingArray
(
rem
:
Int
,
vals
:
Chunk
[
RespValue
],
next
:
String
=>
State
)
extends
State
final
case
class
Done
(
value
:
RespValue
)
extends
State
case
object
Start
extends
State
case
object
ExpectingBulk
extends
State
case
object
Failed
extends
State
final
case
class
CollectingArray
(
rem
:
Int
,
vals
:
Chunk
Builder
[
RespValue
],
next
:
String
=>
State
)
extends
State
final
case
class
Done
(
value
:
RespValue
)
extends
State
}
def
unsafeReadLong
(
text
:
String
,
startFrom
:
Int
)
:
Long
=
{
...
...
redis/src/test/scala/zio/redis/RespValueSpec.scala
浏览文件 @
ce380903
...
...
@@ -35,7 +35,7 @@ object RespValueSpec extends BaseSpec {
Stream
.
fromChunk
(
values
)
.
mapConcat
(
_
.
serialize
)
.
transduce
(
RespValue
.
De
serializ
er
)
.
transduce
(
RespValue
.
De
cod
er
)
.
runCollect
.
map
(
assert
(
_
)(
equalTo
(
values
)))
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录