Last active
December 22, 2015 07:38
-
-
Save guersam/6439112 to your computer and use it in GitHub Desktop.
Suggestion for https://github.com/debasishg/scala-redis-nb/issues/49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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... | |
} |
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
If we don't have any client-wide settings,
RedisClientSettings
could be renamed toRedisConnectionSettings
.