You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is important; if your Brando actor restarts you want be sure it reconnects successfully and to the same database.
30
+
This is important; if your Redis actor restarts you want be sure it reconnects successfully and to the same database.
31
31
32
32
Next, send it a command and get your response as a reply.
33
33
@@ -47,7 +47,7 @@ Error replies are returned as `akka.actor.Status.Failure` objects containing an
47
47
48
48
redis ! Request("EXPIRE", "1", "key")
49
49
50
-
// Response: Failure(brando.BrandoException: ERR value is not an integer or out of range)
50
+
// Response: Failure(brando.RedisException: ERR value is not an integer or out of range)
51
51
52
52
Integer replies are returned as `Option[Long]`.
53
53
@@ -75,7 +75,7 @@ NULL replies are returned as `None` and may appear either on their own or nested
75
75
76
76
If you're not sure what to expect in response to a request, please refer to the Redis command documentation at [http://redis.io/commands](http://redis.io/commands) where the reply type for each is clearly stated.
77
77
78
-
To ensure that a list of requests are executed back to back, the brando actor can receive the following message :
78
+
To ensure that a list of requests are executed back to back, the Redis actor can receive the following message :
@@ -106,28 +106,65 @@ Use the provided response extractors to map your Redis reply to a more appropria
106
106
107
107
### Monitoring Connection State Changes
108
108
109
-
If a set of listeners is provided to the Brando actor when it is created , it will inform the those listeners about state changes to the underlying Redis connection. For example (from inside an actor):
109
+
If a set of listeners is provided to the Redis actor when it is created , it will inform the those listeners about state changes to the underlying Redis connection. For example (from inside an actor):
110
110
111
-
val redis = context.actorOf(Brando("localhost", 6379, listeners = Set(self)))
111
+
val redis = context.actorOf(Redis("localhost", 6379, listeners = Set(self)))
112
112
113
113
Currently, the possible messages sent to each listener include the following:
114
114
115
+
*`Connecting`: When creating a TCP connection.
115
116
*`Connected`: When a TCP connection has been created, and Authentication (if applicable) has succeeded.
116
-
*`Disconnected`: The connection has been lost. Brando transparently handles disconnects and will automatically reconnect, so typically no user action at all is needed here. During the time that Brando is disconnected, Redis commands sent to Brando will be queued, and will be processed when a connection is established.
117
+
*`Disconnected`: The connection has been lost. Redis transparently handles disconnects and will automatically reconnect, so typically no user action at all is needed here. During the time that Redis is disconnected, Redis commands sent will be queuedbe processed once the connection is reestablished.
117
118
*`AuthenticationFailed`: The TCP connected was made, but Redis auth failed.
118
-
*`ConnectionFailed`: A connection could not be (re-) established after three attempts. Brando will not attempt to recover from this state; the user should take action.
119
+
*`ConnectionFailed`: A connection could not be established after the number of attempts defined during creation `connectionRetryAttempts`. Brando will not attempt to recover from this state; the user should take action.
119
120
120
-
All these messages inherit from the `BrandoStateChange` trait.
121
+
All these messages inherit from the `Connection.StateChange` trait.
122
+
123
+
124
+
### Sentinel
125
+
126
+
#### Sentinel Client
127
+
128
+
Sentinel provides support for `monitoring`, `notification` and `automatic failover` using [sentinel](http://redis.io/topics/sentinel). It is implemented based on the following [guidelines](http://redis.io/topics/sentinel-clients) and requires redis 2.8.12 or later.
129
+
130
+
A sentinel client can be created like this. Here, we are using two servers and we provide a listener to receive `Connection.StateChange` events.
Redis can be used with Sentinel to provide automatic failover and discovery. To do so you need to create a `Sentinel` and a `RedisSentinel` actor. In this example we are connecting to the master `mymaster`
148
+
149
+
val sentinel = system.actorOf(Sentinel(Seq(
150
+
Server("localhost", 26380),
151
+
Server("localhost", 26379))))
152
+
153
+
val redis = system.actorOf(RedisSentinel("mymaster", sentinel))
154
+
155
+
redis ! Request("PING")
156
+
157
+
For reliability we encourage to pass `connectionHeartbeatDelay` when using RedisSentinel, this will generate a heartbeat to Redis and will improve failures detections in the case of network partitions.
121
158
122
159
### Sharding
123
160
124
161
Brando provides support for sharding, as outlined [in the Redis documentation](http://redis.io/topics/partitioning) and in [this blog post from antirez](http://oldblog.antirez.com/post/redis-presharding.html).
125
162
126
-
To use it, simply create an instance of `ShardManager`, passing it a list of Redis shards you'd like it to connect to. From there, we create a pool of `Brando` instances - one for each shard.
163
+
To use it, simply create an instance of `ShardManager`, passing it a list of Redis shards you'd like it to connect to. From there, we create a pool of `Redis` instances - one for each shard.
127
164
128
-
val shards = Seq(Shard("redis1", "10.0.0.1", 6379),
129
-
Shard("redis2", "10.0.0.2", 6379),
130
-
Shard("redis3", "10.0.0.3", 6379))
165
+
val shards = Seq(RedisShard("redis1", "10.0.0.1", 6379),
166
+
RedisShard("redis2", "10.0.0.2", 6379),
167
+
RedisShard("redis3", "10.0.0.3", 6379))
131
168
132
169
val shardManager = context.actorOf(ShardManager(shards))
133
170
@@ -147,19 +184,46 @@ Note that the `ShardManager` explicitly requires a key for all operations except
147
184
148
185
Individual shards can have their configuration updated on the fly. To do this, send a `Shard` message to `ShardManager`.
This is intended to support failover via [Redis Sentinel](http://redis.io/topics/sentinel). Note that the id of the shard __MUST__ match one of the original shards configured when the `ShardManager` instance was created. Adding new shards is not supported.
State changes such as disconnects and connection failures can be monitored by providing a set of listeners to the `ShardManager`:
219
+
* Run the tests
155
220
156
-
val shardManager = context.actorOf(ShardManager(shards, listeners = Set(self)))
221
+
sbt test
157
222
158
-
The `ShardManager` will send a `ShardStateChange(shard, state)` message when a shard changes state; here `shard` is a shard object indicating which shard has changed state, and `state` is a `BrandoStateChange` object, documented above, indicating which new state the shard has entered.
159
223
160
224
## Documentation
161
225
162
-
Read the API documentation here: [http://chrisdinn.github.io/api/brando-2.1.2/](http://chrisdinn.github.io/api/brando-2.1.2/)
226
+
Read the API documentation here: [http://chrisdinn.github.io/api/brando-3.0.0-SNAPSHOT/](http://chrisdinn.github.io/api/brando-3.0.0-SNAPSHOT/)
0 commit comments