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 */