zio / zio-redis

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

SCAN never terminates #971

Open russwyte opened 1 month ago

russwyte commented 1 month ago

When using SCAN to get keys - the scan method never returns a 0 cursor - resulting in infinite recursion.

example that should work but does not:

  def findKeys(pattern: String): IO[RedisError, Chunk[String]] =
    def loop(cursor: Long, acc: Chunk[String]): Result[Chunk[String]] =
      manager.redis
        .scan(cursor, Some(pattern))
        .returning[String]
        .flatMap { case (nextCursor, keys) =>
          if nextCursor == 0L then ZIO.succeed((acc ++ keys).distinct)
          else loop(nextCursor, acc ++ keys)
        }
    end loop
    loop(0L, Chunk.empty)
  end findKeys