ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## multi, exec, discard. ##### Description Enter and exit transactional mode. 进入、退出事务处理模式。 ##### Parameters (optional) `<span class="calibre12">Redis::MULTI</span>` or `<span class="calibre12">Redis::PIPELINE</span>`. Defaults to `<span class="calibre12">Redis::MULTI</span>`. A `<span class="calibre12">Redis::MULTI</span>` block of commands runs as a single transaction; a `<span class="calibre12">Redis::PIPELINE</span>` block is simply transmitted faster to the server, but without any guarantee of atomicity. `<span class="calibre12">discard</span>`cancels a transaction. multi函数的参数选项为Redis::MULTI或者是Redis::PIPELINE.默认的是参数是Redis::MULTI。 Redis::MULTI将多个操作当做一个事务来处理。Redis::PIPELINE将作为一个简单快速的处理通道给服务器进行处理,但是不保证处理数据的原子性。 discard()函数取消一个事物处理模式。 ##### Return value `<span class="calibre12">multi()</span>` returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until `<span class="calibre12">exec()</span>` is called. multi()返回一个Redis实例,并且这个实例进入到了事务处理模式(批量处理)。当进入到事务处理模式,所有的方法调用都将返回相同的Redis实例,一直到exec()被调用执行事务处理。 ##### Example ``` <pre class="calibre9">$ret = $redis->multi() ->set('key1', 'val1') ->get('key1') ->set('key2', 'val2') ->get('key2') ->exec(); /* $ret == array( 0 => TRUE, 1 => 'val1', 2 => TRUE, 3 => 'val2'); */ ```