Skip to content

Commit

Permalink
Merge pull request #200 from KarelCemus/prefix
Browse files Browse the repository at this point in the history
Fixed cache prefix in SyncRedis
  • Loading branch information
KarelCemus committed Jan 31, 2019
2 parents 0c4bf37 + e646d9f commit c236d9e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Added `getAll[T: ClassTag](keys: Iterable[String]): Result[Seq[Option[T]]]` into `AbstractCacheApi`
in order to also accept collections aside vararg. [#194](https://github.com/KarelCemus/play-redis/pull/194)

Fixed `getOrElse` method in Synchronous API with non-empty cache prefix. [#196](https://github.com/KarelCemus/play-redis/pull/196)

### [:link: 2.3.0](https://github.com/KarelCemus/play-redis/tree/2.3.0)

Support of Redis Sentinel [#181](https://github.com/KarelCemus/play-redis/pull/181)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/play/api/cache/redis/impl/SyncRedis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private[impl] class SyncRedis(redis: RedisConnector)(implicit runtime: RedisRunt
// helpers for dsl
import dsl._

override def getOrElse[T: ClassTag](key: String, expiration: Duration)(orElse: => T) = {
override def getOrElse[T: ClassTag](key: String, expiration: Duration)(orElse: => T) = key.prefixed { key =>
// note: this method is overridden so the `orElse` won't be included in the timeout
// compute orElse and try to set it into the cache
def computeAndSet = {
Expand Down
8 changes: 8 additions & 0 deletions src/test/scala/play/api/cache/redis/impl/RedisCacheSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ class RedisCacheSpec(implicit ee: ExecutionEnv) extends Specification with Reduc
orElse mustEqual 1
}

"get or else (prefixed,miss)" in new MockedSyncRedis with OrElse {
runtime.prefix returns new RedisPrefixImpl("prefix")
connector.get[String](beEq(s"prefix:$key"))(anyClassTag) returns None
connector.set(beEq(s"prefix:$key"), anyString, any[Duration], anyBoolean) returns true
cache.getOrElse(key)(doElse(value)) must beEqualTo(value)
orElse mustEqual 1
}

"get or future (hit)" in new MockedCache with OrElse {
connector.get[String](anyString)(anyClassTag) returns Some(value)
cache.getOrFuture(key)(doFuture(value)) must beEqualTo(value).await
Expand Down
8 changes: 8 additions & 0 deletions src/test/scala/play/api/cache/redis/impl/SyncRedisSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ class SyncRedisSpec(implicit ee: ExecutionEnv) extends Specification with Reduce
cache.getOrElse(key)(doElse(value)) must beEqualTo(value)
orElse mustEqual 1
}

"get or else (prefixed,miss)" in new MockedSyncRedis with OrElse {
runtime.prefix returns new RedisPrefixImpl("prefix")
connector.get[String](beEq(s"prefix:$key"))(anyClassTag) returns None
connector.set(beEq(s"prefix:$key"), anyString, any[Duration], anyBoolean) returns true
cache.getOrElse(key)(doElse(value)) must beEqualTo(value)
orElse mustEqual 1
}
}
}

0 comments on commit c236d9e

Please sign in to comment.