Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Scala Macro Tools
提交
05d76b5b
S
Scala Macro Tools
项目概览
梦境迷离
/
Scala Macro Tools
上一次同步 大约 1 年
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Scala Macro Tools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
05d76b5b
编写于
3月 27, 2022
作者:
梦境迷离
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use json for zio-redis schema
上级
c7fdcd2d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
62 addition
and
61 deletion
+62
-61
README.md
README.md
+2
-2
README_CN.md
README_CN.md
+2
-2
build.sbt
build.sbt
+1
-1
cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisConfiguration.scala
...cala/org/bitlap/cacheable/redis/ZRedisConfiguration.scala
+2
-2
cacheable-redis/src/test/resources/application.conf
cacheable-redis/src/test/resources/application.conf
+1
-0
cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheableTest.scala
...test/scala/org/bitlap/cacheable/redis/CacheableTest.scala
+54
-54
未找到文件。
README.md
浏览文件 @
05d76b5b
...
...
@@ -80,10 +80,10 @@ Add library dependency
**Use `smt-cacheable-redis`**
>
Not Unavailable
>
TODO Not unavailable, no distributed lock
```
scala
// distributed cache, include dependencies: zio-redis,
config,zio-schema, optional (zio-schema-protobuf,
zio-schema-derivation for case class)
// distributed cache, include dependencies: zio-redis,
config, zio-schema, zio-schema-json, optional (
zio-schema-derivation for case class)
// dependsOn `smt-cacheable-core`(not support Scala2.11.x)
"org.bitlap"
%%
"smt-cacheable-redis"
%
"<VERSION>"
```
...
...
README_CN.md
浏览文件 @
05d76b5b
...
...
@@ -82,10 +82,10 @@
**使用redis实现的cacheable模块**
>
目前不可用
>
TODO,目前不可用,无分布式锁
```
scala
// 分布式缓存, 内部包含的依赖: zio-redis, config, zio-schema,
可选的 (zio-schema-protobuf,
zio-schema-derivation用于样例类序列化)
// 分布式缓存, 内部包含的依赖: zio-redis, config, zio-schema,
zio-schema-json, 可选的 (
zio-schema-derivation用于样例类序列化)
// 依赖于`smt-cacheable-core`(不支持 Scala2.11.x)
"org.bitlap"
%%
"smt-cacheable-redis"
%
"<VERSION>"
```
...
...
build.sbt
浏览文件 @
05d76b5b
...
...
@@ -81,7 +81,7 @@ lazy val `cacheable-redis` = (project in file("cacheable-redis"))
"dev.zio" %% "zio-redis" % "0.0.0+381-86c20614-SNAPSHOT", // 实验性质的
"com.typesafe" % "config" % "1.4.2",
"dev.zio" %% "zio-schema" % "0.1.8",
"dev.zio" %% "zio-schema-
protobuf
" % "0.1.8",
"dev.zio" %% "zio-schema-
json
" % "0.1.8",
"dev.zio" %% "zio-schema-derivation" % "0.1.8" % Test,
),
excludeDependencies ++= Seq(
...
...
cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisConfiguration.scala
浏览文件 @
05d76b5b
...
...
@@ -24,7 +24,7 @@ package org.bitlap.cacheable.redis
import
com.typesafe.config.
{
Config
,
ConfigFactory
}
import
org.bitlap.cacheable.core.Utils
import
zio.redis.
{
Redis
,
RedisConfig
,
RedisError
,
RedisExecutor
}
import
zio.schema.codec.
{
Codec
,
Protobuf
Codec
}
import
zio.schema.codec.
{
Codec
,
Json
Codec
}
import
zio.
{
Has
,
Layer
,
ULayer
,
ZLayer
}
import
zio.logging.Logging
...
...
@@ -43,7 +43,7 @@ object ZRedisConfiguration {
private
[
redis
]
lazy
val
disabledLog
:
Boolean
=
custom
.
getBoolean
(
"redis.disabledLog"
)
private
val
codec
:
ULayer
[
Has
[
Codec
]]
=
ZLayer
.
succeed
[
Codec
](
Protobuf
Codec
)
private
val
codec
:
ULayer
[
Has
[
Codec
]]
=
ZLayer
.
succeed
[
Codec
](
Json
Codec
)
lazy
val
redisLayer
:
Layer
[
RedisError.IOError
,
ZRedisCacheService
]
=
(((
if
(
disabledLog
)
Logging
.
ignore
else
Utils
.
logLayer
)
++
ZLayer
.
succeed
(
redisConf
))
>>>
...
...
cacheable-redis/src/test/resources/application.conf
浏览文件 @
05d76b5b
redis
{
host
=
"0.0.0.0"
port
=
6379
disabledLog
=
false
}
\ No newline at end of file
cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheableTest.scala
浏览文件 @
05d76b5b
...
...
@@ -61,58 +61,58 @@ class CacheableTest extends AnyFlatSpec with Matchers {
ZIO
.
effect
(
CacheValue
(
Random
.
nextInt
()
+
""
))
}
}
//
//
"cacheable4" should "zstream operation is ok with redis" in {
//
val chunk = Chunk(Random.nextInt().toString, Random.nextInt().toString, Random.nextInt().toString)
//
//
@cacheable(local = false)
//
def readStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = {
//
ZStream.fromIterable(chunk)
//
}
//
//
println(chunk)
//
val result = runtime.unsafeRun(for {
//
_ <- ZRedisService.del("CacheableTest-readStreamFunction")
//
method <- readStreamFunction(1, "hello").runCollect
//
cache <- ZRedisService.hGet[Chunk[String]]("CacheableTest-readStreamFunction", "1-hello")
// } yield method -> cache
//
)
//
result._1 shouldEqual result._2
//
}
//
//
"cacheable5" should "entity zstream is ok with redis" in {
//
val cacheValue = CacheValue(Random.nextInt().toString)
//
//
@cacheable(local = false)
//
def readEntityStreamFunction(id: Int, key: String): ZStream[Any, Throwable, CacheValue] = {
//
ZStream.fromEffect(ZIO.effect(cacheValue))
//
}
//
//
val result = runtime.unsafeRun(for {
//
_ <- ZRedisService.del("CacheableTest-readEntityStreamFunction")
//
method <- readEntityStreamFunction(1, "hello").runHead
//
} yield method
//
)
//
//
result shouldEqual Some(cacheValue)
//
}
//
//
"cacheable6" should "entity zio is ok with redis" in {
//
val cacheValue = CacheValue(Random.nextInt().toString)
//
//
@cacheable(local = false)
//
def readEntityIOFunction(id: Int, key: String): ZIO[Any, Throwable, CacheValue] = {
//
ZIO.effect(cacheValue)
//
}
//
//
val result = runtime.unsafeRun(for {
//
_ <- ZRedisService.del("CacheableTest-readEntityIOFunction")
//
method <- readEntityIOFunction(1, "hello")
//
cache <- ZRedisService.hGet[CacheValue]("CacheableTest-readEntityIOFunction", "1-hello")
// } yield Some(method) -> Some(cache)
//
)
//
//
result._1 shouldEqual result._2
//
//
}
"cacheable4"
should
"zstream operation is ok with redis"
in
{
val
chunk
=
Chunk
(
Random
.
nextInt
().
toString
,
Random
.
nextInt
().
toString
,
Random
.
nextInt
().
toString
)
@cacheable
(
local
=
false
)
def
readStreamFunction
(
id
:
Int
,
key
:
String
)
:
ZStream
[
Any
,
Throwable
,
String
]
=
{
ZStream
.
fromIterable
(
chunk
)
}
println
(
chunk
)
val
result
=
runtime
.
unsafeRun
(
for
{
_
<-
ZRedisService
.
del
(
"CacheableTest-readStreamFunction"
)
method
<-
readStreamFunction
(
1
,
"hello"
).
runCollect
cache
<-
ZRedisService
.
hGet
[
Chunk
[
String
]](
"CacheableTest-readStreamFunction"
,
"1-hello"
)
}
yield
method
->
cache
.
getOrElse
(
Chunk
.
empty
)
)
result
.
_1
shouldEqual
result
.
_2
}
"cacheable5"
should
"entity zstream is ok with redis"
in
{
val
cacheValue
=
CacheValue
(
Random
.
nextInt
().
toString
)
@cacheable
(
local
=
false
)
def
readEntityStreamFunction
(
id
:
Int
,
key
:
String
)
:
ZStream
[
Any
,
Throwable
,
CacheValue
]
=
{
ZStream
.
fromEffect
(
ZIO
.
effect
(
cacheValue
))
}
val
result
=
runtime
.
unsafeRun
(
for
{
_
<-
ZRedisService
.
del
(
"CacheableTest-readEntityStreamFunction"
)
method
<-
readEntityStreamFunction
(
1
,
"hello"
).
runHead
}
yield
method
)
result
shouldEqual
Some
(
cacheValue
)
}
"cacheable6"
should
"entity zio is ok with redis"
in
{
val
cacheValue
=
CacheValue
(
Random
.
nextInt
().
toString
)
@cacheable
(
local
=
false
)
def
readEntityIOFunction
(
id
:
Int
,
key
:
String
)
:
ZIO
[
Any
,
Throwable
,
CacheValue
]
=
{
ZIO
.
effect
(
cacheValue
)
}
val
result
=
runtime
.
unsafeRun
(
for
{
_
<-
ZRedisService
.
del
(
"CacheableTest-readEntityIOFunction"
)
method
<-
readEntityIOFunction
(
1
,
"hello"
)
cache
<-
ZRedisService
.
hGet
[
CacheValue
](
"CacheableTest-readEntityIOFunction"
,
"1-hello"
)
}
yield
Some
(
method
)
->
cache
)
result
.
_1
shouldEqual
result
.
_2
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录