aboutsummaryrefslogtreecommitdiffstats
path: root/signaling-server/node_modules/socket.io/node_modules/redis/examples
diff options
context:
space:
mode:
Diffstat (limited to 'signaling-server/node_modules/socket.io/node_modules/redis/examples')
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/auth.js5
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/backpressure_drain.js33
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/eval.js9
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/extend.js24
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/file.js32
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/mget.js5
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/monitor.js10
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/multi.js46
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/multi2.js29
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/psubscribe.js33
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/pub_sub.js41
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/simple.js24
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/sort.js17
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/subqueries.js15
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/subquery.js19
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/unix_socket.js29
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/redis/examples/web_server.js31
17 files changed, 402 insertions, 0 deletions
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/auth.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/auth.js
new file mode 100644
index 0000000..6c0a563
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/auth.js
@@ -0,0 +1,5 @@
+var redis = require("redis"),
+ client = redis.createClient();
+
+// This command is magical. Client stashes the password and will issue on every connect.
+client.auth("somepass");
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/backpressure_drain.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/backpressure_drain.js
new file mode 100644
index 0000000..3488ef4
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/backpressure_drain.js
@@ -0,0 +1,33 @@
+var redis = require("../index"),
+ client = redis.createClient(null, null, {
+ command_queue_high_water: 5,
+ command_queue_low_water: 1
+ }),
+ remaining_ops = 100000, paused = false;
+
+function op() {
+ if (remaining_ops <= 0) {
+ console.error("Finished.");
+ process.exit(0);
+ }
+
+ remaining_ops--;
+ if (client.hset("test hash", "val " + remaining_ops, remaining_ops) === false) {
+ console.log("Pausing at " + remaining_ops);
+ paused = true;
+ } else {
+ process.nextTick(op);
+ }
+}
+
+client.on("drain", function () {
+ if (paused) {
+ console.log("Resuming at " + remaining_ops);
+ paused = false;
+ process.nextTick(op);
+ } else {
+ console.log("Got drain while not paused at " + remaining_ops);
+ }
+});
+
+op();
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/eval.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/eval.js
new file mode 100644
index 0000000..c1fbf8a
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/eval.js
@@ -0,0 +1,9 @@
+var redis = require("./index"),
+ client = redis.createClient();
+
+redis.debug_mode = true;
+
+client.eval("return 100.5", 0, function (err, res) {
+ console.dir(err);
+ console.dir(res);
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/extend.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/extend.js
new file mode 100644
index 0000000..488b8c2
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/extend.js
@@ -0,0 +1,24 @@
+var redis = require("redis"),
+ client = redis.createClient();
+
+// Extend the RedisClient prototype to add a custom method
+// This one converts the results from "INFO" into a JavaScript Object
+
+redis.RedisClient.prototype.parse_info = function (callback) {
+ this.info(function (err, res) {
+ var lines = res.toString().split("\r\n").sort();
+ var obj = {};
+ lines.forEach(function (line) {
+ var parts = line.split(':');
+ if (parts[1]) {
+ obj[parts[0]] = parts[1];
+ }
+ });
+ callback(obj)
+ });
+};
+
+client.parse_info(function (info) {
+ console.dir(info);
+ client.quit();
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/file.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/file.js
new file mode 100644
index 0000000..4d2b5d1
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/file.js
@@ -0,0 +1,32 @@
+// Read a file from disk, store it in Redis, then read it back from Redis.
+
+var redis = require("redis"),
+ client = redis.createClient(),
+ fs = require("fs"),
+ filename = "kids_in_cart.jpg";
+
+// Get the file I use for testing like this:
+// curl http://ranney.com/kids_in_cart.jpg -o kids_in_cart.jpg
+// or just use your own file.
+
+// Read a file from fs, store it in Redis, get it back from Redis, write it back to fs.
+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.get(filename, function (err, reply) { // get entire file
+ if (err) {
+ console.log("Get error: " + err);
+ } else {
+ fs.writeFile("duplicate_" + filename, reply, function (err) {
+ if (err) {
+ console.log("Error on write: " + err)
+ } else {
+ console.log("File written.");
+ }
+ client.end();
+ });
+ }
+ });
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/mget.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/mget.js
new file mode 100644
index 0000000..936740d
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/mget.js
@@ -0,0 +1,5 @@
+var client = require("redis").createClient();
+
+client.mget(["sessions started", "sessions started", "foo"], function (err, res) {
+ console.dir(res);
+}); \ No newline at end of file
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/monitor.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/monitor.js
new file mode 100644
index 0000000..2cb6a4e
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/monitor.js
@@ -0,0 +1,10 @@
+var client = require("../index").createClient(),
+ util = require("util");
+
+client.monitor(function (err, res) {
+ console.log("Entering monitoring mode.");
+});
+
+client.on("monitor", function (time, args) {
+ console.log(time + ": " + util.inspect(args));
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/multi.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/multi.js
new file mode 100644
index 0000000..35c08e1
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/multi.js
@@ -0,0 +1,46 @@
+var redis = require("redis"),
+ client = redis.createClient(), set_size = 20;
+
+client.sadd("bigset", "a member");
+client.sadd("bigset", "another member");
+
+while (set_size > 0) {
+ client.sadd("bigset", "member " + set_size);
+ set_size -= 1;
+}
+
+// multi chain with an individual callback
+client.multi()
+ .scard("bigset")
+ .smembers("bigset")
+ .keys("*", function (err, replies) {
+ client.mget(replies, redis.print);
+ })
+ .dbsize()
+ .exec(function (err, replies) {
+ console.log("MULTI got " + replies.length + " replies");
+ replies.forEach(function (reply, index) {
+ console.log("Reply " + index + ": " + reply.toString());
+ });
+ });
+
+client.mset("incr thing", 100, "incr other thing", 1, redis.print);
+
+// start a separate multi command queue
+var multi = client.multi();
+multi.incr("incr thing", redis.print);
+multi.incr("incr other thing", redis.print);
+
+// runs immediately
+client.get("incr thing", redis.print); // 100
+
+// drains multi queue and runs atomically
+multi.exec(function (err, replies) {
+ console.log(replies); // 101, 2
+});
+
+// you can re-run the same transaction if you like
+multi.exec(function (err, replies) {
+ console.log(replies); // 102, 3
+ client.quit();
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/multi2.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/multi2.js
new file mode 100644
index 0000000..8be4d73
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/multi2.js
@@ -0,0 +1,29 @@
+var redis = require("redis"),
+ client = redis.createClient(), multi;
+
+// start a separate command queue for multi
+multi = client.multi();
+multi.incr("incr thing", redis.print);
+multi.incr("incr other thing", redis.print);
+
+// runs immediately
+client.mset("incr thing", 100, "incr other thing", 1, redis.print);
+
+// drains multi queue and runs atomically
+multi.exec(function (err, replies) {
+ console.log(replies); // 101, 2
+});
+
+// you can re-run the same transaction if you like
+multi.exec(function (err, replies) {
+ console.log(replies); // 102, 3
+ client.quit();
+});
+
+client.multi([
+ ["mget", "multifoo", "multibar", redis.print],
+ ["incr", "multifoo"],
+ ["incr", "multibar"]
+]).exec(function (err, replies) {
+ console.log(replies.toString());
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/psubscribe.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/psubscribe.js
new file mode 100644
index 0000000..c57117b
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/psubscribe.js
@@ -0,0 +1,33 @@
+var redis = require("redis"),
+ client1 = redis.createClient(),
+ client2 = redis.createClient(),
+ client3 = redis.createClient(),
+ client4 = redis.createClient(),
+ msg_count = 0;
+
+redis.debug_mode = false;
+
+client1.on("psubscribe", function (pattern, count) {
+ console.log("client1 psubscribed to " + pattern + ", " + count + " total subscriptions");
+ client2.publish("channeltwo", "Me!");
+ client3.publish("channelthree", "Me too!");
+ client4.publish("channelfour", "And me too!");
+});
+
+client1.on("punsubscribe", function (pattern, count) {
+ console.log("client1 punsubscribed from " + pattern + ", " + count + " total subscriptions");
+ client4.end();
+ client3.end();
+ client2.end();
+ client1.end();
+});
+
+client1.on("pmessage", function (pattern, channel, message) {
+ console.log("("+ pattern +")" + " client1 received message on " + channel + ": " + message);
+ msg_count += 1;
+ if (msg_count === 3) {
+ client1.punsubscribe();
+ }
+});
+
+client1.psubscribe("channel*");
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/pub_sub.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
new file mode 100644
index 0000000..aa508d6
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
@@ -0,0 +1,41 @@
+var redis = require("redis"),
+ client1 = redis.createClient(), msg_count = 0,
+ client2 = redis.createClient();
+
+redis.debug_mode = false;
+
+// Most clients probably don't do much on "subscribe". This example uses it to coordinate things within one program.
+client1.on("subscribe", function (channel, count) {
+ console.log("client1 subscribed to " + channel + ", " + count + " total subscriptions");
+ if (count === 2) {
+ client2.publish("a nice channel", "I am sending a message.");
+ client2.publish("another one", "I am sending a second message.");
+ client2.publish("a nice channel", "I am sending my last message.");
+ }
+});
+
+client1.on("unsubscribe", function (channel, count) {
+ console.log("client1 unsubscribed from " + channel + ", " + count + " total subscriptions");
+ if (count === 0) {
+ client2.end();
+ client1.end();
+ }
+});
+
+client1.on("message", function (channel, message) {
+ console.log("client1 channel " + channel + ": " + message);
+ msg_count += 1;
+ if (msg_count === 3) {
+ client1.unsubscribe();
+ }
+});
+
+client1.on("ready", function () {
+ // if you need auth, do it here
+ client1.incr("did a thing");
+ client1.subscribe("a nice channel", "another one");
+});
+
+client2.on("ready", function () {
+ // if you need auth, do it here
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/simple.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/simple.js
new file mode 100644
index 0000000..f1f2e32
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/simple.js
@@ -0,0 +1,24 @@
+var redis = require("redis"),
+ client = redis.createClient();
+
+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.hkeys("hash key", function (err, replies) {
+ if (err) {
+ return console.error("error response - " + err);
+ }
+
+ console.log(replies.length + " replies:");
+ replies.forEach(function (reply, i) {
+ console.log(" " + i + ": " + reply);
+ });
+});
+
+client.quit(function (err, res) {
+ console.log("Exiting from quit command.");
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/sort.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/sort.js
new file mode 100644
index 0000000..e7c6249
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/sort.js
@@ -0,0 +1,17 @@
+var redis = require("redis"),
+ client = redis.createClient();
+
+client.sadd("mylist", 1);
+client.sadd("mylist", 2);
+client.sadd("mylist", 3);
+
+client.set("weight_1", 5);
+client.set("weight_2", 500);
+client.set("weight_3", 1);
+
+client.set("object_1", "foo");
+client.set("object_2", "bar");
+client.set("object_3", "qux");
+
+client.sort("mylist", "by", "weight_*", "get", "object_*", redis.print);
+// Prints Reply: qux,foo,bar \ No newline at end of file
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/subqueries.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/subqueries.js
new file mode 100644
index 0000000..560db24
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/subqueries.js
@@ -0,0 +1,15 @@
+// Sending commands in response to other commands.
+// This example runs "type" against every key in the database
+//
+var client = require("redis").createClient();
+
+client.keys("*", function (err, keys) {
+ keys.forEach(function (key, pos) {
+ client.type(key, function (err, keytype) {
+ console.log(key + " is " + keytype);
+ if (pos === (keys.length - 1)) {
+ client.quit();
+ }
+ });
+ });
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/subquery.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/subquery.js
new file mode 100644
index 0000000..861657e
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/subquery.js
@@ -0,0 +1,19 @@
+var client = require("redis").createClient();
+
+function print_results(obj) {
+ console.dir(obj);
+}
+
+// build a map of all keys and their types
+client.keys("*", function (err, all_keys) {
+ var key_types = {};
+
+ all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos
+ client.type(key, function (err, type) {
+ key_types[key] = type;
+ if (pos === all_keys.length - 1) { // callbacks all run in order
+ print_results(key_types);
+ }
+ });
+ });
+});
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/unix_socket.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/unix_socket.js
new file mode 100644
index 0000000..4a5e0bb
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/unix_socket.js
@@ -0,0 +1,29 @@
+var redis = require("redis"),
+ client = redis.createClient("/tmp/redis.sock"),
+ profiler = require("v8-profiler");
+
+client.on("connect", function () {
+ console.log("Got Unix socket connection.")
+});
+
+client.on("error", function (err) {
+ console.log(err.message);
+});
+
+client.set("space chars", "space value");
+
+setInterval(function () {
+ client.get("space chars");
+}, 100);
+
+function done() {
+ client.info(function (err, reply) {
+ console.log(reply.toString());
+ client.quit();
+ });
+}
+
+setTimeout(function () {
+ console.log("Taking snapshot.");
+ var snap = profiler.takeSnapshot();
+}, 5000);
diff --git a/signaling-server/node_modules/socket.io/node_modules/redis/examples/web_server.js b/signaling-server/node_modules/socket.io/node_modules/redis/examples/web_server.js
new file mode 100644
index 0000000..9fd8592
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/redis/examples/web_server.js
@@ -0,0 +1,31 @@
+// A simple web server that generates dyanmic content based on responses from Redis
+
+var http = require("http"), server,
+ redis_client = require("redis").createClient();
+
+server = http.createServer(function (request, response) {
+ response.writeHead(200, {
+ "Content-Type": "text/plain"
+ });
+
+ var redis_info, total_requests;
+
+ redis_client.info(function (err, reply) {
+ redis_info = reply; // stash response in outer scope
+ });
+ redis_client.incr("requests", function (err, reply) {
+ total_requests = reply; // stash response in outer scope
+ });
+ redis_client.hincrby("ip", request.connection.remoteAddress, 1);
+ redis_client.hgetall("ip", function (err, reply) {
+ // This is the last reply, so all of the previous replies must have completed already
+ response.write("This page was generated after talking to redis.\n\n" +
+ "Redis info:\n" + redis_info + "\n" +
+ "Total requests: " + total_requests + "\n\n" +
+ "IP count: \n");
+ Object.keys(reply).forEach(function (ip) {
+ response.write(" " + ip + ": " + reply[ip] + "\n");
+ });
+ response.end();
+ });
+}).listen(80);