Skip to content

BlockingClient

Alexandre Curreli edited this page Aug 18, 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.

Initialization

A BlockingClient can be initialized similarly to a regular Client with the exception that receiveTimeout cannot be set.

Full usage example

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 something with the popped value
  case Success(None) => // there was no value to be popped
  case Failure(e) => // an error occurred while processing the request
}
Clone this wiki locally