From d8b5a19c3f2f62977a6587144cdc30c063d9b028 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Mon, 6 Sep 2010 09:42:44 +0000 Subject: [PATCH] New NoSQL backend --- .../lib/Apache/Session/NoSQL.pm | 13 +++- .../lib/Apache/Session/Store/NoSQL.pm | 4 +- .../lib/Apache/Session/Store/NoSQL/Redis.pm | 66 +++++++++++++++++++ 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL/Redis.pm diff --git a/contribs/apache-session-nosql/lib/Apache/Session/NoSQL.pm b/contribs/apache-session-nosql/lib/Apache/Session/NoSQL.pm index ccbc15a21..ccaa6b58b 100644 --- a/contribs/apache-session-nosql/lib/Apache/Session/NoSQL.pm +++ b/contribs/apache-session-nosql/lib/Apache/Session/NoSQL.pm @@ -9,7 +9,7 @@ use Apache::Session::Serialize::Base64; #use Apache::Session::Serialize::Storable; use vars qw($VERSION); -$VERSION = '0.01'; +$VERSION = '0.02'; sub populate { my $self = shift; @@ -38,7 +38,13 @@ Apache::Session::NoSQL - An implementation of Apache::Session module for NoSQL d use Apache::Session::NoSQL; tie %hash, 'Apache::Session::NoSQL', $id, { - # TODO + Driver => 'Cassandra', + + # or + + Driver => 'Redis', + # optional: default to 127.0.0.1:6379 + server => '10.1.1.1:6379', }; =head1 DESCRIPTION @@ -49,10 +55,11 @@ to store datas. =head1 AUTHOR Thomas Chemineau, Ethomas.chemineau@gmail.comE +Xavier Guimard, Ex.guimard@free.frE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2010 by Thomas Chemineau +Copyright (C) 2010 by Thomas Chemineau, Xavier Guimard This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, diff --git a/contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL.pm b/contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL.pm index 2f0063ef9..5897fa4d8 100644 --- a/contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL.pm +++ b/contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL.pm @@ -3,7 +3,7 @@ package Apache::Session::Store::NoSQL; use strict; use vars qw(@ISA $VERSION); -$VERSION = '0.01'; +$VERSION = '0.02'; sub new { my ( $class, $session ) = @_; @@ -16,7 +16,7 @@ sub new { if ($@) { die 'Unable to load ' . $module; } - unless ( $self->{cache} = new $module ) { + unless ( $self->{cache} = new $module ( $session->{args} ) ) { die 'Unable to instanciate ' . $module; } } diff --git a/contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL/Redis.pm b/contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL/Redis.pm new file mode 100644 index 000000000..d4ea06d2f --- /dev/null +++ b/contribs/apache-session-nosql/lib/Apache/Session/Store/NoSQL/Redis.pm @@ -0,0 +1,66 @@ +package Apache::Session::Store::NoSQL::Redis; + +use strict; +use Redis; + +our $VERSION = '0.01'; + +sub new { + my ( $class, $session ) = @_; + my $self; + + $self->{cache} = Redis->new( %{$session} ); + print STDERR Dumper(\@_);use Data::Dumper; + + bless $self, $class; +} + +sub insert { + my ( $self, $session ) = @_; + $self->{cache}->set($session->{data}->{_session_id},$session->{serialized}); +} + +*update = *insert; + +sub materialize { + my ( $self, $session ) = @_; + $self->{cache}->get($session->{data}->{_session_id}) or die 'Object does not exist in data store.'; +} + +sub remove { + my ( $self, $session ) = @_; + $self->{cache}->del($session->{data}->{_session_id}); +} + +1; +__END__ +=pod + +=head1 NAME + +Apache::Session::Store::NoSQL::Redis - An implementation of Apache::Session::Store + +=head1 SYNOPSIS + + use Apache::Session::NoSQL; + + #if you want Apache::Session to open new DB handles: + + tie %hash, 'Apache::Session::MySQL', $id, { + Driver => 'Redis', + # optional: default to localhost + server => '127.0.0.1:6379', + }; + +=head1 DESCRIPTION + +This module is an implementation of Apache::Session::NoSQL. It uses the Redis +storage system + +=head1 AUTHOR + +This module was written by Xavier Guimard + +=head1 SEE ALSO + +L, L