Skip to content

mpak/Redis-Connector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME
    Redis::Connector - wrapper around Redis with autoreconnect support

SYNOPSIS
        use Redis::Connector;
        my $conn = Redis::Connector->new();
        # or my $conn = Redis::Connector->new({});
    
        # access to Redis object
        $conn->handle->incr('foo');
    
        # transaction procession
        eval {
            my @values = $conn->transaction(sub {
                my $r = shift;
                $r->incr('foo');
            });
            # transaction complete
            # @values contains result of exec()
        };
        if ( $@ ) {
            # transaction failed, discard() already executed
        }

DESCRIPTION
    Reconnect to Redis DB after fork() or in case of ping() failures.
    Provide handy transaction procession. Does not delegate to methods of
    Redis.

METHODS
  "new(arg => value)"
  "new({ arg => value })"
    Create object. Arguments are the same as for "Redis->new()". Additional
    arguments:

    password
        If present will automatically call auth() after connect.

    dbindex
        Database index. Will be automatically selected after connect.

  "handle()"
    Return Redis instance. First it checks that PID was not changed from
    last time. Then calls ping() and in case of failure tries create new
    Redis object.

  "transaction(CODE)"
    If error occured during transaction every following multi() will throw
    exception. So you should explicitly run discard().

        try {
            $r->multi();
            ...
            $r->exec();
        }
        catch {
            # Oops!
            $r->discard();
        };

    This method do it for you. It executes CODE in transaction with Redis
    instance in first argument (so it will not reconnect on failure). On
    failure it will call discard() and rethrow exception. On success return
    result of exec().

SEE ALSO
    Redis

AUTHOR
    Andrey Fedorov <secrethost@gmail.com>

COPYRIGHT AND LICENSE
    Copyright (C) 2011 by Andrey Fedorov

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

About

Redis connection management.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages