Skip to content

Commit 4d4da6f

Browse files
author
Ben Buckman
committed
RedisShardingClient: initial skeleton, updated readme
1 parent feb6c14 commit 4d4da6f

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ redis - a node.js redis client
33

44
This is a fork of [node_redis](https://github.com/mranney/node_redis), the complete Redis client for node.js.
55

6-
The purpose of this fork is to implement support for [Redis Sentinel](http://redis.io/topics/sentinel).
6+
The purpose of this fork is to:
77

8+
1. Implement support for [Redis Sentinel](http://redis.io/topics/sentinel) via a `RedisSentinalClient`.
9+
- See related thread: https://github.com/mranney/node_redis/issues/302
10+
2. Implement support for Redis sharding via a `RedisShardingClient`.
11+
- See related thread: https://github.com/mranney/node_redis/issues/116
812

9-
See related thread: https://github.com/mranney/node_redis/issues/302
1013

14+
# `RedisSentinelClient`
1115

12-
# Concept
16+
### Concepts
1317

14-
- `RedisSentinelClient`
15-
- connects to a single sentinel, which is watching a single master/slave(s) cluster
16-
- maintains an activeMasterClient in the background, automatically updates on failover (using psub)
17-
- behaves exactly like a single RedisClient
18-
- passes thru all client commands, behaves transparently like a `RedisClient`
18+
- connects to a single sentinel, which is watching a single master/slave(s) cluster
19+
- maintains an activeMasterClient in the background, automatically updates on failover (using psub)
20+
- behaves exactly like a single RedisClient
21+
- passes thru all client commands, behaves transparently like a `RedisClient`
1922

20-
# Usage
23+
### Usage
2124

2225
```
2326
var redis = require('redis');
@@ -26,20 +29,21 @@ var sentinelClient = redis.createClient(PORT, HOST, { sentinel: true });
2629

2730
Now use `sentinelClient` as a regular client: `set`, `get`, `hmset`, etc.
2831

29-
## Options
32+
### RedisSentinelClient Options
33+
3034
- `masterName`: Which master the sentinel is listening to. Defaults to 'mymaster'. (If a sentinel is listening to multiple masters, create multiple `RedisSentinelClients`.)
3135
- `logger`: pass in [winston](https://github.com/flatiron/winston) or another custom logger, otherwises uses console. (Expects a `log` method.)
3236
- `debug`: verbose output (to `logger` about internal ops)
3337

3438

35-
## RedisSentinelClient Methods
39+
### RedisSentinelClient Methods
3640

3741
- `getMaster()`: returns a reference to the sentinel client's `activeMasterClient` (also available directly)
3842
- `reconnect()`: used on instantiation and on psub events, this checks if the master has changed and connects to the new master.
3943
- `send_command()` (and any other `RedisClient` command): command is passed to the master client.
4044

4145

42-
## RedisSentinelClient Events
46+
### RedisSentinelClient Events
4347

4448
- `sentinel message` (`msg`): passed up from the sentinel's channel listener. Note, messages can be about other masters, does not differentiate.
4549
- `failover-start`: corresponds to sentinel's `+failover-triggered` message.
@@ -50,7 +54,7 @@ Now use `sentinelClient` as a regular client: `set`, `get`, `hmset`, etc.
5054
- `error` (`error`): An error occured. (Currently does not differentiate errors in different components.) Will fire errors during a failover, before new master is connected.
5155

5256

53-
# Limitations
57+
### RedisSentinelClient Limitations
5458

5559
- Unlike `RedisClient`, `RedisSentinelClient` is not / does not need to be a stream
5660
- Sentinel docs don't specify a default host+port, so option-less implementations of `createClient()` won't be compatible
@@ -59,8 +63,12 @@ Now use `sentinelClient` as a regular client: `set`, `get`, `hmset`, etc.
5963
- With non-atomic operations like pub/sub, your code needs to listen to `reconnect` events and reload its client.
6064

6165

62-
# Possible roadmap
66+
### Possible roadmap
6367

6468
- Multiple master/slave(s) clusters per sentinel
6569
- But thinking not: Just create multiple sentinel clients, one per cluster.
6670

71+
72+
# `RedisShardingClient`
73+
74+
To be continued...

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,12 @@ var Sentinel = require('./lib/sentinel');
11131113
exports.RedisSentinelClient = Sentinel.RedisSentinelClient;
11141114

11151115

1116+
// sharding client. instantiate separately.
1117+
var Sharding = require('./lib/sharding');
1118+
exports.RedisShardingClient = Sharding.RedisShardingClient;
1119+
1120+
1121+
11161122
exports.createClient = function (port_arg, host_arg, options) {
11171123
var redis_client;
11181124
var net_client;

lib/sharding.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
[Ben Buckman @ DocuSign]
3+
4+
Adds Redis sharding support, via RedisShardingClient.
5+
Modeled on the RedisSentinelClient (also added in our fork).
6+
7+
(see readme for notes)
8+
*/
9+
10+
var RedisSingleClient = require('../index'),
11+
events = require('events'),
12+
util = require('util'),
13+
reply_to_object = require('./utils').reply_to_object,
14+
commands = RedisSingleClient.commands,
15+
to_array = require('./to_array');
16+
17+
18+
function RedisShardingClient(options) {
19+
}
20+
21+
22+
exports.RedisShardingClient = RedisShardingClient;

0 commit comments

Comments
 (0)