Skip to content

Instantly share code, notes, and snippets.

@Wu-Wu
Created May 14, 2013 17:29
Show Gist options
  • Save Wu-Wu/5577823 to your computer and use it in GitHub Desktop.
Save Wu-Wu/5577823 to your computer and use it in GitHub Desktop.
testing Dancer::Session::Redis and Dancer::Serializer::JSON
#
# Dancer::Session::Redis
# Dancer::Serializer::JSON
#
use strict;
use warnings;
use Dancer;
# set up session
set redis_session => {
server => $ENV{REDIS_SERVER} || 'localhost:6379', # this option should be tuned to fit your needs
database => 1,
expire => 300,
debug => 0,
};
set session => 'Redis';
set session_name => 'example'; # session's cookie name
set serializer => 'JSON';
# route
get '/' => sub {
# fetch old value
my $old = session->{counter};
# prepare new value
my $new = 1 + (defined $old ? $old : 0);
# save new value
session counter => $new;
+{
this_session_id => session->id,
counter => $new,
message => 'the page was loaded #' . $new,
}
};
dance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment