contrib: first work on Apache::Session::NoSQL
This commit is contained in:
parent
7f427610fe
commit
908ed6fa37
19
contribs/apache-session-nosql/examples/simple.pl
Normal file
19
contribs/apache-session-nosql/examples/simple.pl
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
use Apache::Session::NoSQL;
|
||||
|
||||
my %session1;
|
||||
tie %session1, 'Apache::Session::NoSQL', undef, {
|
||||
Driver => 'Cassandra',
|
||||
Hostname => 'localhost',
|
||||
};
|
||||
$session1{visa_number} = "1234 5678 9876 5432";
|
||||
my $id = $session1{_session_id};
|
||||
untie %session1;
|
||||
|
||||
my %session2;
|
||||
tie %session2, 'Apache::Session::MySQL', $id, {
|
||||
Driver => 'Cassandra',
|
||||
Hostname => 'localhost',
|
||||
};
|
||||
tied(%session2)->delete;
|
||||
|
52
contribs/apache-session-nosql/lib/Apache/Session/NoSQL.pm
Normal file
52
contribs/apache-session-nosql/lib/Apache/Session/NoSQL.pm
Normal file
@ -0,0 +1,52 @@
|
||||
package Apache::Session::NoSQL;
|
||||
|
||||
use strict;
|
||||
use base qw(Apache::Session);
|
||||
use Apache::Session::Generate::MD5;
|
||||
use Apache::Session::Lock::Null;
|
||||
use Apache::Session::Serialize::Storable;
|
||||
use Apache::Session::Store::NoSQL;
|
||||
|
||||
use vars qw($VERSION);
|
||||
$VERSION = '0.01';
|
||||
|
||||
sub populate {
|
||||
my $self = shift;
|
||||
|
||||
$self->{object_store} = new Apache::Session::Store::NoSQL;
|
||||
$self->{lock_manager} = new Apache::Session::Lock::Null;
|
||||
$self->{generate} = \&Apache::Session::Generate::MD5::generate;
|
||||
$self->{validate} = \&Apache::Session::Generate::MD5::validate;
|
||||
$self->{serialize} = \&Apache::Session::Serialize::Storable::serialize;
|
||||
$self->{unserialize} = \&Apache::Session::Serialize::Storable::unserialize;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Apache::Session::NoSQL
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Thomas Chemineau, E<lt>thomas.chemineau@gmail.comE<gt>
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
Copyright (C) 2010 by Thomas Chemineau
|
||||
|
||||
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,
|
||||
at your option, any later version of Perl 5 you may have available.
|
||||
|
||||
=cut
|
@ -0,0 +1,76 @@
|
||||
package Apache::Session::Store::NoSQL;
|
||||
|
||||
use strict;
|
||||
|
||||
use vars qw($VERSION);
|
||||
$VERSION = '0.01';
|
||||
|
||||
sub new {
|
||||
my ( $class, $session ) = @_;
|
||||
my $self;
|
||||
|
||||
if ( $session->{args}->{Driver} ) {
|
||||
my $driver = $session->{args}->{Driver};
|
||||
$self->{driver} = $driver
|
||||
$self->{cache} = new Apache::Session::Store::NoSQL::$driver;
|
||||
}
|
||||
else {
|
||||
die 'No driver specified.';
|
||||
}
|
||||
|
||||
bless $self,$class;
|
||||
}
|
||||
|
||||
sub insert {
|
||||
my ( $self, $session ) = @_;
|
||||
$self->{cache}->set(
|
||||
$session->{data}->{_session_id},
|
||||
$session->{serialized} );
|
||||
}
|
||||
|
||||
sub update {
|
||||
my ( $self, $session ) = @_;
|
||||
$self->{cache}->replace(
|
||||
$session->{data}->{_session_id},
|
||||
$session->{serialized} );
|
||||
}
|
||||
|
||||
sub materialize {
|
||||
my ( $self, $session ) = @_;
|
||||
$session->{serialized} = $self->{cache}->get(
|
||||
$session->{data}->{_session_id})
|
||||
or die 'Object does not exist in data store.';
|
||||
}
|
||||
|
||||
sub remove {
|
||||
my ( $self, $session ) = @_;
|
||||
$self->{cache}->delete( $session->{data}->{_session_id} );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Apache::Session::Store::NoSQL
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Thomas Chemineau, E<lt>thomas.chemineau@gmail.comE<gt>
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
Copyright (C) 2010 by Thomas Chemineau
|
||||
|
||||
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,
|
||||
at your option, any later version of Perl 5 you may have available.
|
||||
|
||||
=cut
|
@ -0,0 +1,89 @@
|
||||
package Apache::Session::Store::NoSQL::Cassandra;
|
||||
|
||||
use strict;
|
||||
use Net::Cassandra;
|
||||
|
||||
use vars qw($VERSION);
|
||||
$VERSION = '0.01';
|
||||
|
||||
sub new {
|
||||
my ( $class, $session ) = @_;
|
||||
my $self;
|
||||
|
||||
$self->{cache} = Net::Cassandra->new( %{$session} )->client;
|
||||
|
||||
bless $self,$class;
|
||||
}
|
||||
|
||||
sub insert {
|
||||
my ( $self, $session ) = @_;
|
||||
$self->{cache}->insert(
|
||||
'Keyspace1',
|
||||
$session->{data}->{_session_id},
|
||||
Net::Cassandra::Backend::ColumnPath->new(
|
||||
{ column_family => 'Standard1', column => 'name' }
|
||||
),
|
||||
$session->{serialized},
|
||||
time,
|
||||
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
|
||||
);
|
||||
}
|
||||
|
||||
sub update {
|
||||
my ( $self, $session ) = @_;
|
||||
$self->insert( %{$session} );
|
||||
}
|
||||
|
||||
sub materialize {
|
||||
my ( $self, $session ) = @_;
|
||||
$client->get(
|
||||
'Keyspace1',
|
||||
$key1,
|
||||
Net::Cassandra::Backend::ColumnPath->new(
|
||||
{ column_family => 'Standard1', column => 'name' }
|
||||
),
|
||||
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
|
||||
)
|
||||
or die 'Object does not exist in data store.';
|
||||
}
|
||||
|
||||
sub remove {
|
||||
my ( $self, $session ) = @_;
|
||||
$self->{cache}->remove(
|
||||
'Keyspace1',
|
||||
$session->{data}->{_session_id},
|
||||
Net::Cassandra::Backend::ColumnPath->new(
|
||||
{ column_family => 'Standard1', column => 'name' }
|
||||
),
|
||||
time,
|
||||
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Apache::Session::Store::NoSQL
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Thomas Chemineau, E<lt>thomas.chemineau@gmail.comE<gt>
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
Copyright (C) 2010 by Thomas Chemineau
|
||||
|
||||
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,
|
||||
at your option, any later version of Perl 5 you may have available.
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue
Block a user