Skip to content

Commit

Permalink
Merge pull request #19 from Worteks/sentinel
Browse files Browse the repository at this point in the history
allow sentinel list to be passed as a comma-delimited string
  • Loading branch information
guimard authored Jul 3, 2019
2 parents 5df061d + 4bb1b53 commit e8b5d29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
48 changes: 29 additions & 19 deletions lib/Apache/Session/Browseable/Redis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,20 @@ sub populate {

sub unserialize {
my $session = shift;
my $tmp = { serialized => $session };
my $tmp = { serialized => $session };
Apache::Session::Serialize::JSON::unserialize($tmp);
return $tmp->{data};
}

sub searchOn {
my ( $class, $args, $selectField, $value, @fields ) = @_;

# Manage undef encoding
$args->{encoding} = undef
if ( $args->{encoding} and $args->{encoding} eq "undef" );

my %res = ();
my $index =
ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ];
if ( grep { $_ eq $selectField } @$index ) {
my $redisObj = $redis->new(%$args);

# Manage database
$redisObj->select( $args->{database} ) if defined $args->{database};

my $redisObj = $class->_getRedis($args);
my @keys = $redisObj->smembers("${selectField}_$value");
foreach my $k (@keys) {
next unless ($k);
Expand Down Expand Up @@ -92,16 +85,7 @@ sub get_key_from_all_sessions {
my $data = shift;
my %res;

# Manage undef encoding
$args->{encoding} = undef
if ( $args->{encoding} and $args->{encoding} eq "undef" );

# TODO new Redis object
my $redisObj = $redis->new(%$args);

# Manage database
$redisObj->select( $args->{database} ) if defined $args->{database};

my $redisObj = $class->_getRedis($args);
my @keys = $redisObj->keys('*');
foreach my $k (@keys) {
next if ( !$k or $k =~ /_/ );
Expand All @@ -122,6 +106,32 @@ sub get_key_from_all_sessions {
return \%res;
}

sub _getRedis {
my $class = shift;
my $args = shift;

# Manage undef encoding
$args->{encoding} = undef
if ( $args->{encoding}
and $args->{encoding} eq "undef" );

# If sentinels is not given as an array ref, try to parse
# a comma delimited list instead
if ( $args->{sentinels}
and ref $args->{sentinels} ne 'ARRAY' )
{
$args->{sentinels} =
[ split /[,\s]+/, $args->{sentinels} ];
}
my $redisObj = $redis->new( %{$args} );
# Manage database
$redisObj->select( $args->{database} )
if defined $args->{database};
return $redisObj;
}
1;
__END__
Expand Down
9 changes: 9 additions & 0 deletions lib/Apache/Session/Browseable/Store/Redis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ sub new {
if ( $session->{args}->{encoding}
and $session->{args}->{encoding} eq "undef" );

# If sentinels is not given as an array ref, try to parse
# a comma delimited list instead
if ( $session->{args}->{sentinels}
and ref $session->{args}->{sentinels} ne 'ARRAY' )
{
$session->{args}->{sentinels} =
[ split /[,\s]+/, $session->{args}->{sentinels} ];
}
$self->{cache} = $redis->new( %{ $session->{args} } );
# Manage database
Expand Down

0 comments on commit e8b5d29

Please sign in to comment.