3 import com.redis.operations._
10 import scala.collection.mutable.ArrayBuffer
12 class RedisCluster(val hosts: String*) extends Operations with ListOperations with SetOperations with HashRing with SortOperations {
14 // Get Redis Client connection inside the HashRing.
15 def getConnection(key: String) = {
16 getNode(key).connection
19 // Default value used on MemCache client.
20 private val NUMBER_OF_REPLICAS = 160
21 val replicas = NUMBER_OF_REPLICAS
23 // Outputs a formatted representation of the Redis server.
24 override def toString = cluster.mkString(", ")
26 // Connect the client and add it to the cluster.
27 def connectClient(host: String): Boolean = {
28 val h = host.split(":")(0)
29 val p = host.split(":")(1)
30 val client = new Redis(h.toString, p.toString.toInt)
35 // Connect all clients in the cluster.
36 def connect = cluster.map(c => c.connect)
38 // Initialize cluster.
39 def initialize_cluster = hosts.map(connectClient(_))