NAME
Mojo::Redis::Transaction - Transaction support for Redis
SYNOPSIS
my $redis = Mojo::Redis->new($ENV{TEST_ONLINE});
my $txn = $redis->txn;
$txn->set($key => 123)
->get($key)
->incr($key)
->incrby($key => -10)
->exec_p
->then(sub {
my ($set, $get, $incr, $incrby) = @{$_[0]};
});
DESCRIPTION
Mojo::Redis::Transaction provides most of the same methods as Mojo::Redis::Database, but will issue the commands inside an atomic transaction.
See https://redis.io/topics/transactions for more details about how Redis handle transactions.
This class is currently EXPERIMENTAL, and might change without warning.
ATTRIBUTES
connection
$conn = $self->connection;
$self = $self->connection(Mojo::Redis::Connection->new);
Holds a Mojo::Redis::Connection object.
redis
$conn = $self->connection;
$self = $self->connection(Mojo::Redis::Connection->new);
Holds a Mojo::Redis object used to create the connections to talk with Redis.
METHODS
This class has most of the methods documented in Mojo::Redis::Database, but the methods (such as set()
, incr()
, ...) will not send a command to Redis, but rather build up a command queue that is sent when calling "exec" or "exec_p".
Note that this might change in the future.
discard
$self = $self->discard(sub { my ($self, $err, $res) = @_ });
$res = $self->discard;
This method does not send any command to the Redis server. The method will simply empty the command queue.
Note that this might change in future releases.
discard_p
$promise = $self->discard_p;
Same as "discard", but returns a Mojo::Promise.
exec
$self = $self->exec(sub { my ($self, $err, $res) = @_ });
$res = $self->exec;
Will start a transaction using MULTI
, run all the commands queued and then commit at the end using EXEC
.
exec_p
$promise = $self->exec_p;
Same as "exec", but returns a Mojo::Promise.
multi
$self = $self->multi(sub { my ($self, $err, $res) = @_ });
$res = $self->multi;
Note that this might change in future releases.
multi_p
$promise = $self->multi_p;
Same as "multi", but returns a Mojo::Promise.
unwatch
$self = $self->unwatch(sub { my ($self, $err, $res) = @_ });
$res = $self->unwatch;
Forget about all watched keys.
See https://redis.io/commands/unwatch for more information.
unwatch_p
$promise = $self->unwatch_p($key);
Same as "unwatch", but returns a Mojo::Promise.
watch
$self = $self->watch($key, sub { my ($self, $err, $res) = @_ });
$res = $self->watch($key);
Watch the given keys to determine execution of the MULTI/EXEC block.
See https://redis.io/commands/watch for more information.
watch_p
$promise = $self->watch_p($key);
Same as "watch", but returns a Mojo::Promise.