Permalink
Browse files

Demonstrated client.close() in README Quick Tour. Added an accompanyi…

…ng examples/tour.js example to accompany the README Quick Tour.
  • Loading branch information...
1 parent c387673 commit 59120714ddb26b68d3b9b3479fea7bea68022c11 @bnoguchi committed Nov 19, 2010
Showing with 55 additions and 0 deletions.
  1. +6 −0 README.md
  2. +49 −0 examples/tour.js
View
@@ -17,6 +17,7 @@ Blog post coming.
npm install redis-node
### A Quick Tour
+ // See ./examples/tour.js
var sys = require("sys");
var redis = require("redis-node");
var client = redis.createClient(); // Create the client
@@ -60,6 +61,11 @@ Blog post coming.
client.set("I'm missing a 2nd argument"); // Our client with automatically discard the transaction
});
+ // Close the connection
+ setTimeout( function () {
+ client.close();
+ }, 1000);
+
See test/ for examples of each command.
# API Reference
View
@@ -0,0 +1,49 @@
+// Run using
+// node examples/tour.js
+var sys = require("sys");
+var redis = require("redis-node");
+var client = redis.createClient(); // Create the client
+client.select(2); // Select database 2
+
+// Assign the string "world" to the "hello" key.
+// You can provide a callback to handle the response from Redis
+// that gets asynchronously run upon seeing the response.
+client.set("hello", "world", function (err, status) {
+ if (err) throw err;
+ console.log(status); // true
+});
+
+// ... but you don't have to provide a callback.
+client.set("hello", "world");
+
+// We may or may not be connected yet, but that's ok, since
+// the client queues up any commands.
+
+// The commands are also idiomatic
+client.hmset("hash", { t: "rex", steg: "asaurus" }, function (err, status) {
+ if (err) throw err;
+ sys.log(status); // true
+});
+
+// Support for transactions
+console.log("Transfer from checking to savings.");
+client.transaction( function () {
+ client.decrby("checking", 100, function (err, balance) {
+ if (err) throw err;
+ console.log("Checking Balance: " + balance);
+ });
+ client.incrby("savings", 100, function (err, balance) {
+ if (err) throw err;
+ console.log("Savings Balance: " + balance);
+ });
+});
+
+// With automatic transaction discard if there are any syntactic errors
+client.transaction( function () {
+ client.set("I'm missing a 2nd argument"); // Our client with automatically discard the transaction
+});
+
+// Close the connection
+setTimeout( function () {
+ client.close();
+}, 1000);

0 comments on commit 5912071

Please sign in to comment.