init, just some testing

This commit is contained in:
psychobunny
2013-04-22 16:51:32 +00:00
commit b04d262fe4
256 changed files with 36023 additions and 0 deletions

5
node_modules/redis/examples/auth.js generated vendored Normal file
View File

@@ -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");

33
node_modules/redis/examples/backpressure_drain.js generated vendored Normal file
View File

@@ -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();

14
node_modules/redis/examples/eval.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
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);
});
client.eval([ "return 100.5", 0 ], function (err, res) {
console.dir(err);
console.dir(res);
});

24
node_modules/redis/examples/extend.js generated vendored Normal file
View File

@@ -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();
});

32
node_modules/redis/examples/file.js generated vendored Normal file
View File

@@ -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();
});
}
});
});

5
node_modules/redis/examples/mget.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
var client = require("redis").createClient();
client.mget(["sessions started", "sessions started", "foo"], function (err, res) {
console.dir(res);
});

10
node_modules/redis/examples/monitor.js generated vendored Normal file
View File

@@ -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));
});

46
node_modules/redis/examples/multi.js generated vendored Normal file
View File

@@ -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();
});

29
node_modules/redis/examples/multi2.js generated vendored Normal file
View File

@@ -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());
});

33
node_modules/redis/examples/psubscribe.js generated vendored Normal file
View File

@@ -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*");

41
node_modules/redis/examples/pub_sub.js generated vendored Normal file
View File

@@ -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
});

24
node_modules/redis/examples/simple.js generated vendored Normal file
View File

@@ -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.");
});

17
node_modules/redis/examples/sort.js generated vendored Normal file
View File

@@ -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

15
node_modules/redis/examples/subqueries.js generated vendored Normal file
View File

@@ -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();
}
});
});
});

19
node_modules/redis/examples/subquery.js generated vendored Normal file
View File

@@ -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);
}
});
});
});

29
node_modules/redis/examples/unix_socket.js generated vendored Normal file
View File

@@ -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);

31
node_modules/redis/examples/web_server.js generated vendored Normal file
View File

@@ -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);