zio / zio-redis

A ZIO-based redis client
https://zio.github.io/zio-redis
Apache License 2.0
121 stars 63 forks source link

Stuck when Value is greater than 127 #944

Closed dungdq2002 closed 3 months ago

dungdq2002 commented 4 months ago

Similar to this issue https://github.com/zio/zio-redis/issues/898, I get stuck when I query a key with a value greater than 127. It seems that zio-redis is not compatible with ProtobufCodec, as it's fine if I use CodecSupplier.utf8string.

import zio._
import zio.redis._
import zio.schema._
import zio.schema.codec._

object ZIORedisExample extends ZIOAppDefault {

  object ProtobufCodecSupplier extends CodecSupplier {
    def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
  }

  val myApp: ZIO[Redis, RedisError, Unit] =
    for {
      redis <- ZIO.service[Redis]
      _   <- redis.set("key", 128)
      res    <- redis.get("key").returning[Int]  // get stuck
      _     <- ZIO.log(s"$res")
    } yield ()

  override def run = myApp.provide(
    Redis.layer,
    RedisExecutor.layer,
    ZLayer.succeed(RedisConfig.Default),
    ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier),
  )

}
mijicd commented 4 months ago

We just merged a fix for #898, could you please check out the latest snapshot (once it lands) and let us know if it addressed your issue as well?

victornguen commented 3 months ago

Hi! I tried to reproduce this issue using version 0.2.0 and the snapshot. This bug has been fixed in #946. When the data was encoded in ASCII, it caused issues with the protobuf encoding, leading to corruption of the data. As a result, the data could not be decoded correctly.