Christophe Nowicki
and 1 contributors


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'); };


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 details will be taken from your Dancer application config file, and should be specified as, for example:

            server: ''
            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.


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.


Christophe Nowicki, <>


This module is developed on Github at:

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, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


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 <>.


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 for more information.