Skip to content

Commit

Permalink
Merge pull request #57 from OddKristensen/bulk-mget-and-mset
Browse files Browse the repository at this point in the history
mset() and mget() accept variadic parameters
  • Loading branch information
ChristopherDavenport authored Sep 6, 2022
2 parents a30d96c + 97f1835 commit 899d42b
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,15 @@ object RedisCommands {
def expire[F[_]: RedisCtx](key: String, seconds: Long): F[Boolean] =
RedisCtx[F].keyed(key, NEL.of("EXPIRE", key.encode, seconds.encode))

def mget[F[_]: RedisCtx](key: String): F[List[Option[String]]] = {
private[rediculous] def mget[F[_]: RedisCtx](key: String): F[List[Option[String]]] = {
val cmd = NEL("MGET", key.encode :: Nil)
RedisCtx[F].keyed(key, cmd)
}

def mget[F[_]: RedisCtx](key: String, keys: String*): F[List[Option[String]]] = {
RedisCtx[F].keyed(key, NEL("MGET", (key :: keys.toList).map(_.encode)))
}

def bitpos[F[_]: RedisCtx](key: String, bit: Long, start: Long, end: Long): F[Long] =
RedisCtx[F].keyed(key, NEL.of("BITPOS", key.encode, bit.encode, start.encode, end.encode))

Expand Down Expand Up @@ -769,9 +773,14 @@ object RedisCommands {
def hsetnx[F[_]: RedisCtx](key: String, field: String, value: String): F[Boolean] =
RedisCtx[F].keyed(key, NEL.of("HSETNX", key.encode, field.encode, value.encode))

def mset[F[_]: RedisCtx](keyvalue: (String, String)): F[Status] =
private[rediculous] def mset[F[_]: RedisCtx](keyvalue: (String, String)): F[Status] =
RedisCtx[F].keyed(keyvalue._1, NEL("MSET", List(keyvalue._1.encode, keyvalue._2.encode)))

def mset[F[_]: RedisCtx](keyValue: (String, String), keyValues: (String, String)*): F[List[Status]] = {
val command = NEL("MSET", (keyValue :: keyValues.toList).flatMap(t => List(t._1.encode, t._2.encode)))
RedisCtx[F].keyed(keyValue._1, command)
}

def setex[F[_]: RedisCtx](key: String, seconds: Long, value: String): F[Status] =
RedisCtx[F].keyed(key, NEL.of("SETEX", key.encode, seconds.encode, value.encode))

Expand Down

0 comments on commit 899d42b

Please sign in to comment.