From ce3227deddf834d3d255106404385da291da16f9 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Dec 2016 17:19:13 +0100 Subject: [PATCH] Remove print helper --- README.md | 39 ++++++++++----------------------------- examples/file.js | 2 +- examples/multi.js | 10 +++++----- examples/multi2.js | 8 ++++---- examples/simple.js | 6 +++--- examples/sort.js | 2 +- index.js | 1 - lib/utils.js | 10 ---------- test/utils.spec.js | 24 ------------------------ 9 files changed, 24 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 8109a7679d..71cf7e15ae 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/file.js b/examples/file.js index 0bacd723b3..9c74c89ed8 100644 --- a/examples/file.js +++ b/examples/file.js @@ -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); diff --git a/examples/multi.js b/examples/multi.js index e0e3bf13fc..8680d4a817 100644 --- a/examples/multi.js +++ b/examples/multi.js @@ -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) { diff --git a/examples/multi2.js b/examples/multi2.js index 3a0ceaec6a..71bde7b9ad 100644 --- a/examples/multi2.js +++ b/examples/multi2.js @@ -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) { diff --git a/examples/simple.js b/examples/simple.js index 2fc2c3aefb..8df8fcbc0a 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -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); diff --git a/examples/sort.js b/examples/sort.js index b09b06fbbf..eb6d287345 100644 --- a/examples/sort.js +++ b/examples/sort.js @@ -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 diff --git a/index.js b/index.js index 2b93b5aa56..770828ae95 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/lib/utils.js b/lib/utils.js index 52e58ecfa6..aa7d49b510 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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, diff --git a/test/utils.spec.js b/test/utils.spec.js index e036d84167..f8639dbc57 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -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;