Subject: | CHI-Driver-TokyoTyrant fails several tests against latest CHI |
CHI-Driver-TokyoTyrant fails several tests against latest CHI.
For this I wrote a patch (attached) which make the tests run
successfully.
I removed all iternext/regex checks and replaced the with tyrants
fwmkeys which makes it easier and more robust against strange
namespaces, especially because the regex did not use \Q\E to protect the
variables contents.
All prefix removals of namespaces are done using substr which is faster
than a regex and does not have troubles with more than one : in
namespace/key.
I removed store_multi at all, because CHI documents but never calls it
(and it is never tested). The code looks broken, as counter++ is true
for values and false for keys.
Subject: | CHI-Driver-TokyoTyrant.patch |
--- CHI-Driver-TokyoTyrant-0.01.orig/lib/CHI/Driver/TokyoTyrant.pm 2010-05-17 17:56:36.000000000 +0200
+++ CHI-Driver-TokyoTyrant-0.01/lib/CHI/Driver/TokyoTyrant.pm 2012-04-17 08:57:37.585003542 +0200
@@ -92,19 +92,11 @@
sub clear {
my ($self) = @_;
-
my $namespace = $self->namespace;
- my @keys;
+ my $keys = $self->rdb->fwmkeys($namespace . ":", -1);
- $self->rdb->iterinit();
-
- while(defined(my $key = $self->rdb->iternext())){
- next unless $key =~ /^$namespace:/;
- push @keys, $key;
- }
-
- $self->rdb->misc('outlist', \@keys);
+ $self->rdb->misc('outlist', $keys);
}
@@ -117,12 +109,10 @@
my $namespace = $self->namespace;
- my @keys;
- while(defined(my $key = $self->rdb->iternext())){
- next unless $key =~ /^$namespace:(.+)/;
- push @keys, $1;
- }
-
+ my $keys = $self->rdb->fwmkeys($namespace . ":", -1);
+ my $l = length($namespace)+1;
+
+ my @keys = map { substr($_,$l) } @$keys;
return @keys;
@@ -150,41 +140,20 @@
sub fetch_multi_hashref {
- my ($self, @keys) = @_;
+ my ($self, $keys) = @_;
my $namespace = $self->namespace;
- @keys = map {"${namespace}:$_"} @keys;
+ my @keys = map {"${namespace}:$_"} @$keys;
my $out = $self->rdb->misc('getlist', \@keys) ||
die $self->rdb->errmsg($self->rdb->ecode);
-
- my %result = @$out;
-
-
-
- return \%result;
-}
-
-sub store_multi {
-
- my ($self, $data) = @_;
-
- my $namespace = $self->namespace;
-
- # The putlist method requires sequence of keys and values as an array ref.
- # Flatten the hashref into array and prepend current namespace to keys.
- my @data_as_array = map { my $counter++ % 2 ? "${namespace}:$_" : $_ } %$data;
-
- my $r = $self->rdb->misc('putlist', \@data_as_array);
-
- if ($r == undef) {
- die $self->rdb->errmsg($self->rdb->ecode);
- }
-
+ my $l = length($namespace)+1;
+ my $c = 0;
+ my %res = map { $c++ % 2 ? $_ : substr($_,$l) } @{$out};
+ return \%res;
}
-
1;