1 // Read a file from disk, store it in Redis, then read it back from Redis.
3 var redis = require("redis"),
4 client = redis.createClient(),
6 filename = "kids_in_cart.jpg";
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.
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) {
15 console.log("Read " + data.length + " bytes from filesystem.");
17 client.set(filename, data, redis.print); // set entire file
18 client.get(filename, function (err, reply) { // get entire file
20 console.log("Get error: " + err);
22 fs.writeFile("duplicate_" + filename, reply, function (err) {
24 console.log("Error on write: " + err)
26 console.log("File written.");