Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Zio Redis
提交
30db77ac
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 搜索 >>
未验证
提交
30db77ac
编写于
12月 02, 2020
作者:
D
Dejan Mijić
提交者:
GitHub
12月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass connection info through layers (#235)
上级
a145b6da
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
34 addition
and
28 deletion
+34
-28
benchmarks/src/main/scala/zio/redis/BenchmarksUtils.scala
benchmarks/src/main/scala/zio/redis/BenchmarksUtils.scala
+5
-1
benchmarks/src/main/scala/zio/redis/RedisClients.scala
benchmarks/src/main/scala/zio/redis/RedisClients.scala
+6
-3
redis/src/main/scala/zio/redis/ByteStream.scala
redis/src/main/scala/zio/redis/ByteStream.scala
+9
-9
redis/src/main/scala/zio/redis/Interpreter.scala
redis/src/main/scala/zio/redis/Interpreter.scala
+5
-11
redis/src/main/scala/zio/redis/RedisConfig.scala
redis/src/main/scala/zio/redis/RedisConfig.scala
+7
-0
redis/src/test/scala/zio/redis/ApiSpec.scala
redis/src/test/scala/zio/redis/ApiSpec.scala
+1
-3
redis/src/test/scala/zio/redis/ByteStreamSpec.scala
redis/src/test/scala/zio/redis/ByteStreamSpec.scala
+1
-1
未找到文件。
benchmarks/src/main/scala/zio/redis/BenchmarksUtils.scala
浏览文件 @
30db77ac
...
...
@@ -12,5 +12,9 @@ trait BenchmarksUtils {
unsafeRunner
.
unsafeRun
(
f
)
def
zioUnsafeRun
(
source
:
ZIO
[
RedisExecutor
,
RedisError
,
Unit
])
:
Unit
=
unsafeRun
(
source
.
provideLayer
(
Logging
.
ignore
>>>
RedisExecutor
.
live
(
RedisHost
,
RedisPort
).
orDie
))
unsafeRun
(
source
.
provideLayer
(
BenchmarksUtils
.
Layer
))
}
object
BenchmarksUtils
{
private
final
val
Layer
=
Logging
.
ignore
>>>
RedisExecutor
.
default
.
orDie
}
benchmarks/src/main/scala/zio/redis/RedisClients.scala
浏览文件 @
30db77ac
...
...
@@ -11,13 +11,11 @@ import io.lettuce.core.ClientOptions
import
laserdisc.fs2.RedisClient
trait
RedisClients
{
import
RedisClients._
implicit
val
cs
:
ContextShift
[
CatsIO
]
=
CatsIO
.
contextShift
(
ExecutionContext
.
global
)
implicit
val
timer
:
Timer
[
CatsIO
]
=
CatsIO
.
timer
(
ExecutionContext
.
global
)
final
val
RedisHost
=
"127.0.0.1"
final
val
RedisPort
=
6379
type
RedisIO
[
A
]
=
Redis
[
CatsIO
,
A
]
type
Redis4CatsClient
[
V
]
=
RedisCommands
[
CatsIO
,
String
,
V
]
...
...
@@ -69,3 +67,8 @@ trait RedisClients {
Redis
[
CatsIO
].
withOptions
(
s
"redis://$RedisHost:$RedisPort"
,
ClientOptions
.
create
(),
longCodec
)
}
}
object
RedisClients
{
private
final
val
RedisHost
=
"127.0.0.1"
private
final
val
RedisPort
=
6379
}
redis/src/main/scala/zio/redis/ByteStream.scala
浏览文件 @
30db77ac
package
zio.redis
import
java.io.
{
EOFException
,
IOException
}
import
java.net.
{
Inet
Address
,
Inet
SocketAddress
,
SocketAddress
,
StandardSocketOptions
}
import
java.net.
{
InetSocketAddress
,
SocketAddress
,
StandardSocketOptions
}
import
java.nio.ByteBuffer
import
java.nio.channels.
{
AsynchronousSocketChannel
,
Channel
,
CompletionHandler
}
...
...
@@ -15,22 +15,22 @@ private[redis] object ByteStream {
def
write
(
chunk
:
Chunk
[
Byte
])
:
IO
[
IOException
,
Unit
]
}
def
live
(
host
:
String
,
port
:
Int
)
:
ZLayer
[
Logging
,
RedisError.IOError
,
Has
[
Service
]]
=
live
(
new
InetSocketAddress
(
host
,
port
))
lazy
val
default
:
ZLayer
[
Logging
,
RedisError.IOError
,
Has
[
ByteStream.
Service
]]
=
ZLayer
.
succeed
(
RedisConfig
.
Default
)
++
ZLayer
.
identity
[
Logging
]
>>>
live
def
live
(
address
:
=>
SocketAddress
)
:
ZLayer
[
Logging
,
RedisError.IOError
,
Has
[
Service
]]
=
connect
(
address
)
def
loopback
(
port
:
Int
=
RedisExecutor
.
DefaultPort
)
:
ZLayer
[
Logging
,
RedisError.IOError
,
Has
[
Service
]]
=
live
(
new
InetSocketAddress
(
InetAddress
.
getLoopbackAddress
,
port
))
lazy
val
live
:
ZLayer
[
Logging
with
Has
[
RedisConfig
]
,
RedisError.IOError
,
Has
[
ByteStream.Service
]]
=
ZLayer
.
fromServiceManaged
[
RedisConfig
,
Logging
,
RedisError.IOError
,
Service
]
{
config
=>
connect
(
new
InetSocketAddress
(
config
.
host
,
config
.
port
))
}
private
[
this
]
def
connect
(
address
:
=>
SocketAddress
)
:
Z
Layer
[
Logging
,
RedisError.IOError
,
Has
[
Service
]
]
=
private
[
this
]
def
connect
(
address
:
=>
SocketAddress
)
:
Z
Managed
[
Logging
,
RedisError.IOError
,
ByteStream.Service
]
=
(
for
{
address
<-
UIO
(
address
).
toManaged_
makeBuffer
=
IO
.
effectTotal
(
ByteBuffer
.
allocateDirect
(
ResponseBufferSize
))
readBuffer
<-
makeBuffer
.
toManaged_
writeBuffer
<-
makeBuffer
.
toManaged_
channel
<-
openChannel
(
address
)
}
yield
new
Connection
(
readBuffer
,
writeBuffer
,
channel
)).
mapError
(
RedisError
.
IOError
)
.
toLayer
}
yield
new
Connection
(
readBuffer
,
writeBuffer
,
channel
)).
mapError
(
RedisError
.
IOError
)
private
[
this
]
final
val
ResponseBufferSize
=
1024
...
...
redis/src/main/scala/zio/redis/Interpreter.scala
浏览文件 @
30db77ac
package
zio.redis
import
java.io.IOException
import
java.net.SocketAddress
import
scala.collection.compat.immutable.LazyList
...
...
@@ -22,16 +21,13 @@ trait Interpreter {
def
execute
(
command
:
Chunk
[
RespValue.BulkString
])
:
IO
[
RedisError
,
RespValue
]
}
def
live
(
address
:
=>
SocketAddress
)
:
ZLayer
[
Logging
,
RedisError.IOError
,
RedisExecutor
]
=
(
ZLayer
.
identity
[
Logging
]
++
ByteStream
.
live
(
address
))
>>>
StreamedExecutor
lazy
val
default
:
ZLayer
[
Logging
,
RedisError.IOError
,
RedisExecutor
]
=
ZLayer
.
identity
[
Logging
]
++
ByteStream
.
default
>>>
StreamedExecutor
def
live
(
host
:
String
,
port
:
Int
=
DefaultPort
)
:
ZLayer
[
Logging
,
RedisError.IOError
,
RedisExecutor
]
=
(
ZLayer
.
identity
[
Logging
]
++
ByteStream
.
live
(
host
,
port
))
>>>
StreamedExecutor
lazy
val
live
:
ZLayer
[
Logging
with
Has
[
RedisConfig
]
,
RedisError.IOError
,
RedisExecutor
]
=
ZLayer
.
identity
[
Logging
]
++
ByteStream
.
live
>>>
StreamedExecutor
def
loopback
(
port
:
Int
=
DefaultPort
)
:
ZLayer
[
Logging
,
RedisError.IOError
,
RedisExecutor
]
=
(
ZLayer
.
identity
[
Logging
]
++
ByteStream
.
loopback
(
port
))
>>>
StreamedExecutor
val
test
:
ZLayer
[
zio.random.Random
,
Nothing
,
RedisExecutor
]
=
{
lazy
val
test
:
URLayer
[
zio.random.Random
,
RedisExecutor
]
=
{
val
makePickRandom
:
URIO
[
zio.random.Random
,
Int
=>
USTM
[
Int
]]
=
for
{
seed
<-
random
.
nextInt
...
...
@@ -52,8 +48,6 @@ trait Interpreter {
}
}
private
[
redis
]
final
val
DefaultPort
=
6379
private
[
this
]
final
val
RequestQueueSize
=
16
private
[
this
]
final
val
StreamedExecutor
=
...
...
redis/src/main/scala/zio/redis/RedisConfig.scala
0 → 100644
浏览文件 @
30db77ac
package
zio.redis
final
case
class
RedisConfig
(
host
:
String
,
port
:
Int
)
object
RedisConfig
{
lazy
val
Default
=
RedisConfig
(
"localhost"
,
6379
)
}
redis/src/test/scala/zio/redis/ApiSpec.scala
浏览文件 @
30db77ac
...
...
@@ -29,7 +29,7 @@ object ApiSpec
hyperLogLogSuite
,
hashSuite
,
streamsSuite
).
provideCustomLayerShared
(
Logging
.
ignore
>>>
Executor
++
Clock
.
liv
e
),
).
provideCustomLayerShared
(
Clock
.
live
++
Logging
.
ignore
>>>
RedisExecutor
.
default
.
orDi
e
),
suite
(
"Test Executor"
)(
connectionSuite
,
setsSuite
...
...
@@ -37,6 +37,4 @@ object ApiSpec
.
get
.
provideCustomLayerShared
(
RedisExecutor
.
test
)
)
private
val
Executor
=
RedisExecutor
.
loopback
().
orDie
}
redis/src/test/scala/zio/redis/ByteStreamSpec.scala
浏览文件 @
30db77ac
...
...
@@ -18,5 +18,5 @@ object ByteStreamSpec extends BaseSpec {
res
<-
stream
.
read
.
runHead
}
yield
assert
(
res
)(
isSome
(
equalTo
(
'*'
.
toByte
)))
}
).
provideCustomLayer
(
Logging
.
ignore
>>>
ByteStream
.
loopback
()
.
orDie
)
).
provideCustomLayer
(
Logging
.
ignore
>>>
ByteStream
.
default
.
orDie
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录