From b41d2f8780a998547997d3c7512f915821dbe208 Mon Sep 17 00:00:00 2001 From: Matt Ranney Date: Fri, 17 Sep 2010 16:21:11 -0700 Subject: [PATCH] Add large binary get/set example. --- example_file.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 example_file.js diff --git a/example_file.js b/example_file.js new file mode 100644 index 0000000000..f048615845 --- /dev/null +++ b/example_file.js @@ -0,0 +1,30 @@ +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(); + }); + } + }); +});