|
| 1 | +=encoding utf8 |
| 2 | + |
| 3 | +=head1 NAME |
| 4 | + |
| 5 | +MojoX::Session::Store::Redis - RedisDB Store for MojoX::Session |
| 6 | + |
| 7 | +=head1 VERSION |
| 8 | + |
| 9 | +Version 0.09 |
| 10 | + |
| 11 | + |
| 12 | +=cut |
| 13 | + |
| 14 | +=head1 SYNOPSIS |
| 15 | + |
| 16 | + my $session = MojoX::Session->new( |
| 17 | + tx => $tx, |
| 18 | + store => MojoX::Session::Store::Redis->new({ |
| 19 | + server => '127.0.0.1:6379', |
| 20 | + redis_prefix => 'mojo-session', |
| 21 | + redis_dbid => 0, |
| 22 | + }), |
| 23 | + transport => MojoX::Session::Transport::Cookie->new, |
| 24 | + ); |
| 25 | + |
| 26 | + # see doc for MojoX::Session |
| 27 | + # see doc for Redis |
| 28 | + |
| 29 | +And later when you need to use it in Mojolicious Controller |
| 30 | + |
| 31 | + my $session = $self->stash('mojox-session'); |
| 32 | + $session->load; |
| 33 | + $session->create unless $session->sid; |
| 34 | + |
| 35 | + #set |
| 36 | + $session->data( |
| 37 | + id => 5, |
| 38 | + name => 'hoge', |
| 39 | + ); |
| 40 | + |
| 41 | + #get |
| 42 | + my $name = $session->data('name'); |
| 43 | + |
| 44 | + |
| 45 | +=head1 DESCRIPTION |
| 46 | + |
| 47 | +L<MojoX::Session::Store::Redis> is a store for L<MojoX::Session> that stores a |
| 48 | +session in a L<Redis> database. |
| 49 | + |
| 50 | + |
| 51 | +=head1 ATTRIBUTES |
| 52 | + |
| 53 | +L<MojoX::Session::Store::Redis> implements the following attributes. |
| 54 | + |
| 55 | +=head2 C<redis> |
| 56 | + |
| 57 | +Get and set Redis object. See doc for L<Redis> param. |
| 58 | + |
| 59 | + $store->redis( Redis->new($param) ); |
| 60 | + my $redis = $store->redis; |
| 61 | + |
| 62 | +=head2 C<redis_prefix> |
| 63 | + |
| 64 | +Get and set the Key prefix of the stored session in Redis. |
| 65 | +Default is 'mojo-session'. |
| 66 | + |
| 67 | + $store->redis_prefix('mojo-session'); |
| 68 | + my $prefix = $store->redis_prefix; |
| 69 | + |
| 70 | +=head2 C<redis_dbid> |
| 71 | + |
| 72 | +Get and set the DB ID Number to use in Redis DB. |
| 73 | +Default is 0. |
| 74 | + |
| 75 | + $store->redis_dbid(0); |
| 76 | + my $dbid = $store->redis_dbid; |
| 77 | + |
| 78 | +=head2 C<auto_purge> |
| 79 | + |
| 80 | +Enable/disable auto purge. |
| 81 | +When enable, session object/data stored in RedisDB will be automatically purged after TTL. |
| 82 | +This is done by setting expire time for objects just right after creating them. |
| 83 | +Changing this can only affect on objects created/updated after the change. |
| 84 | +Default is 1 (enable). |
| 85 | + |
| 86 | + $store->auto_purge(1); |
| 87 | + my $is_auto_purge_enabled = $store->auto_purge; |
| 88 | + |
| 89 | +=head1 METHODS |
| 90 | + |
| 91 | +L<MojoX::Session::Store::Redis> inherits all methods from |
| 92 | +L<MojoX::Session::Store>, and few more. |
| 93 | + |
| 94 | +=head2 C<new> |
| 95 | + |
| 96 | +C<new> uses the redis_prefix and redis_dbid parameters for the Key name prefix |
| 97 | +and the DB ID Number respectively. All other parameters are passed to C<Redis->new()>. |
| 98 | + |
| 99 | +=head2 C<create> |
| 100 | + |
| 101 | +Insert session to Redis. |
| 102 | + |
| 103 | +=head2 C<update> |
| 104 | + |
| 105 | +Update session in Redis. |
| 106 | + |
| 107 | +=head2 C<load> |
| 108 | + |
| 109 | +Load session from Redis. |
| 110 | + |
| 111 | +=head2 C<delete> |
| 112 | + |
| 113 | +Delete session from Redis. |
| 114 | + |
| 115 | + |
| 116 | +=head1 AUTHOR |
| 117 | + |
| 118 | +BlueT - Matthew Lien - 練喆明, C<< <BlueT at BlueT.org> >> |
| 119 | + |
| 120 | + |
| 121 | +=head1 BUGS |
| 122 | + |
| 123 | +Please report any bugs or feature requests to C<bug-mojox-session-store-redis at rt.cpan.org>, or through |
| 124 | +the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MojoX-Session-Store-Redis>. I will be notified, and then you'll |
| 125 | +automatically be notified of progress on your bug as I make changes. |
| 126 | + |
| 127 | + |
| 128 | +=head1 CREDITS |
| 129 | + |
| 130 | +Tatsuya Fukata, L<https://github.com/fukata> |
| 131 | + |
| 132 | +=head1 CONTRIBUTE |
| 133 | + |
| 134 | +Main: |
| 135 | + |
| 136 | + bzr repository etc at L<https://launchpad.net/p5-mojox-session-store-redis>. |
| 137 | + |
| 138 | +A copy of the codes: |
| 139 | + |
| 140 | + git repository etc at L<https://github.com/BlueT/p5-MojoX-Session-Store-Redis>. |
| 141 | + |
| 142 | + |
| 143 | +=head1 SUPPORT |
| 144 | + |
| 145 | +You can find documentation for this module with the perldoc command. |
| 146 | + |
| 147 | + perldoc MojoX::Session::Store::Redis |
| 148 | + |
| 149 | + |
| 150 | +You can also look for information at: |
| 151 | + |
| 152 | +=over 4 |
| 153 | + |
| 154 | +=item * RT: CPAN's request tracker |
| 155 | + |
| 156 | +L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Session-Store-Redis> |
| 157 | + |
| 158 | +=item * AnnoCPAN: Annotated CPAN documentation |
| 159 | + |
| 160 | +L<http://annocpan.org/dist/MojoX-Session-Store-Redis> |
| 161 | + |
| 162 | +=item * CPAN Ratings |
| 163 | + |
| 164 | +L<http://cpanratings.perl.org/d/MojoX-Session-Store-Redis> |
| 165 | + |
| 166 | +=item * Search CPAN |
| 167 | + |
| 168 | +L<http://search.cpan.org/dist/MojoX-Session-Store-Redis/> |
| 169 | + |
| 170 | +=back |
| 171 | + |
| 172 | + |
| 173 | +=head1 ACKNOWLEDGEMENTS |
| 174 | + |
| 175 | + |
| 176 | +=head1 LICENSE AND COPYRIGHT |
| 177 | + |
| 178 | +Copyright 2011 BlueT - Matthew Lien - 練喆明. |
| 179 | + |
| 180 | +This program is free software; you can redistribute it and/or modify it |
| 181 | +under the terms of either: the GNU General Public License as published |
| 182 | +by the Free Software Foundation; or the Artistic License. |
| 183 | + |
| 184 | +See http://dev.perl.org/licenses/ for more information. |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | +=cut |
| 189 | + |
0 commit comments