Skip to content
This repository

Added authentication command to finagle-redis #78

Merged
merged 1 commit into from over 2 years ago

2 participants

Mairbek Khadikov marius a. eriksen
Mairbek Khadikov

Added auth method to finagle redis library.
Authentication is required to use Redis to Go on heroku.

marius a. eriksen mariusaeriksen merged commit 3c0a680 into from
marius a. eriksen
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 10, 2012
Mairbek Khadikov mairbek Added authentication command 110b565
This page is out of date. Refresh to see the latest.
8 finagle-redis/src/main/scala/com/twitter/finagle/redis/Client.scala
@@ -118,6 +118,14 @@ class Client(service: Service[Command, Reply]) {
118 118 }
119 119
120 120 /**
  121 + * Authorizes to db
  122 + */
  123 + def auth(token: String): Future[Unit] =
  124 + doRequest(Auth(token)) {
  125 + case StatusReply(message) => Future.Unit
  126 + }
  127 +
  128 + /**
121 129 * Select DB with specified zero-based index
122 130 * @param index
123 131 * @return Status reply
2  finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/Command.scala
@@ -64,6 +64,7 @@ object Commands {
64 64 // Miscellaneous
65 65 val FLUSHDB = "FLUSHDB"
66 66 val SELECT = "SELECT"
  67 + val AUTH = "AUTH"
67 68
68 69 // Hash Sets
69 70 val HDEL = "HDEL"
@@ -127,6 +128,7 @@ object Commands {
127 128 // miscellaneous
128 129 FLUSHDB -> {_ => FlushDB()},
129 130 SELECT -> {Select(_)},
  131 + AUTH -> {Auth(_)},
130 132
131 133 // hash sets
132 134 HDEL -> {HDel(_)},
11 finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/commands/Misc.scala
@@ -17,3 +17,14 @@ object Select {
17 17 case class Select(index: Int) extends Command {
18 18 def toChannelBuffer = RedisCodec.toInlineFormat(List(Commands.SELECT, index.toString))
19 19 }
  20 +
  21 +object Auth {
  22 + def apply(args: List[Array[Byte]]) = {
  23 + val list = trimList(args, 1, "AUTH")
  24 + new Auth(BytesToString(list(0)))
  25 + }
  26 +}
  27 +
  28 +case class Auth(code: String) extends Command {
  29 + def toChannelBuffer = RedisCodec.toInlineFormat(List(Commands.AUTH, code))
  30 +}

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.