Rediska

Follow me on twitter…

Rediska transactions

July 15, 2010

Few minutes ago i'm pushed to github new feature - transactions.

It's very useful implementaton of MULTI/EXEC Redis command:

<?php

$rediska = new Rediska();
$rediska->transaction()->set('a', 1)
                       ->get('a', 1)
                       ->delete('a')
                       ->execute();

// or
$transaction = $rediska->transaction();
$transaction->set('a', 1);

$rediska->get('a') // #=> null

$transaction->get('a', 1);
$transaction->delete('a', 1);
$transaction->set('b', 2);

$rediska->get('b') // #=> null

$transaction->execute();
$rediska->get('b') // #=> 2

// You may discard transaction
$transaction = $rediska->transaction();
$transaction->set('a', 1)
            ->get('a', 1);
            ->delete('a', 1);

if (/* something wrong */) {
    $transaction->discard();
}

?>

Oh! Important feature of transactions - all commands executed as one atomic operation!

Comments

Fork me on GitHub