Enter and exit transactional mode.php
進入、退出事務處理模式。git
(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.github
multi函數的參數選項爲Redis::MULTI或者是Redis::PIPELINE.默認的是參數是Redis::MULTI。redis
Redis::MULTI將多個操做當作一個事務來處理。Redis::PIPELINE將做爲一個簡單快速的處理通道給服務器進行處理,可是不保證處理數據的原子性。服務器
discard()函數取消一個事物處理模式。函數
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.this
multi()返回一個Redis實例,而且這個實例進入到了事務處理模式(批量處理)。當進入到事務處理模式,全部的方法調用都將返回相同的Redis實例,一直到exec()被調用執行事務處理。atom
$ret = $redis->multi() ->set('key1', 'val1') ->get('key1') ->set('key2', 'val2') ->get('key2') ->exec(); /* $ret == array( 0 => TRUE, 1 => 'val1', 2 => TRUE, 3 => 'val2'); */
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.spa
監控一個KEY是否被其餘的客戶端修改。若是KEY在調用watch()和exec()之間被修改,那麼批量處理最終的exec()執行將失敗。unwatch()取消對於全部KEY值的監控操做針對於這個Redis實例。code
keys: a list of keys
$redis->watch('x'); /* long code here during the execution of which other clients could well modify `x` */ $ret = $redis->multi() ->incr('x') ->exec(); /* $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC. */
Subscribe to channels. Warning: this function will probably change in the future.
方法回調函數,注意:該方法在未來有可能被修改。
channels: an array of channels to subscribe to
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.
function f($redis, $chan, $msg) { switch($chan) { case 'chan-1': ... break; case 'chan-2': ... break; case 'chan-2': ... break; } } $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
Publish messages to channels. Warning: this function will probably change in the future.
channel: a channel to publish to
messsage: string
$redis->publish('chan-1', 'hello, world!'); // send message.
Verify if the specified key exists.
驗證一個指定的KEY是否存在
key
BOOL: If the key exists, return TRUE
, otherwise return FALSE
.
$redis->set('key', 'value'); $redis->exists('key'); /* TRUE */ $redis->exists('NonExistingKey'); /* FALSE */