1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Some bug fixes:

* An important bug fix in reconnection logic.  Previously, reply callbacks would be invoked twice after
  a reconnect.
* Changed error callback argument to be an actual Error object.

New feature:

* Add friendly syntax for HMSET using an object.
This commit is contained in:
Matt Ranney
2010-12-29 17:48:40 -08:00
parent aa3cefe506
commit ccce845cc2
5 changed files with 172 additions and 33 deletions

View File

@@ -53,7 +53,7 @@ The performance of `node_redis` improves dramatically with pipelining.
## Usage
Simple example, included as `example.js`:
Simple example, included as `examples/simple.js`:
var redis = require("redis"),
client = redis.createClient();
@@ -195,6 +195,44 @@ want to do this:
`client.end()` is useful for timeout cases where something is stuck or taking too long and you want
to start over.
## Friendlier hash commands
Most Redis commands take a single String or an Array of Strings as arguments, and replies are sent back as a single String or an Array of Strings. When dealing with hash values, there are a couple of useful exceptions to this.
### client.hgetall(hash)
The reply from an HGETALL command will be converted into a JavaScript Object by `node_redis`. That way you can interact
with the responses using JavaScript syntax.
Example:
client.hmset("hosts", "mjr", "1", "another", "23", "home", "1234");
client.hgetall("hosts", function (err, obj) {
console.dir(obj);
});
Output:
{ mjr: '1', another: '23', home: '1234' }
### client.hmset(hash, obj, [callback])
Multiple values in a hash can be set by supplying an object:
client.HMSET(key2, {
"0123456789": "abcdefghij",
"some manner of key": "a type of value"
});
The properties and values of this Object will be set as keys and values in the Redis hash.
### client.hmset(hash, key1, val1, ... keyn, valn, [callback])
Multiple values may also be set by supplying a list:
client.HMSET(key1, "0123456789", "abcdefghij", "some manner of key", "a type of value");
## Publish / Subscribe
Here is a simple example of the API for publish / subscribe. This program opens two