-
Notifications
You must be signed in to change notification settings - Fork 16
BlockingClient
Alexandre Curreli edited this page Jul 31, 2014
·
4 revisions
The BlockingClient
class represents a blocking Redis client. The major practical difference with blocking requests is that they return scala.util.Try
instead of scala.concurrent.Future
.
Note: the
BlockingClient
can only be used to issue blocking requests such as BRPOP.
- To send regular requests, use Client
- To subscribe to channels/patterns, use SubscriberClient
A BlockingClient
can be initialized similarly to a regular Client with the exception that receiveTimeout
cannot be set.
import scredis._
import akka.actor.ActorSystem
import scala.util.{ Success, Failure }
// Defines an actor system to use with the blocking client
implicit val system = ActorSystem("my-actor-system")
// Creates a blocking client with default configuration (see reference.conf)
val client = BlockingClient()
// Send a blocking request and match upon the result
client.brPop(timeoutSeconds = 5, "list") match {
case Success(Some((key, value))) => // do somethung with the popped value
case Success(None) => // there was no value to be popped
case Failure(e) => // an error occurred while processing the request
}