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. discard
cancels 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'); */