Redis transaction operation

Redis transactions can not be rolled back, but can guarantee atomicity, can also achieve redis transaction effect with lua script

The following is a transaction operation example, the return data is a bit special, the even number is success or not, the odd number is the execution key , and the following is a result traversal method.

 $count  = 2;
$result = Redis::transaction(function (\Redis $redis) use ($count) {
    for ($i = 0; $i < $count; $i++) {
        $key = "key:$i";
        $redis->set($key, $i);
        $redis->get($key);
    }
});

/*
$result = array(4) {
    [0]=>
    bool(true)
    [1]=>
    int(0)
    [2]=>
    bool(true)
    [3]=>
    int(1)
}*/

foreach ($result as $index => $value) {
    if ($index % 2 == 0) {
        // is exec ok ?
       if ($value) {
            // todo... 
       }
    }
}
 
/docs/2.x/en/redis/transaction.html
progress-bar