php-redis中文参考手册_multi_exec_discard_watch_unwatc...

multi, exec, discard.

Description

Enter and exit transactional mode.php

进入、退出事务处理模式。git

Parameters

(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. discardcancels a transaction.github

multi函数的参数选项为Redis::MULTI或者是Redis::PIPELINE.默认的是参数是Redis::MULTI。redis

Redis::MULTI将多个操做当作一个事务来处理。Redis::PIPELINE将做为一个简单快速的处理通道给服务器进行处理,可是不保证处理数据的原子性。服务器

discard()函数取消一个事物处理模式。函数

Return value

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

Example
$ret = $redis->multi()
    ->set('key1', 'val1')
    ->get('key1')
    ->set('key2', 'val2')
    ->get('key2')
    ->exec();

/*
$ret == array(
    0 => TRUE,
    1 => 'val1',
    2 => TRUE,
    3 => 'val2');
*/

watch, unwatch

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.spa

监控一个KEY是否被其余的客户端修改。若是KEY在调用watch()和exec()之间被修改,那么批量处理最终的exec()执行将失败。unwatch()取消对于全部KEY值的监控操做针对于这个Redis实例。code

Parameters

keys: a list of keys

Example
$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

Description

Subscribe to channels. Warning: this function will probably change in the future.

方法回调函数,注意:该方法在未来有可能被修改。

Parameters

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.

Example
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

Description

Publish messages to channels. Warning: this function will probably change in the future.

Parameters

channel: a channel to publish to
messsage: string

Example
$redis->publish('chan-1', 'hello, world!'); // send message.

exists

Description

Verify if the specified key exists.

验证一个指定的KEY是否存在

Parameters

key

Return value

BOOL: If the key exists, return TRUE, otherwise return FALSE.

Examples
$redis->set('key', 'value');
$redis->exists('key'); /*  TRUE */
$redis->exists('NonExistingKey'); /* FALSE */
相关文章
相关标签/搜索