Skip to content

Instantly share code, notes, and snippets.

@guersam
Last active December 22, 2015 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guersam/6439112 to your computer and use it in GitHub Desktop.
Save guersam/6439112 to your computer and use it in GitHub Desktop.
package com.redis
package api
import akka.actor.ActorRef
trait RedisOps extends StringOperations
with ListOperations
with SetOperations
with SortedSetOperations
with HashOperations
with KeyOperations
with ServerOperations
with EvalOperations
with ConnectionOperations {
def clientRef: ActorRef
}
object RedisClient {
def apply(host: String, port: Int = 6379, name: String = defaultName,
settings: RedisClientSettings = RedisClientSettings())(implicit refFactory: ActorRefFactory): RedisClient =
apply(new InetSocketAddress(host, port), name, settings)
// More independent setting classes might be introduced for client, connection pool or cluster setup,
// but not sure of actual interface yet
def apply(remote: InetSocketAddress, name: String, settings: RedisClientSettings)
(implicit refFactory: ActorRefFactory): RedisClient =
new RedisClient(refFactory.actorOf(RedisConnection.props(remote, settings), name = name))
private def defaultName = "redis-client-" + nameSeq.next
private val nameSeq = Iterator from 0
}
class RedisClient(val clientRef: ActorRef) extends AnyVal with api.RedisOps
// Renamed from `RedisClient`.
// There might be multiple connections behind one `RedisClient`.
// Currently intended to have single TCP connection per instance, but could be changed IAW connection pool/cluster design.
object RedisConnection {
def props(remote: InetSocketAddress, settings: RedisClientSettings) = Props(classOf[RedisConnection], remote, settings)
}
/* private[redis]?? */ class RedisConnection(remote: InetSocketAddress, settings: RedisClientSettings) extends Actor with ActorLogging {
import Tcp._
import context.system
private[this] var pendingRequests = Queue.empty[RedisRequest]
IO(Tcp) ! Connect(remote)
// And so on...
}
@guersam
Copy link
Author

guersam commented Sep 4, 2013

If we don't have any client-wide settings, RedisClientSettings could be renamed to RedisConnectionSettings.

@guersam
Copy link
Author

guersam commented Sep 4, 2013

RedisClient also could be abstract, extended by concrete classes such as RedisClient.Single, RedisClient.Sentinel, or RedisClient.Cluster. Bringing them to top-level is also acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment