Skip to content

Commit aac1138

Browse files
author
Ben Buckman
committed
ShardClient blocks unnecessary static properties, more tests
1 parent 4db9c78 commit aac1138

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

lib/sharding.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ util.inherits(RedisShardingClient, events.EventEmitter);
5757
// meant purely for sanity check. avoid calling un-implemented methods in your app.
5858
RedisShardingClient.prototype.notYetImplemented = function NotSupported(command) {
5959
command = ("Command " + command).trim();
60-
throw new Error(command + " is not yet supported in RedisShardingClient.");
60+
throw new Error(command + " is not supported in RedisShardingClient.");
6161
};
6262

6363
// helper, and for testing: get index of client to use, based on key.
@@ -132,7 +132,8 @@ RedisShardingClient.prototype.waitForConnected = function waitForConnected() {
132132
};
133133

134134

135-
// not-yet-implemented methods throw an error.
135+
// not-yet-implemented methods throw an error
136+
// (everything not explicitly re-defined below, and some specific ones.)
136137
var unImplementedMethods = SingleClientCommands.concat([ 'end', 'send_command', 'server_info' ]);
137138
unImplementedMethods.forEach(function(command){
138139
RedisShardingClient.prototype[command] =
@@ -142,6 +143,18 @@ unImplementedMethods.forEach(function(command){
142143
});
143144

144145

146+
// not-yet-implemented static properties
147+
[ 'connection_id', 'connections', 'commands_sent', 'connect_timeout',
148+
'monitoring', 'closing', 'server_info', 'stream'
149+
].forEach(function(staticProp){
150+
RedisShardingClient.prototype.__defineGetter__(staticProp, function(){
151+
throw new Error("Property " + staticProp + " is not supported in RedisShardingClient.");
152+
});
153+
// == no need for setters ==
154+
});
155+
156+
157+
145158
// implement a subset of redis commands,
146159
// with a simpler input syntax.
147160
// throw errors on anything not supported.
@@ -260,9 +273,6 @@ RedisShardingClient.prototype.DBSIZE = function(callback) {
260273
};
261274

262275

263-
// @todo dbsize() should return aggregate size
264-
// @todo keys() should check all clients
265-
266276

267277

268278
// @TODO this is duplicated between sentinal and sharding, consolidate.

test/test_sharding.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,33 @@ describe('RedisShardingClient', function(){
528528

529529
});
530530

531+
532+
it('blocks unnecessary static properties', function(){
533+
[ 'connection_id', 'connections', 'commands_sent', 'connect_timeout',
534+
'monitoring', 'closing', 'server_info', 'stream'
535+
].forEach(function(staticProp){
536+
assert.throws(function(){
537+
var x = shardClient[staticProp];
538+
},
539+
/not supported/);
540+
});
541+
});
542+
543+
it('blocks unnecessary methods', function(){
544+
[
545+
// some by design
546+
'end', 'send_command', 'server_info',
547+
548+
// some @todo
549+
'watch', 'unwatch', 'migrate', 'dump', 'select', /* and lots more... */
550+
].forEach(function(command){
551+
assert.throws(function(){
552+
shardClient[command]();
553+
},
554+
/not supported/);
555+
});
556+
});
557+
531558
/*
532559
@todo
533560
'persist', 'lpop', 'rpop',
@@ -538,8 +565,6 @@ describe('RedisShardingClient', function(){
538565
'expire', 'expireat', 'pexpire', 'pexpireat'
539566
540567
'hset', 'hsetnx', 'hdel', 'hincrby', 'sadd', 'setex', 'psetex', 'srem', 'lpush', 'rpush'
541-
542-
connections, other static properties
543568
*/
544569

545570
});

0 commit comments

Comments
 (0)