Dancer::Plugin::Redis - easy database connections for Dancer applications
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.
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.
connection_check_threshold
$r->ping
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.
connectivity-check-threshold
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.
redis
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.
Christophe Nowicki, <cscm@csquad.org>
<cscm@csquad.org>
This module is developed on Github at:
https://github.com/cscm/Dancer-Plugin-Redis
Feel free to fork the repo and submit pull requests!
Igor Bujna, David Precious
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.
bug-dancer-plugin-database at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::Redis
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-Redis
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Dancer-Plugin-Redis
CPAN Ratings
http://cpanratings.perl.org/d/Dancer-Plugin-Redis
Search CPAN
http://search.cpan.org/dist/Dancer-Plugin-Redis/
You can find the author on IRC in the channel #dancer on <irc.perl.org>.
#dancer
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.
Dancer
DBI
To install Dancer::Plugin::Redis, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Redis
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Redis
For more information on module installation, please visit the detailed CPAN module installation guide.