Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the MOVE command to finagle-redis. #267

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ trait Keys { self: BaseClient =>
case EmptyMBulkReply() => Future.Nil
}

/**
* Move key from the currently selected database to the specified destination
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one space after the *

* database. When key already exists in the destination database, or it does
* not exist in the source database, it does nothing.
*
* @param key, db
* @return true if key was moved.
* false if key was not moved for any reason.
* @see http://redis.io/commands/move
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is implicit. If you think it's useful to point out in the scaladocs that users can find more details in the redis protocol documentation, let's just stick it in a package.scala file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not biased in any direction here - from looking through the *Command.scala files for guidance, I saw what seemed to be a bit of a mixed bag on the scaladocs. There was one usage of @see but it wasn't consistent.

Me personally, I figure if someone is using a redis driver they know what the Redis Command is, so I would simply do something like this

   /**
    * Move key from the currently selected database to the specified destination
    * database. When key already exists in the destination database, or it does
    * not exist in the source database, it does nothing.
    *
    * @param key, db
    * @return true if key was moved.
    *               false if key was not moved for any reason.
  */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop it then. 🤘

*/
def move(key: ChannelBuffer, db: ChannelBuffer): Future[JBoolean] =
doRequest(Move(key,db)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be: Move(key, db)

case IntegerReply(n) => Future.value(n == 1)
}

/**
* Set a key's time to live in milliseconds.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object Commands {
val EXPIRE = "EXPIRE"
val EXPIREAT = "EXPIREAT"
val KEYS = "KEYS"
val MOVE = "MOVE"
val PERSIST = "PERSIST"
val PEXPIRE = "PEXPIRE"
val PEXPIREAT = "PEXPIREAT"
Expand Down Expand Up @@ -140,6 +141,7 @@ object Commands {
EXPIRE -> {Expire(_)},
EXPIREAT -> {ExpireAt(_)},
KEYS -> {Keys(_)},
MOVE -> {Move(_)},
PERSIST -> {Persist(_)},
PEXPIRE -> {PExpire(_)},
PEXPIREAT -> {PExpireAt(_)},
Expand Down Expand Up @@ -269,11 +271,13 @@ object Commands {
}

object CommandBytes {
// Key Commands
val DEL = StringToChannelBuffer("DEL")
val EXISTS = StringToChannelBuffer("EXISTS")
val EXPIRE = StringToChannelBuffer("EXPIRE")
val EXPIREAT = StringToChannelBuffer("EXPIREAT")
val KEYS = StringToChannelBuffer("KEYS")
val MOVE = StringToChannelBuffer("MOVE")
val PERSIST = StringToChannelBuffer("PERSIST")
val PEXPIRE = StringToChannelBuffer("PEXPIRE")
val PEXPIREAT = StringToChannelBuffer("PEXPIREAT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ object Keys {
def apply(args: Seq[Array[Byte]]) = new Keys(ChannelBuffers.wrappedBuffer(args.head))
}

case class Move(key: ChannelBuffer, db: ChannelBuffer) extends StrictKeyCommand {
def command = Commands.MOVE
RequireClientProtocol(db != null && db.readableBytes > 0, "Database must be specified")
def toChannelBuffer =
RedisCodec.toUnifiedFormat(Seq(CommandBytes.MOVE, key, db))
}
object Move {
def apply(args: Seq[Array[Byte]]) = {
val list = trimList(args, 2, "MOVE")
new Move(ChannelBuffers.wrappedBuffer(list(0)),
ChannelBuffers.wrappedBuffer(list(1)))
}
}

case class Persist(key: ChannelBuffer) extends StrictKeyCommand {
def command = Commands.PERSIST
def toChannelBuffer = RedisCodec.toUnifiedFormat(Seq(CommandBytes.PERSIST, key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class NaggatiSpec extends SpecificationWithJUnit {
"KEYS" >> {
codec(wrap("KEYS h?llo\r\n")) mustEqual List(Keys("h?llo"))
}
"MOVE" >> {
codec(wrap("MOVE\r\n")) must throwA[ClientError]
codec(wrap("MOVE boo\r\n")) must throwA[ClientError]
codec(wrap("MOVE boo moo \r\n")) mustEqual List(Move(boo, moo))
}
"PERSIST" >> {
codec(wrap("PERSIST\r\n")) must throwA[ClientError]
codec(wrap("PERSIST foo\r\n")) mustEqual List(Persist("foo"))
Expand Down