1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Remove print helper

This commit is contained in:
Ruben Bridgewater
2016-12-17 17:19:13 +01:00
committed by Ruben Bridgewater
parent 47242b342a
commit ce3227dedd
9 changed files with 24 additions and 78 deletions

View File

@@ -25,9 +25,11 @@ client.on("error", function (err) {
console.log("Error " + err);
});
client.set("string key", "string val", redis.print);
client.hset("hash key", "hashtest 1", "some value", redis.print);
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
function callback () {}
client.set("string key", "string val", callback);
client.hset("hash key", "hashtest 1", "some value", callback);
client.hset(["hash key", "hashtest 2", "some other value"], callback);
client.hkeys("hash key", function (err, replies) {
console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
@@ -529,7 +531,7 @@ client.multi()
.keys("*", function (err, replies) {
// NOTE: code in this callback is NOT atomic
// this only happens after the the .exec call finishes.
client.mget(replies, redis.print);
client.mget(replies, console.log);
})
.dbsize()
.exec(function (err, replies) {
@@ -558,11 +560,11 @@ var redis = require("redis"),
// start a separate multi command queue
multi = client.multi();
multi.incr("incr thing", redis.print);
multi.incr("incr other thing", redis.print);
multi.incr("incr thing", console.log);
multi.incr("incr other thing", console.log);
// runs immediately
client.mset("incr thing", 100, "incr other thing", 1, redis.print);
client.mset("incr thing", 100, "incr other thing", 1, console.log);
// drains multi queue and runs atomically
multi.exec(function (err, replies) {
@@ -578,7 +580,7 @@ var redis = require("redis"),
client = redis.createClient(), multi;
client.multi([
["mget", "multifoo", "multibar", redis.print],
["mget", "multifoo", "multibar", console.log],
["incr", "multifoo"],
["incr", "multibar"]
]).exec(function (err, replies) {
@@ -639,27 +641,6 @@ The `versions` key contains an array of the elements of the version string for e
> client.server_info.versions
[ 2, 3, 0 ]
## redis.print()
A handy callback function for displaying return values when testing. Example:
```js
var redis = require("redis"),
client = redis.createClient();
client.on("connect", function () {
client.set("foo_rand000000000000", "some fantastic value", redis.print);
client.get("foo_rand000000000000", redis.print);
});
```
This will print:
Reply: OK
Reply: some fantastic value
Note that this program will not exit cleanly because the client is still connected.
## Multi-word commands
To execute redis multi-word commands like `SCRIPT LOAD` or `CLIENT LIST` pass

View File

@@ -19,7 +19,7 @@ fs.readFile(filename, function (err, data) {
if (err) throw err;
console.log('Read ' + data.length + ' bytes from filesystem.');
client.set(filename, data, redis.print); // set entire file
client.set(filename, data, console.log); // set entire file
client.get(filename, function (err, reply) { // get entire file
if (err) {
console.log('Get error: ' + err);

View File

@@ -17,7 +17,7 @@ client.multi()
.scard('bigset')
.smembers('bigset')
.keys('*', function (err, replies) {
client.mget(replies, redis.print);
client.mget(replies, console.log);
})
.dbsize()
.exec(function (err, replies) {
@@ -27,15 +27,15 @@ client.multi()
});
});
client.mset('incr thing', 100, 'incr other thing', 1, redis.print);
client.mset('incr thing', 100, 'incr other thing', 1, console.log);
// start a separate multi command queue
var multi = client.multi();
multi.incr('incr thing', redis.print);
multi.incr('incr other thing', redis.print);
multi.incr('incr thing', console.log);
multi.incr('incr other thing', console.log);
// runs immediately
client.get('incr thing', redis.print); // 100
client.get('incr thing', console.log); // 100
// drains multi queue and runs atomically
multi.exec(function (err, replies) {

View File

@@ -5,11 +5,11 @@ var client = redis.createClient();
// start a separate command queue for multi
var multi = client.multi();
multi.incr('incr thing', redis.print);
multi.incr('incr other thing', redis.print);
multi.incr('incr thing', console.log);
multi.incr('incr other thing', console.log);
// runs immediately
client.mset('incr thing', 100, 'incr other thing', 1, redis.print);
client.mset('incr thing', 100, 'incr other thing', 1, console.log);
// drains multi queue and runs atomically
multi.exec(function (err, replies) {
@@ -23,7 +23,7 @@ multi.exec(function (err, replies) {
});
client.multi([
['mget', 'multifoo', 'multibar', redis.print],
['mget', 'multifoo', 'multibar', console.log],
['incr', 'multifoo'],
['incr', 'multibar']
]).exec(function (err, replies) {

View File

@@ -7,9 +7,9 @@ client.on('error', function (err) {
console.log('error event - ' + client.host + ':' + client.port + ' - ' + err);
});
client.set('string key', 'string val', redis.print);
client.hset('hash key', 'hashtest 1', 'some value', redis.print);
client.hset(['hash key', 'hashtest 2', 'some other value'], redis.print);
client.set('string key', 'string val', console.log);
client.hset('hash key', 'hashtest 1', 'some value', console.log);
client.hset(['hash key', 'hashtest 2', 'some other value'], console.log);
client.hkeys('hash key', function (err, replies) {
if (err) {
return console.error('error response - ' + err);

View File

@@ -15,5 +15,5 @@ client.set('object_1', 'foo');
client.set('object_2', 'bar');
client.set('object_3', 'qux');
client.sort('mylist', 'by', 'weight_*', 'get', 'object_*', redis.print);
client.sort('mylist', 'by', 'weight_*', 'get', 'object_*', console.log);
// Prints Reply: qux,foo,bar

View File

@@ -1084,7 +1084,6 @@ exports.createClient = function () {
return new RedisClient(unifyOptions.apply(null, arguments));
};
exports.RedisClient = RedisClient;
exports.print = utils.print;
exports.Multi = require('./lib/multi');
exports.AbortError = errorClasses.AbortError;
exports.RedisError = Parser.RedisError;

View File

@@ -30,15 +30,6 @@ function replyToStrings (reply) {
return reply;
}
function print (err, reply) {
if (err) {
// A error always begins with Error:
console.log(err.toString());
} else {
console.log('Reply: ' + reply);
}
}
var camelCase;
// Deep clone arbitrary objects with arrays. Can't handle cyclic structures (results in a range error)
// Any attribute with a non primitive value besides object and array will be passed by reference (e.g. Buffers, Maps, Functions)
@@ -125,7 +116,6 @@ function replyInOrder (self, callback, err, res, queue) {
module.exports = {
reply_to_strings: replyToStrings,
reply_to_object: replyToObject,
print: print,
err_code: /^([A-Z]+)\s+(.+)$/,
monitor_regex: /^[0-9]{10,11}\.[0-9]+ \[[0-9]+ .+\]( ".+?")+$/,
clone: convenienceClone,

View File

@@ -60,30 +60,6 @@ describe('utils.js', function () {
});
});
describe('print helper', function () {
it('callback with reply', function () {
var text = '';
var unhookIntercept = intercept(function (data) {
text += data;
return '';
});
utils.print(null, 'abc');
unhookIntercept();
assert.strictEqual(text, 'Reply: abc\n');
});
it('callback with error', function () {
var text = '';
var unhookIntercept = intercept(function (data) {
text += data;
return '';
});
utils.print(new Error('Wonderful exception'));
unhookIntercept();
assert.strictEqual(text, 'Error: Wonderful exception\n');
});
});
describe('reply_in_order', function () {
var err_count = 0;