redis 0.10.2 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.npmignore +8 -2
  2. package/README.md +12 -22
  3. package/connection_breaker.js +80 -0
  4. package/index.js +109 -30
  5. package/lib/commands.js +9 -1
  6. package/package.json +1 -1
  7. package/benches/buffer_bench.js +0 -89
  8. package/benches/hiredis_parser.js +0 -38
  9. package/benches/re_sub_test.js +0 -14
  10. package/benches/reconnect_test.js +0 -29
  11. package/benches/stress/codec.js +0 -16
  12. package/benches/stress/pubsub/pub.js +0 -38
  13. package/benches/stress/pubsub/run +0 -10
  14. package/benches/stress/pubsub/server.js +0 -23
  15. package/benches/stress/rpushblpop/pub.js +0 -49
  16. package/benches/stress/rpushblpop/run +0 -6
  17. package/benches/stress/rpushblpop/server.js +0 -30
  18. package/benches/stress/speed/00 +0 -13
  19. package/benches/stress/speed/plot +0 -13
  20. package/benches/stress/speed/size-rate.png +0 -0
  21. package/benches/stress/speed/speed.js +0 -84
  22. package/benches/sub_quit_test.js +0 -18
  23. package/changelog.md +0 -316
  24. package/diff_multi_bench_output.js +0 -90
  25. package/examples/auth.js +0 -5
  26. package/examples/backpressure_drain.js +0 -33
  27. package/examples/eval.js +0 -14
  28. package/examples/extend.js +0 -24
  29. package/examples/file.js +0 -32
  30. package/examples/mget.js +0 -5
  31. package/examples/monitor.js +0 -10
  32. package/examples/multi.js +0 -46
  33. package/examples/multi2.js +0 -29
  34. package/examples/psubscribe.js +0 -33
  35. package/examples/pub_sub.js +0 -41
  36. package/examples/simple.js +0 -24
  37. package/examples/sort.js +0 -17
  38. package/examples/subqueries.js +0 -15
  39. package/examples/subquery.js +0 -19
  40. package/examples/unix_socket.js +0 -29
  41. package/examples/web_server.js +0 -31
  42. package/generate_commands.js +0 -39
  43. package/multi_bench.js +0 -222
  44. package/test-unref.js +0 -12
  45. package/test.js +0 -2257
