Skip to content

Commit

Permalink
Prevent hDel and hmGet from receiving empty list (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
nox213 authored Mar 26, 2023
1 parent 250084b commit e4ed102
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package dev.profunktor.redis4cats.algebra

trait HashCommands[F[_], K, V] extends HashGetter[F, K, V] with HashSetter[F, K, V] with HashIncrement[F, K, V] {
def hDel(key: K, fields: K*): F[Long]
def hDel(key: K, field: K, fields: K*): F[Long]
def hExists(key: K, field: K): F[Boolean]
}

trait HashGetter[F[_], K, V] {
def hGet(key: K, field: K): F[Option[V]]
def hGetAll(key: K): F[Map[K, V]]
def hmGet(key: K, fields: K*): F[Map[K, V]]
def hmGet(key: K, field: K, fields: K*): F[Map[K, V]]
def hKeys(key: K): F[List[K]]
def hVals(key: K): F[List[V]]
def hStrLen(key: K, field: K): F[Option[Long]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ private[redis4cats] class BaseRedis[F[_]: FutureLift: MonadThrow: Log, K, V](
async.flatMap(_.msetnx(keyValues.asJava).futureLift.map(x => Boolean.box(x)))

/******************************* Hashes API **********************************/
override def hDel(key: K, fields: K*): F[Long] =
async.flatMap(_.hdel(key, fields: _*).futureLift.map(x => Long.box(x)))
override def hDel(key: K, field: K, fields: K*): F[Long] =
async.flatMap(_.hdel(key, (field +: fields): _*).futureLift.map(x => Long.box(x)))

override def hExists(key: K, field: K): F[Boolean] =
async.flatMap(_.hexists(key, field).futureLift.map(x => Boolean.box(x)))
Expand All @@ -640,9 +640,9 @@ private[redis4cats] class BaseRedis[F[_]: FutureLift: MonadThrow: Log, K, V](
override def hGetAll(key: K): F[Map[K, V]] =
async.flatMap(_.hgetall(key).futureLift.map(_.asScala.toMap))

override def hmGet(key: K, fields: K*): F[Map[K, V]] =
override def hmGet(key: K, field: K, fields: K*): F[Map[K, V]] =
async
.flatMap(_.hmget(key, fields: _*).futureLift)
.flatMap(_.hmget(key, (field +: fields): _*).futureLift)
.map(_.asScala.toList.collect { case kv if kv.hasValue => kv.getKey -> kv.getValue }.toMap)

override def hKeys(key: K): F[List[K]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ trait TestScenarios { self: FunSuite =>
_ <- IO(assert(w.contains("some value")))
w <- redis.hmGet(testKey, testField, testField2)
_ <- IO(assertEquals(w, Map(testField -> "some value")))
w <- redis.hmGet(testKey, testField)
_ <- IO(assertEquals(w, Map(testField -> "some value")))
d <- redis.hDel(testKey, testField)
_ <- IO(assertEquals(d, 1L))
z <- redis.hGet(testKey, testField)
Expand Down

0 comments on commit e4ed102

Please sign in to comment.