From f2ab80e7e9aeba94fd1724dc60e7a371239331e6 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 1 Jan 2011 17:40:35 +0100 Subject: [PATCH] Add missing example for CAS with MULTI/EXEC abstraction. --- examples/MultiExecTransactionsWithCAS.php | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/MultiExecTransactionsWithCAS.php diff --git a/examples/MultiExecTransactionsWithCAS.php b/examples/MultiExecTransactionsWithCAS.php new file mode 100644 index 00000000..513b2051 --- /dev/null +++ b/examples/MultiExecTransactionsWithCAS.php @@ -0,0 +1,38 @@ + true, // Initialize with support for CAS operations + 'watch' => $zsetKey, // Key that needs to be WATCHed to detect changes + ); + + $tx = $client->multiExec($options); + @list($element) = $tx->zrange($zsetKey, 0, 0); + if (isset($element)) { + $tx->multi(); // With CAS, MULTI *must* be explicitly invoked. + $tx->zrem($zsetKey, $element); + $tx->exec(); + } + return $element; +} + +$redis = new Predis_Client($single_server, 'dev'); +$zpopped = zpop($redis, 'zset'); +echo isset($zpopped) ? "ZPOPed $zpopped" : "Nothing to ZPOP!", "\n"; +?>