Skip to content

Commit

Permalink
Merge pull request #427 from mmienko/auth-command
Browse files Browse the repository at this point in the history
Add auth command
  • Loading branch information
gvolpe authored Dec 5, 2020
2 parents 946fa13 + b0bdc61 commit de7654e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@

package dev.profunktor.redis4cats.algebra

trait ConnectionCommands[F[_]] extends Ping[F]
trait ConnectionCommands[F[_]] extends Ping[F] with Auth[F]

trait Ping[F[_]] {
def ping: F[String]
def select(index: Int): F[Unit]
}

trait Auth[F[_]] {
def auth(password: CharSequence): F[Boolean]
def auth(username: String, password: CharSequence): F[Boolean]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,18 @@ private[redis4cats] class BaseRedis[F[_]: Concurrent: ContextShift: Log, K, V](
override def select(index: Int): F[Unit] =
conn.async.flatMap(c => blocker.delay(c.select(index))).void

override def auth(password: CharSequence): F[Boolean] =
async
.flatMap(c => F.delay(c.auth(password)))
.futureLift
.map(_ == "OK")

override def auth(username: String, password: CharSequence): F[Boolean] =
async
.flatMap(c => F.delay(c.auth(username, password)))
.futureLift
.map(_ == "OK")

/******************************* Server API **********************************/
override val flushAll: F[Unit] =
async.flatMap(c => F.delay(c.flushall())).futureLift.void
Expand Down

0 comments on commit de7654e

Please sign in to comment.