Christophe Nowicki > Dancer-Plugin-Redis-0.02 > Dancer::Plugin::Redis

Download:
Dancer-Plugin-Redis-0.02.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.02   Source   Latest Release: Dancer-Plugin-Redis-0.8

NAME ^

Dancer::Plugin::Redis - easy database connections for Dancer applications

SYNOPSIS ^

    use Dancer;
    use Dancer::Plugin::Redis;

    # Calling the redis keyword will get you a connected Redis Database handle:
    get '/widget/view/:id' => sub {
        template 'display_widget', { widget => redis->get('hash_key'); };
    };

    dance;

Redis connection details are read from your Dancer application config - see below.

DESCRIPTION ^

Provides an easy way to obtain a connected Redis database handle by simply calling the redis keyword within your Dancer application.

Takes care of ensuring that the database handle is still connected and valid. If the handle was last asked for more than connection_check_threshold seconds ago, it will check that the connection is still alive, using either the $r->ping method if the Redis driver supports it, or performing a simple no-op query against the database if not. If the connection has gone away, a new connection will be obtained and returned. This avoids any problems for a long-running script where the connection to the database might go away.

CONFIGURATION ^

Connection details will be taken from your Dancer application config file, and should be specified as, for example:

    plugins:
        Redis:
            server: '127.0.0.1:6379'
            debug: 0

The connectivity-check-threshold setting is optional, if not provided, it will default to 30 seconds. If the database keyword was last called more than this number of seconds ago, a quick check will be performed to ensure that we still have a connection to the database, and will reconnect if not. This handles cases where the database handle hasn't been used for a while and the underlying connection has gone away.

GETTING A DATABASE HANDLE ^

Calling redis will return a connected database handle; the first time it is called, the plugin will establish a connection to the database, and return a reference to the DBI object. On subsequent calls, the same DBI connection object will be returned, unless it has been found to be no longer usable (the connection has gone away), in which case a fresh connection will be obtained.

If you have declared named connections as described above in 'DEFINING MULTIPLE CONNECTIONS', then calling the database() keyword with the name of the connection as specified in the config file will get you a database handle connected with those details.

AUTHOR ^

Christophe Nowicki, <cscm@csquad.org>

CONTRIBUTING ^

This module is developed on Github at:

https://github.com/cscm/Dancer-Plugin-Redis

Feel free to fork the repo and submit pull requests!

ACKNOWLEDGEMENTS ^

Igor Bujna, David Precious

BUGS ^

Please report any bugs or feature requests to bug-dancer-plugin-database at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-Redis. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Dancer::Plugin::Redis

You can also look for information at:

You can find the author on IRC in the channel #dancer on <irc.perl.org>.

LICENSE AND COPYRIGHT ^

Copyright 2010 Christophe Nowicki.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

SEE ALSO ^

Dancer

DBI

syntax highlighting: