smelikecat

导航

[redis]Redis Transaction

https://github.com/phpredis/phpredis#transactions

Transactions

  1. multi, exec, discard - Enter and exit transactional mode
  2. watch, unwatch - Watches a key for modifications by another client.

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.

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.

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

posted on 2015-10-17 19:28  smelikecat  阅读(245)  评论(0编辑  收藏  举报