@@ -715,7 +715,7 @@ command, which is meant to be used with MULTI:
715
715
716
716
``` js
717
717
var redis = require (" redis" ),
718
- client = redis .createClient ();
718
+ client = redis .createClient ({ ... } );
719
719
720
720
client .watch (" foo" , function ( err ){
721
721
if (err) throw err;
@@ -793,9 +793,38 @@ clients.watcher.watch('foo',function(err) {
793
793
});
794
794
```
795
795
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.
799
828
800
829
## Monitor mode
801
830
0 commit comments