You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_**Description**_: Enter and exit transactional mode.
629
-
630
-
##### *Parameters*
631
-
(optional) `Redis::MULTI` or `Redis::PIPELINE`. Defaults to `Redis::MULTI`. A `Redis::MULTI` block of commands runs as a single transaction; a `Redis::PIPELINE` block is simply transmitted faster to the server, but without any guarantee of atomicity. `discard` cancels a transaction.
632
-
633
-
##### *Return value*
634
-
`multi()` returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until `exec()` is called.
635
-
636
-
##### *Example*
637
-
~~~
638
-
$ret = $redis->multi()
639
-
->set('key1', 'val1')
640
-
->get('key1')
641
-
->set('key2', 'val2')
642
-
->get('key2')
643
-
->exec();
644
-
645
-
/*
646
-
$ret == array(
647
-
0 => TRUE,
648
-
1 => 'val1',
649
-
2 => TRUE,
650
-
3 => 'val2');
651
-
*/
652
-
~~~
653
-
654
-
### watch, unwatch
655
-
-----
656
-
_**Description**_: Watches a key for modifications by another client. If the key is modified between `WATCH` and `EXEC`, the MULTI/EXEC transaction will fail (return `FALSE`). `unwatch` cancels all the watching of all keys by this client.
657
-
658
-
##### *Parameters*
659
-
*keys*: a list of keys
660
-
661
-
##### *Example*
662
-
~~~
663
-
$redis->watch('x');
664
-
/* long code here during the execution of which other clients could well modify `x` */
665
-
$ret = $redis->multi()
666
-
->incr('x')
667
-
->exec();
668
-
/*
669
-
$ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
670
-
*/
671
-
~~~
672
-
673
-
### subscribe
674
-
-----
675
-
_**Description**_: Subscribe to channels. Warning: this function will probably change in the future.
676
-
677
-
##### *Parameters*
678
-
*channels*: an array of channels to subscribe to
679
-
*callback*: either a string or an array($instance, 'method_name'). The callback function receives 3 parameters: the redis instance, the channel name, and the message.
680
-
681
-
##### *Example*
682
-
~~~
683
-
function f($redis, $chan, $msg) {
684
-
switch($chan) {
685
-
case 'chan-1':
686
-
...
687
-
break;
688
-
689
-
case 'chan-2':
690
-
...
691
-
break;
692
-
693
-
case 'chan-2':
694
-
...
695
-
break;
696
-
}
697
-
}
698
-
699
-
$redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
700
-
~~~
701
-
702
-
### psubscribe
703
-
-----
704
-
_**Description**_: Subscribe to channels by pattern
705
-
706
-
##### *Parameters*
707
-
*patterns*: An array of patterns to match
708
-
*callback*: Either a string or an array with an object and method. The callback will get four arguments ($redis, $pattern, $channel, $message)
709
-
710
-
##### *Example*
711
-
~~~
712
-
function psubscribe($redis, $pattern, $chan, $msg) {
713
-
echo "Pattern: $pattern\n";
714
-
echo "Channel: $chan\n";
715
-
echo "Payload: $msg\n";
716
-
}
717
-
~~~
718
-
719
-
### publish
720
-
-----
721
-
_**Description**_: Publish messages to channels. Warning: this function will probably change in the future.
_**Description**_: Subscribe to channels. Warning: this function will probably change in the future.
2640
+
2641
+
##### *Parameters*
2642
+
*channels*: an array of channels to subscribe to
2643
+
*callback*: either a string or an array($instance, 'method_name'). The callback function receives 3 parameters: the redis instance, the channel name, and the message.
2644
+
2645
+
##### *Example*
2646
+
~~~
2647
+
function f($redis, $chan, $msg) {
2648
+
switch($chan) {
2649
+
case 'chan-1':
2650
+
...
2651
+
break;
2652
+
2653
+
case 'chan-2':
2654
+
...
2655
+
break;
2656
+
2657
+
case 'chan-2':
2658
+
...
2659
+
break;
2660
+
}
2661
+
}
2662
+
2663
+
$redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
2664
+
~~~
2665
+
2666
+
2667
+
## Transactions
2668
+
2669
+
1.[multi, exec, discard](#multi-exec-discard) - Enter and exit transactional mode
2670
+
2.[watch, unwatch](#watch-unwatch) - Watches a key for modifications by another client.
2671
+
2672
+
### multi, exec, discard.
2673
+
-----
2674
+
_**Description**_: Enter and exit transactional mode.
2675
+
2676
+
##### *Parameters*
2677
+
(optional) `Redis::MULTI` or `Redis::PIPELINE`. Defaults to `Redis::MULTI`. A `Redis::MULTI` block of commands runs as a single transaction; a `Redis::PIPELINE` block is simply transmitted faster to the server, but without any guarantee of atomicity. `discard` cancels a transaction.
2678
+
2679
+
##### *Return value*
2680
+
`multi()` returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until `exec()` is called.
2681
+
2682
+
##### *Example*
2683
+
~~~
2684
+
$ret = $redis->multi()
2685
+
->set('key1', 'val1')
2686
+
->get('key1')
2687
+
->set('key2', 'val2')
2688
+
->get('key2')
2689
+
->exec();
2690
+
2691
+
/*
2692
+
$ret == array(
2693
+
0 => TRUE,
2694
+
1 => 'val1',
2695
+
2 => TRUE,
2696
+
3 => 'val2');
2697
+
*/
2698
+
~~~
2699
+
2700
+
### watch, unwatch
2701
+
-----
2702
+
_**Description**_: Watches a key for modifications by another client.
2703
+
2704
+
If the key is modified between `WATCH` and `EXEC`, the MULTI/EXEC transaction will fail (return `FALSE`). `unwatch` cancels all the watching of all keys by this client.
2705
+
2706
+
##### *Parameters*
2707
+
*keys*: a list of keys
2708
+
2709
+
##### *Example*
2710
+
~~~
2711
+
$redis->watch('x');
2712
+
/* long code here during the execution of which other clients could well modify `x` */
2713
+
$ret = $redis->multi()
2714
+
->incr('x')
2715
+
->exec();
2716
+
/*
2717
+
$ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
0 commit comments