Skip to content

Commit

Permalink
a few additional client commands
Browse files Browse the repository at this point in the history
  • Loading branch information
yisraelU committed Aug 22, 2024
1 parent 6aca4d1 commit 19c3f4a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ trait Client[F[_], K] {
def setClientName(name: K): F[Boolean]
def getClientName(): F[Option[K]]
def getClientId(): F[Long]
def getClientInfo: F[Map[String, String]]
def setLibName(name: String): F[Boolean]
def setLibVersion(version: String): F[Boolean]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,29 @@ private[redis4cats] class BaseRedis[F[_]: FutureLift: MonadThrow: Log, K, V](
override def getClientId(): F[Long] =
async.flatMap(_.clientId().futureLift.map(Long.unbox))

override def setLibName(name: String): F[Boolean] =
async.flatMap(_.clientSetinfo("LIB-NAME", name).futureLift.map(_ == "OK"))

override def setLibVersion(version: String): F[Boolean] =
async.flatMap(_.clientSetinfo("LIB-VER", version).futureLift.map(_ == "OK"))

override def getClientInfo: F[Map[String, String]] =
async.flatMap(
_.clientInfo().futureLift
.flatMap(parseClientInfo)
)

private def parseClientInfo(info: String): F[Map[String, String]] =
FutureLift[F].delay(
info
.replace("\n", "")
.split(" ")
.toList
.map(_.split("=", 2).toList)
.collect { case k :: v :: Nil => (k, v) }
.toMap
)

/******************************* Server API **********************************/
override val flushAll: F[Unit] =
async.flatMap(_.flushall().futureLift.void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ trait TestScenarios { self: FunSuite =>
newClientName <- redis.getClientName()
_ <- IO(assertEquals(newClientName, Some(clientName)))
_ <- redis.getClientId()
info <- redis.getClientInfo
_ <- IO(assert(info.nonEmpty))
success <- redis.setLibName("redis4cats")
_ <- IO(assert(success))
success <- redis.setLibVersion("0.10.0")
_ <- IO(assert(success))
info <- redis.getClientInfo
_ <- IO(assert(info.get("lib-name").contains("redis4cats")))
_ <- IO(assert(info.get("lib-ver").contains("0.10.0")))
} yield ()
}

Expand Down

0 comments on commit 19c3f4a

Please sign in to comment.