package/examples/auth.js DELETED
@@ -1,5 +0,0 @@
1
- var redis = require("redis"),
2
- client = redis.createClient();
3
-
4
- // This command is magical. Client stashes the password and will issue on every connect.
5
- client.auth("somepass");
@@ -1,33 +0,0 @@
1
- var redis = require("../index"),
2
- client = redis.createClient(null, null, {
3
- command_queue_high_water: 5,
4
- command_queue_low_water: 1
5
- }),
6
- remaining_ops = 100000, paused = false;
7
-
8
- function op() {
9
- if (remaining_ops <= 0) {
10
- console.error("Finished.");
11
- process.exit(0);
12
- }
13
-
14
- remaining_ops--;
15
- if (client.hset("test hash", "val " + remaining_ops, remaining_ops) === false) {
16
- console.log("Pausing at " + remaining_ops);
17
- paused = true;
18
- } else {
19
- process.nextTick(op);
20
- }
21
- }
22
-
23
- client.on("drain", function () {
24
- if (paused) {
25
- console.log("Resuming at " + remaining_ops);
26
- paused = false;
27
- process.nextTick(op);
28
- } else {
29
- console.log("Got drain while not paused at " + remaining_ops);
30
- }
31
- });
32
-
33
- op();
package/examples/eval.js DELETED
@@ -1,14 +0,0 @@
1
- var redis = require("../index"),
2
- client = redis.createClient();
3
-
4
- redis.debug_mode = true;
5
-
6
- client.eval("return 100.5", 0, function (err, res) {
7
- console.dir(err);
8
- console.dir(res);
9
- });
10
-
11
- client.eval([ "return 100.5", 0 ], function (err, res) {
12
- console.dir(err);
13
- console.dir(res);
14
- });
@@ -1,24 +0,0 @@
1
- var redis = require("redis"),
2
- client = redis.createClient();
3
-
4
- // Extend the RedisClient prototype to add a custom method
5
- // This one converts the results from "INFO" into a JavaScript Object
6
-
7
- redis.RedisClient.prototype.parse_info = function (callback) {
8
- this.info(function (err, res) {
9
- var lines = res.toString().split("\r\n").sort();
10
- var obj = {};
11
- lines.forEach(function (line) {
12
- var parts = line.split(':');
13
- if (parts[1]) {
14
- obj[parts[0]] = parts[1];
15
- }
16
- });
17
- callback(obj)
18
- });
19
- };
20
-
21
- client.parse_info(function (info) {
22
- console.dir(info);
23
- client.quit();
24
- });
package/examples/file.js DELETED
@@ -1,32 +0,0 @@
1
- // Read a file from disk, store it in Redis, then read it back from Redis.
2
-
3
- var redis = require("redis"),
4
- client = redis.createClient(),
5
- fs = require("fs"),
6
- filename = "kids_in_cart.jpg";
7
-
8
- // Get the file I use for testing like this:
9
- // curl http://ranney.com/kids_in_cart.jpg -o kids_in_cart.jpg
10
- // or just use your own file.
11
-
12
- // Read a file from fs, store it in Redis, get it back from Redis, write it back to fs.
13
- fs.readFile(filename, function (err, data) {
14
- if (err) throw err
15
- console.log("Read " + data.length + " bytes from filesystem.");
16
-
17
- client.set(filename, data, redis.print); // set entire file
18
- client.get(filename, function (err, reply) { // get entire file
19
- if (err) {
20
- console.log("Get error: " + err);
21
- } else {
22
- fs.writeFile("duplicate_" + filename, reply, function (err) {
23
- if (err) {
24
- console.log("Error on write: " + err)
25
- } else {
26
- console.log("File written.");
27
- }
28
- client.end();
29
- });
30
- }
31
- });
32
- });
package/examples/mget.js DELETED
@@ -1,5 +0,0 @@
1
- var client = require("redis").createClient();
2
-
3
- client.mget(["sessions started", "sessions started", "foo"], function (err, res) {
4
- console.dir(res);
5
- });
@@ -1,10 +0,0 @@
1
- var client = require("../index").createClient(),
2
- util = require("util");
3
-
4
- client.monitor(function (err, res) {
5
- console.log("Entering monitoring mode.");
6
- });
7
-
8
- client.on("monitor", function (time, args) {
9
- console.log(time + ": " + util.inspect(args));
10
- });
package/examples/multi.js DELETED
@@ -1,46 +0,0 @@
1
- var redis = require("redis"),
2
- client = redis.createClient(), set_size = 20;
3
-
4
- client.sadd("bigset", "a member");
5
- client.sadd("bigset", "another member");
6
-
7
- while (set_size > 0) {
8
- client.sadd("bigset", "member " + set_size);
9
- set_size -= 1;
10
- }
11
-
12
- // multi chain with an individual callback
13
- client.multi()
14
- .scard("bigset")
15
- .smembers("bigset")
16
- .keys("*", function (err, replies) {
17
- client.mget(replies, redis.print);
18
- })
19
- .dbsize()
20
- .exec(function (err, replies) {
21
- console.log("MULTI got " + replies.length + " replies");
22
- replies.forEach(function (reply, index) {
23
- console.log("Reply " + index + ": " + reply.toString());
24
- });
25
- });
26
-
27
- client.mset("incr thing", 100, "incr other thing", 1, redis.print);
28
-
29
- // start a separate multi command queue
30
- var multi = client.multi();
31
- multi.incr("incr thing", redis.print);
32
- multi.incr("incr other thing", redis.print);
33
-
34
- // runs immediately
35
- client.get("incr thing", redis.print); // 100
36
-
37
- // drains multi queue and runs atomically
38
- multi.exec(function (err, replies) {
39
- console.log(replies); // 101, 2
40
- });
41
-
42
- // you can re-run the same transaction if you like
43
- multi.exec(function (err, replies) {
44
- console.log(replies); // 102, 3
45
- client.quit();
46
- });
@@ -1,29 +0,0 @@
1
- var redis = require("redis"),
2
- client = redis.createClient(), multi;
3
-
4
- // start a separate command queue for multi
5
- multi = client.multi();
6
- multi.incr("incr thing", redis.print);
7
- multi.incr("incr other thing", redis.print);
8
-
9
- // runs immediately
10
- client.mset("incr thing", 100, "incr other thing", 1, redis.print);
11
-
12
- // drains multi queue and runs atomically
13
- multi.exec(function (err, replies) {
14
- console.log(replies); // 101, 2
15
- });
16
-
17
- // you can re-run the same transaction if you like
18
- multi.exec(function (err, replies) {
19
- console.log(replies); // 102, 3
20
- client.quit();
21
- });
22
-
23
- client.multi([
24
- ["mget", "multifoo", "multibar", redis.print],
25
- ["incr", "multifoo"],
26
- ["incr", "multibar"]
27
- ]).exec(function (err, replies) {
28
- console.log(replies.toString());
29
- });
@@ -1,33 +0,0 @@
1
- var redis = require("redis"),
2
- client1 = redis.createClient(),
3
- client2 = redis.createClient(),
4
- client3 = redis.createClient(),
5
- client4 = redis.createClient(),
6
- msg_count = 0;
7
-
8
- redis.debug_mode = false;
9
-
10
- client1.on("psubscribe", function (pattern, count) {
11
- console.log("client1 psubscribed to " + pattern + ", " + count + " total subscriptions");
12
- client2.publish("channeltwo", "Me!");
13
- client3.publish("channelthree", "Me too!");
14
- client4.publish("channelfour", "And me too!");
15
- });
16
-
17
- client1.on("punsubscribe", function (pattern, count) {
18
- console.log("client1 punsubscribed from " + pattern + ", " + count + " total subscriptions");
19
- client4.end();
20
- client3.end();
21
- client2.end();
22
- client1.end();
23
- });
24
-
25
- client1.on("pmessage", function (pattern, channel, message) {
26
- console.log("("+ pattern +")" + " client1 received message on " + channel + ": " + message);
27
- msg_count += 1;
28
- if (msg_count === 3) {
29
- client1.punsubscribe();
30
- }
31
- });
32
-
33
- client1.psubscribe("channel*");
@@ -1,41 +0,0 @@
1
- var redis = require("redis"),
2
- client1 = redis.createClient(), msg_count = 0,
3
- client2 = redis.createClient();
4
-
5
- redis.debug_mode = false;
6
-
7
- // Most clients probably don't do much on "subscribe". This example uses it to coordinate things within one program.
8
- client1.on("subscribe", function (channel, count) {
9
- console.log("client1 subscribed to " + channel + ", " + count + " total subscriptions");
10
- if (count === 2) {
11
- client2.publish("a nice channel", "I am sending a message.");
12
- client2.publish("another one", "I am sending a second message.");
13
- client2.publish("a nice channel", "I am sending my last message.");
14
- }
15
- });
16
-
17
- client1.on("unsubscribe", function (channel, count) {
18
- console.log("client1 unsubscribed from " + channel + ", " + count + " total subscriptions");
19
- if (count === 0) {
20
- client2.end();
21
- client1.end();
22
- }
23
- });
24
-
25
- client1.on("message", function (channel, message) {
26
- console.log("client1 channel " + channel + ": " + message);
27
- msg_count += 1;
28
- if (msg_count === 3) {
29
- client1.unsubscribe();
30
- }
31
- });
32
-
33
- client1.on("ready", function () {
34
- // if you need auth, do it here
35
- client1.incr("did a thing");
36
- client1.subscribe("a nice channel", "another one");
37
- });
38
-
39
- client2.on("ready", function () {
40
- // if you need auth, do it here
41
- });
@@ -1,24 +0,0 @@
1
- var redis = require("redis"),
2
- client = redis.createClient();
3
-
4
- client.on("error", function (err) {
5
- console.log("error event - " + client.host + ":" + client.port + " - " + err);
6
- });
7
-
8
- client.set("string key", "string val", redis.print);
9
- client.hset("hash key", "hashtest 1", "some value", redis.print);
10
- client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
11
- client.hkeys("hash key", function (err, replies) {
12
- if (err) {
13
- return console.error("error response - " + err);
14
- }
15
-
16
- console.log(replies.length + " replies:");
17
- replies.forEach(function (reply, i) {
18
- console.log(" " + i + ": " + reply);
19
- });
20
- });
21
-
22
- client.quit(function (err, res) {
23
- console.log("Exiting from quit command.");
24
- });
package/examples/sort.js DELETED
@@ -1,17 +0,0 @@
1
- var redis = require("redis"),
2
- client = redis.createClient();
3
-
4
- client.sadd("mylist", 1);
5
- client.sadd("mylist", 2);
6
- client.sadd("mylist", 3);
7
-
8
- client.set("weight_1", 5);
9
- client.set("weight_2", 500);
10
- client.set("weight_3", 1);
11
-
12
- client.set("object_1", "foo");
13
- client.set("object_2", "bar");
14
- client.set("object_3", "qux");
15
-
16
- client.sort("mylist", "by", "weight_*", "get", "object_*", redis.print);
17
- // Prints Reply: qux,foo,bar
@@ -1,15 +0,0 @@
1
- // Sending commands in response to other commands.
2
- // This example runs "type" against every key in the database
3
- //
4
- var client = require("redis").createClient();
5
-
6
- client.keys("*", function (err, keys) {
7
- keys.forEach(function (key, pos) {
8
- client.type(key, function (err, keytype) {
9
- console.log(key + " is " + keytype);
10
- if (pos === (keys.length - 1)) {
11
- client.quit();
12
- }
13
- });
14
- });
15
- });
@@ -1,19 +0,0 @@
1
- var client = require("redis").createClient();
2
-
3
- function print_results(obj) {
4
- console.dir(obj);
5
- }
6
-
7
- // build a map of all keys and their types
8
- client.keys("*", function (err, all_keys) {
9
- var key_types = {};
10
-
11
- all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos
12
- client.type(key, function (err, type) {
13
- key_types[key] = type;
14
- if (pos === all_keys.length - 1) { // callbacks all run in order
15
- print_results(key_types);
16
- }
17
- });
18
- });
19
- });
@@ -1,29 +0,0 @@
1
- var redis = require("redis"),
2
- client = redis.createClient("/tmp/redis.sock"),
3
- profiler = require("v8-profiler");
4
-
5
- client.on("connect", function () {
6
- console.log("Got Unix socket connection.")
7
- });
8
-
9
- client.on("error", function (err) {
10
- console.log(err.message);
11
- });
12
-
13
- client.set("space chars", "space value");
14
-
15
- setInterval(function () {
16
- client.get("space chars");
17
- }, 100);
18
-
19
- function done() {
20
- client.info(function (err, reply) {
21
- console.log(reply.toString());
22
- client.quit();
23
- });
24
- }
25
-
26
- setTimeout(function () {
27
- console.log("Taking snapshot.");
28
- var snap = profiler.takeSnapshot();
29
- }, 5000);
@@ -1,31 +0,0 @@
1
- // A simple web server that generates dyanmic content based on responses from Redis
2
-
3
- var http = require("http"), server,
4
- redis_client = require("redis").createClient();
5
-
6
- server = http.createServer(function (request, response) {
7
- response.writeHead(200, {
8
- "Content-Type": "text/plain"
9
- });
10
-
11
- var redis_info, total_requests;
12
-
13
- redis_client.info(function (err, reply) {
14
- redis_info = reply; // stash response in outer scope
15
- });
16
- redis_client.incr("requests", function (err, reply) {
17
- total_requests = reply; // stash response in outer scope
18
- });
19
- redis_client.hincrby("ip", request.connection.remoteAddress, 1);
20
- redis_client.hgetall("ip", function (err, reply) {
21
- // This is the last reply, so all of the previous replies must have completed already
22
- response.write("This page was generated after talking to redis.\n\n" +
23
- "Redis info:\n" + redis_info + "\n" +
24
- "Total requests: " + total_requests + "\n\n" +
25
- "IP count: \n");
26
- Object.keys(reply).forEach(function (ip) {
27
- response.write(" " + ip + ": " + reply[ip] + "\n");
28
- });
29
- response.end();
30
- });
31
- }).listen(80);
@@ -1,39 +0,0 @@
1
- var http = require("http"),
2
- fs = require("fs");
3
-
4
- function prettyCurrentTime() {
5
- var date = new Date();
6
- return date.toLocaleString();
7
- }
8
-
9
- function write_file(commands, path) {
10
- var file_contents, out_commands;
11
-
12
- console.log("Writing " + Object.keys(commands).length + " commands to " + path);
13
-
14
- file_contents = "// This file was generated by ./generate_commands.js on " + prettyCurrentTime() + "\n";
15
-
16
- out_commands = Object.keys(commands).map(function (key) {
17
- return key.toLowerCase();
18
- });
19
-
20
- file_contents += "module.exports = " + JSON.stringify(out_commands, null, " ") + ";\n";
21
-
22
- fs.writeFile(path, file_contents);
23
- }
24
-
25
- http.get({host: "redis.io", path: "/commands.json"}, function (res) {
26
- var body = "";
27
-
28
- console.log("Response from redis.io/commands.json: " + res.statusCode);
29
-
30
- res.on('data', function (chunk) {
31
- body += chunk;
32
- });
33
-
34
- res.on('end', function () {
35
- write_file(JSON.parse(body), "lib/commands.js");
36
- });
37
- }).on('error', function (e) {
38
- console.log("Error fetching command list from redis.io: " + e.message);
39
- });