Skip to content

Commit 7b57578

Browse files
committed
Improved QA of code snippets, improved documentatino on WATCH limitations.
1 parent 0dc6262 commit 7b57578

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ command, which is meant to be used with MULTI:
715715

716716
```js
717717
var redis = require("redis"),
718-
client = redis.createClient();
718+
client = redis.createClient({ ... });
719719

720720
client.watch("foo", function( err ){
721721
if(err) throw err;
@@ -793,9 +793,38 @@ clients.watcher.watch('foo',function(err) {
793793
});
794794
```
795795

796-
**NOTE**: Redis WATCH does not work on fields of hashes and other objects. You can watch a hash
797-
to see if anything inside it was modified, but you cannot watch a specific hash field for a
798-
modification.
796+
### WATCH limitations
797+
798+
Redis WATCH works only on *whole* key values. For example, with WATCH you can
799+
watch a hash for modifications, but you cannot watch a specific field of a hash.
800+
801+
The following example would watch the keys `foo` and `hello`, not the field `hello`
802+
of hash `foo`:
803+
804+
```js
805+
var redis = require("redis"),
806+
client = redis.createClient({ ... });
807+
808+
client.hget( "foo", "hello", function(err, result){
809+
810+
//Do some processing with the value from this field and watch it after
811+
812+
client.watch("foo", "hello", function( err ){
813+
if(err) throw err;
814+
815+
/**
816+
* WRONG: This is now watching the keys 'foo' and 'hello'. It is not
817+
* watching the field 'hello' of hash 'foo'. Because the key 'foo'
818+
* refers to a hash, this command is now watching the entire hash
819+
* for modifications.
820+
*/
821+
});
822+
} )
823+
824+
```
825+
826+
This limitation also applies to sets ( cannot watch individual set members )
827+
and any other collections.
799828

800829
## Monitor mode
801830

0 commit comments

Comments
 (0)