Created
May 14, 2013 17:29
-
-
Save Wu-Wu/5577823 to your computer and use it in GitHub Desktop.
testing Dancer::Session::Redis and Dancer::Serializer::JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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