Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,28 @@ libraryDependencies ++= Seq(
```scala
import zio._
import zio.redis._
import zio.redis.options.NonNegativeLong
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] =

val myApp: ZIO[Redis, RedisError, Unit] =
for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minutes))
_ <- redis.set("myKey", 8L, expireAt = Some(SetExpire.SetExpireSeconds(NonNegativeLong(60))))
v <- redis.get("myKey").returning[Long]
_ <- Console.printLine(s"Value of myKey: $v").orDie
_ <- redis.hSet("myHash", ("k1", 6), ("k2", 2))
_ <- redis.rPush("myList", 1, 2, 3, 4)
_ <- redis.sAdd("mySet", "a", "b", "a", "c")
} yield ()

override def run =
override def run =
myApp.provide(Redis.local, ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier))
}
```
Expand Down
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ libraryDependencies ++= Seq(
```scala mdoc:compile-only
import zio._
import zio.redis._
import zio.redis.options.NonNegativeLong
import zio.schema._
import zio.schema.codec._

Expand All @@ -49,10 +50,10 @@ object ZIORedisExample extends ZIOAppDefault {
def get[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec
}

val myApp: ZIO[Redis, RedisError, Unit] =
val myApp: ZIO[Redis, RedisError, Unit] =
for {
redis <- ZIO.service[Redis]
_ <- redis.set("myKey", 8L, Some(1.minutes))
_ <- redis.set("myKey", 8L, expireAt = Some(SetExpire.Seconds(NonNegativeLong(60))))
v <- redis.get("myKey").returning[Long]
_ <- Console.printLine(s"Value of myKey: $v").orDie
_ <- redis.hSet("myHash", ("k1", 6), ("k2", 2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import zio._
import zio.json._
import zio.redis._
import zio.redis.example.ApiError._
import zio.redis.options.PositiveLong

trait ContributorsCache {
def fetchAll(repository: Repository): IO[ApiError, Contributors]
Expand All @@ -40,7 +41,7 @@ object ContributorsCache {
ZIO
.fromOption(NonEmptyChunk.fromChunk(contributors))
.map(Contributors(_).toJson)
.flatMap(data => redis.set(repository.key, data, Some(1.minute)).orDie)
.flatMap(data => redis.set(repository.key, data, expireAt = Some(SetExpire.Seconds(PositiveLong(60)))).orDie)
.ignore

private def read(repository: Repository): IO[ApiError, Contributors] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait HyperLogLogSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.set(key, value, None, None, None)
_ <- redis.set(key, value, None, None)
add <- redis.pfAdd(key, "one", "two", "three").either
} yield assert(add)(isLeft(isSubtype[RedisError.WrongType](anything)))
}
Expand Down Expand Up @@ -63,7 +63,7 @@ trait HyperLogLogSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.set(key, value, None, None, None)
_ <- redis.set(key, value, None, None)
count <- redis.pfCount(key).either
} yield assert(count)(isLeft)
}
Expand Down Expand Up @@ -101,7 +101,7 @@ trait HyperLogLogSpec extends IntegrationSpec {
value <- uuid
key2 <- uuid
key3 <- uuid
_ <- redis.set(key, value, None, None, None)
_ <- redis.set(key, value, None, None)
_ <- redis.pfAdd(key2, "five", "six", "seven")
merge <- redis.pfMerge(key3, key2, key).either
} yield assert(merge)(isLeft)
Expand Down
5 changes: 3 additions & 2 deletions modules/redis-it/src/test/scala/zio/redis/KeysSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zio.redis
import com.dimafeng.testcontainers.DockerComposeContainer
import zio._
import zio.redis.RedisError.ProtocolError
import zio.redis.options.PositiveLong
import zio.test.Assertion.{exists => _, _}
import zio.test.TestAspect.{restore => _, _}
import zio.test._
Expand Down Expand Up @@ -244,7 +245,7 @@ trait KeysSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.pSetEx(key, 1000.millis, value)
_ <- redis.set(key, value, expireAt = Some(SetExpire.Milliseconds(PositiveLong(1000))))
ttl <- redis.ttl(key).either
} yield assert(ttl)(isRight)
} @@ flaky,
Expand All @@ -260,7 +261,7 @@ trait KeysSpec extends IntegrationSpec {
redis <- ZIO.service[Redis]
key <- uuid
value <- uuid
_ <- redis.pSetEx(key, 1000.millis, value)
_ <- redis.set(key, value, expireAt = Some(SetExpire.Milliseconds(PositiveLong(1000))))
pTtl <- redis.pTtl(key).either
} yield assert(pTtl)(isRight)
} @@ flaky,
Expand Down
16 changes: 10 additions & 6 deletions modules/redis-it/src/test/scala/zio/redis/SortedSetsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ trait SortedSetsSpec extends IntegrationSpec {
key <- uuid
_ <- redis.zAdd(key)(MemberScore("v1", 3d))
_ <- redis.zAdd(key)(MemberScore("v2", 4d))
added <- redis.zAdd(key, update = Some(Update.SetLessThan))(MemberScore("v3", 1d), MemberScore("v1", 2d))
added <- redis.zAdd(key, updateByScore = Some(UpdateByScore.SetLessThan))(
MemberScore("v3", 1d),
MemberScore("v1", 2d)
)
result <- redis.zRange(key, 0 to -1).returning[String]
} yield assert(added)(equalTo(1L)) && assert(result.toList)(equalTo(List("v3", "v1", "v2")))
},
Expand All @@ -193,7 +196,10 @@ trait SortedSetsSpec extends IntegrationSpec {
key <- uuid
_ <- redis.zAdd(key)(MemberScore("v1", 1d))
_ <- redis.zAdd(key)(MemberScore("v2", 2d))
added <- redis.zAdd(key, update = Some(Update.SetGreaterThan))(MemberScore("v3", 1d), MemberScore("v1", 3d))
added <- redis.zAdd(key, updateByScore = Some(UpdateByScore.SetGreaterThan))(
MemberScore("v3", 1d),
MemberScore("v1", 3d)
)
result <- redis.zRange(key, 0 to -1).returning[String]
} yield assert(added)(equalTo(1L)) && assert(result.toList)(equalTo(List("v3", "v2", "v1")))
},
Expand All @@ -203,7 +209,7 @@ trait SortedSetsSpec extends IntegrationSpec {
key <- uuid
_ <- redis.zAdd(key)(MemberScore("v1", 1d))
_ <- redis.zAdd(key)(MemberScore("v2", 2d))
added <- redis.zAdd(key, update = Some(Update.SetGreaterThan), change = Some(Changed))(
added <- redis.zAdd(key, updateByScore = Some(UpdateByScore.SetGreaterThan), change = Some(Changed))(
MemberScore("v3", 1d),
MemberScore("v1", 3d)
)
Expand Down Expand Up @@ -431,9 +437,7 @@ trait SortedSetsSpec extends IntegrationSpec {
_ <- redis.zAdd(second)(MemberScore("b", 2d), MemberScore("b", 2d), MemberScore("d", 4d))
_ <- redis.zAdd(third)(MemberScore("a", 1d), MemberScore("b", 2d), MemberScore("c", 3d))
members <- redis.zInter(first, second, third)().returning[String]
} yield assert(members)(
equalTo(Chunk("b"))
)
} yield assert(members)(equalTo(Chunk("b")))
},
test("error when first parameter is not set") {
for {
Expand Down
Loading