Skip to content

Commit

Permalink
[split] Future.Nil Like Future.None, Future.Nil can be used anytime y…
Browse files Browse the repository at this point in the history
…ou need a Future[Seq[_]] with an empty sequence. Using this rather than always creating a new Future can save a tiny bit on garbage generation, plus makes the code marginally easier to read. I've done a search-and-replace in a few select projects to use the new constant.

RB_ID=133413
  • Loading branch information
Jeremy Cloud authored and CI committed Mar 20, 2013
1 parent 450001b commit f833c7e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class MockClient(val map: mutable.Map[String, ChannelBuffer]) extends Client {
def decr(key: String, delta: Long): Future[Option[JLong]] =
incr(key, -delta)

def stats(args: Option[String]): Future[Seq[String]] = Future.value(Nil)
def stats(args: Option[String]): Future[Seq[String]] = Future.Nil

def release() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ trait BtreeSortedSetCommands { self: BaseClient =>
doRequest(BRange(key, startField, endField)) {
case MBulkReply(messages) => Future.value(
returnPairs(ReplyFormat.toChannelBuffers(messages)))
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private[redis] class ConnectedTransactionalClient(
private def exec(svc: Service[Command, Reply]): Future[Seq[Reply]] =
svc(Exec) flatMap {
case MBulkReply(messages) => Future.value(messages)
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
case NilMBulkReply() => Future.exception(
new ServerError("One or more keys were modified before transaction"))
case ErrorReply(message) => Future.exception(new ServerError(message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ trait Hashes { self: BaseClient =>
doRequest(HGetAll(key)) {
case MBulkReply(messages) => Future.value(
returnPairs(ReplyFormat.toChannelBuffers(messages)))
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
}

/**
Expand All @@ -51,7 +51,7 @@ trait Hashes { self: BaseClient =>
doRequest(HKeys(key)) {
case MBulkReply(messages) => Future.value(
ReplyFormat.toChannelBuffers(messages))
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
}

/**
Expand All @@ -63,7 +63,7 @@ trait Hashes { self: BaseClient =>
doRequest(HMGet(key, fields)) {
case MBulkReply(messages) => Future.value(
ReplyFormat.toChannelBuffers(messages))
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
}

/**
Expand All @@ -86,7 +86,7 @@ trait Hashes { self: BaseClient =>
): Future[Seq[ChannelBuffer]] =
doRequest(HScan(key, cursor, count, pattern)) {
case MBulkReply(messages) => Future.value(ReplyFormat.toChannelBuffers(messages))
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ trait Keys { self: BaseClient =>
def keys(pattern: ChannelBuffer): Future[Seq[ChannelBuffer]] =
doRequest(Keys(pattern)) {
case MBulkReply(messages) => Future.value(ReplyFormat.toChannelBuffers(messages))
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
}

/**
Expand All @@ -71,7 +71,7 @@ trait Keys { self: BaseClient =>
): Future[Seq[ChannelBuffer]] =
doRequest(Scan(cursor, count, pattern)) {
case MBulkReply(messages) => Future.value(ReplyFormat.toChannelBuffers(messages))
case EmptyMBulkReply() => Future.value(Seq())
case EmptyMBulkReply() => Future.Nil
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ trait Strings { self: BaseClient =>
case _ => throw new IllegalStateException()
} toSeq
}
case EmptyMBulkReply() => Future.value(Seq.empty)
case EmptyMBulkReply() => Future.Nil
}

/**
Expand Down

0 comments on commit f833c7e

Please sign in to comment.