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

multi, exec, discard.

Description

Enter and exit transactional mode.

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

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.

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

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.

multi()返回一个Redis实例,并且这个实例进入到了事务处理模式(批量处理)。当进入到事务处理模式,所有的方法调用都将返回相同的Redis实例,一直到exec()被调用执行事务处理。

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.

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

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

你可能感兴趣的:(redis,PHP,phpredis,php-redis,中文参考手册)