-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support zio2.x #598
Support zio2.x #598
Conversation
… in some places.
@@ -152,8 +151,9 @@ object Output { | |||
final case class OptionalOutput[+A](output: Output[A]) extends Output[Option[A]] { | |||
protected def tryDecode(respValue: RespValue)(implicit codec: Codec): Option[A] = | |||
respValue match { | |||
case RespValue.NullBulkString | RespValue.NullArray | RespValue.BulkString(Chunk.empty) => None | |||
case other => Some(output.tryDecode(other)) | |||
case RespValue.NullBulkString | RespValue.NullArray => None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIXME
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please elaborate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compile failed
stable identifier required, but zio.Chunk.empty found.
case RespValue.NullBulkString | RespValue.NullArray | RespValue.BulkString(Chunk.empty) => None
because in zio2.x Chunk.empty is def
?
… into series/2.x � Conflicts: � redis/src/main/scala/zio/redis/TestExecutor.scala
bfd5b22
to
5c11ed9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thank you for taking care of this. Since it is a huge change we may need to do a few review passes, but it looks good in general.
P.S. It looks like we're going to "forget" about 1.x compatible release (which is not necessary bad considering our timing). That said, please resolve the conflicts.
benchmarks/src/main/scala/zio/redis/benchmarks/lists/BlMoveBenchmarks.scala
Outdated
Show resolved
Hide resolved
|
||
import java.util.concurrent.TimeUnit | ||
|
||
@State(Scope.Thread) | ||
@State(org.openjdk.jmh.annotations.Scope.Thread) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? The import is there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope conflicts with zio.Scope, I have imported zio.Scope to hide
import zio.redis.RedisConfig | ||
|
||
final case class AppConfig(redis: RedisConfig, server: ServerConfig) | ||
|
||
object AppConfig { | ||
val descriptor: ConfigDescriptor[AppConfig] = DeriveConfigDescriptor.descriptor[AppConfig] | ||
val confDescriptor: _root_.zio.config.ConfigDescriptor[AppConfig] = descriptor[AppConfig] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
descriptor is now the top-level method instead of DeriveConfigDescriptor's method. And i will delete package prefix
package object example { | ||
type ContributorsCache = Has[ContributorsCache.Service] | ||
type ContributorsCache = ContributorsCache.Service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should get rid of old module pattern encoding as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will use case class
@@ -28,57 +27,59 @@ import java.nio.channels.{AsynchronousSocketChannel, Channel, CompletionHandler} | |||
private[redis] object ByteStream { | |||
trait Service { | |||
def read: Stream[IOException, Byte] | |||
def write(chunk: Chunk[Byte]): IO[IOException, Unit] | |||
def write(chunk: Chunk[Byte]): IO[IOException, Option[Unit]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Option is required for matching here(case State.Start), this is one of the areas I find most confusing.
private[redis] final val Decoder: ZPipeline[Any, RedisError.ProtocolError, Byte, Option[RespValue]] = {
val Sinker: ZSink[Any, RedisError.ProtocolError, String, String, Option[RespValue]] = {
import internal.State
ZSink.fold[String, State](State.Start)(_.inProgress)(_ feed _).mapZIO {
case State.Done(value) => ZIO.succeedNow(Some(value))
case State.Failed => ZIO.fail(RedisError.ProtocolError("Invalid data received."))
// ZSink fold will return a State.Start when contFn is false
case State.Start => ZIO.succeedNow(None)
case other => ZIO.dieMessage(s"Deserialization bug, should not get $other")
}
}
lazy val live: URLayer[Has[RedisExecutor] with Has[Codec], Has[Redis]] = | ||
ZLayer.identity[Has[Codec]] ++ ZLayer.identity[Has[RedisExecutor]] >>> RedisService | ||
lazy val live: URLayer[RedisExecutor with Codec, Redis] = | ||
ZLayer.environment[Codec] ++ ZLayer.environment[RedisExecutor] >>> RedisService |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd get rid of operators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean i should use ZLayer.make
?
private[redis] final val Decoder: Transducer[RedisError.ProtocolError, Byte, RespValue] = { | ||
import internal.State | ||
private[redis] final val Decoder: ZPipeline[Any, RedisError.ProtocolError, Byte, Option[RespValue]] = { | ||
val Sinker: ZSink[Any, RedisError.ProtocolError, String, String, Option[RespValue]] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop the type, and use the lower camel case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't mark unresolved issues as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, I thought it was just the outermost type declaration that should be removed.
…chmarks.scala Co-authored-by: Dejan Mijić <dmijic@acm.org>
case class ServiceLive(r: Redis, s: Sttp) extends Service { | ||
override def fetchAll(repository: Repository): IO[ApiError, Contributors] = | ||
(read(repository) <> retrieve(repository)).provide(ZLayer.succeed(r), ZLayer.succeed(s)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's abandon the old encoding, e.g.:
trait ContributorsCache {
def fetchAll(...)
}
final case class ContributorsCacheLive(...) extends ContributorsCache {
...
}
Also, let's please adhere to the multi-unit files naming convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
(read(repository) <> retrieve(repository)).provide(ZLayer.succeed(r), ZLayer.succeed(s)) | ||
} | ||
|
||
object ServiceLive { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adjust accordingly.
} | ||
|
||
object ServiceLive { | ||
lazy val layer: ZLayer[Redis with Sttp, Nothing, Service] = ZLayer.fromZIO { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need fromZIO
, apply
works as well. Also, you can use URLayer
.
get(repository.key) | ||
.returning[String] | ||
.someOrFail(ApiError.CacheMiss(repository.key)) | ||
.map(_.fromJson[Contributors]) | ||
.rightOrFail(ApiError.CorruptedData) | ||
.refineToOrDie[ApiError] | ||
.foldZIO(_ => ZIO.fail(ApiError.CorruptedData), s => ZIO.succeed(s.getOrElse(Contributors(Chunk.empty)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found no rightOrFail
method, so I changed it here.
@@ -22,41 +22,38 @@ import example.config.{AppConfig, ServerConfig} | |||
import sttp.client3.asynchttpclient.zio.AsyncHttpClientZioBackend | |||
import zhttp.service.server.ServerChannelFactory | |||
import zhttp.service.{EventLoopGroup, Server} | |||
import zio.Console.printLine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not import it. Console.printLine
reads nicer.
import zio.redis.RedisError.ProtocolError | ||
import zio.redis.RespValue.{BulkString, bulkString} | ||
import zio.redis.TestExecutor.{KeyInfo, KeyType} | ||
import zio.stm.{random => _, _} | ||
import zio.stm._ | ||
import zio.{Clock, Random, _} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import zio.{Clock, Random, _} | |
import zio._ |
import zio.redis.Input._ | ||
import zio.redis.Output._ | ||
import zio.redis.ResultBuilder._ | ||
import zio.redis._ | ||
import zio.schema.Schema | ||
import zio.{Chunk, Has, ZIO} | ||
import zio.{Chunk, ZIO, _} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import zio.{Chunk, ZIO, _} | |
import zio._ |
import zio.redis.Input._ | ||
import zio.redis.Output._ | ||
import zio.redis.ResultBuilder._ | ||
import zio.redis._ | ||
import zio.schema.Schema | ||
import zio.{Chunk, Has, ZIO} | ||
import zio.{Chunk, ZIO, _} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import zio.{Chunk, ZIO, _} | |
import zio._ |
import zio.redis.Input._ | ||
import zio.redis.Output._ | ||
import zio.redis.ResultBuilder._ | ||
import zio.redis._ | ||
import zio.schema.Schema | ||
import zio.{Chunk, Has, ZIO} | ||
import zio.{Chunk, ZIO, _} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import zio.{Chunk, ZIO, _} | |
import zio._ |
@jxnu-liguobin this pattern repeats a lot, please adjust it everywhere according to the suggestion.
private val TestLayer = | ||
RedisExecutor.test ++ ZLayer.succeed(codec) >>> Redis.live | ||
private val TestLayer = { | ||
val redis = RedisExecutor.test ++ ZLayer.succeed(codec) >>> Redis.live |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to just use make
.
closed #462 Initially commit to upgrade zio2.x
Blocking until ZIO 2.0.0