X-Git-Url: http://git.rot13.org/?p=perl-Redis.git;a=blobdiff_plain;f=lib%2FRedis.pm;h=8df6779a2d5b1ed08a897aaaedebcffa27a81bd0;hp=2caa3b782846d2cd60b579020dabde9f9983f373;hb=HEAD;hpb=e99389aa9c654dacda29dfe72d070c1f6f9d043c
diff --git a/lib/Redis.pm b/lib/Redis.pm
index 2caa3b7..8df6779 100644
--- a/lib/Redis.pm
+++ b/lib/Redis.pm
@@ -4,8 +4,9 @@ use warnings;
use strict;
use IO::Socket::INET;
-use Data::Dump qw/dump/;
+use Data::Dumper;
use Carp qw/confess/;
+use Encode;
=head1 NAME
@@ -13,14 +14,14 @@ Redis - perl binding for Redis database
=cut
-our $VERSION = '0.0801';
+our $VERSION = '1.2001';
=head1 DESCRIPTION
Pure perl bindings for L
-This version support git version 0.08 or later of Redis available at
+This version supports protocol 1.2 or later of Redis available at
L
@@ -61,6 +62,13 @@ my $bulk_command = {
sadd => 1, srem => 1,
sismember => 1,
echo => 1,
+ getset => 1,
+ smove => 1,
+ zadd => 1,
+ zrem => 1,
+ zscore => 1,
+ zincrby => 1,
+ append => 1,
};
# we don't want DESTROY to fallback into AUTOLOAD
@@ -70,12 +78,14 @@ our $AUTOLOAD;
sub AUTOLOAD {
my $self = shift;
+ use bytes;
+
my $sock = $self->{sock} || die "no server connected";
my $command = $AUTOLOAD;
$command =~ s/.*://;
- warn "## $command ",dump(@_) if $self->{debug};
+ warn "## $command ",Dumper(@_) if $self->{debug};
my $send;
@@ -108,6 +118,7 @@ sub AUTOLOAD {
}
my $result = <$sock> || die "can't read socket: $!";
+ Encode::_utf8_on($result);
warn "<< $result" if $self->{debug};
my $type = substr($result,0,1);
$result = substr($result,1,-2);
@@ -126,7 +137,7 @@ sub AUTOLOAD {
}
if ( $type eq '-' ) {
- confess $result;
+ confess "[$command] $result";
} elsif ( $type eq '+' ) {
return $result;
} elsif ( $type eq '$' ) {
@@ -142,12 +153,13 @@ sub AUTOLOAD {
sub __read_bulk {
my ($self,$len) = @_;
- return undef if $len < 0;
+ return if $len < 0;
my $v;
if ( $len > 0 ) {
read($self->{sock}, $v, $len) || die $!;
- warn "<< ",dump($v),$/ if $self->{debug};
+ Encode::_utf8_on($v);
+ warn "<< ",Dumper($v),$/ if $self->{debug};
}
my $crlf;
read($self->{sock}, $crlf, 2); # skip cr/lf
@@ -156,7 +168,7 @@ sub __read_bulk {
sub __read_multi_bulk {
my ($self,$size) = @_;
- return undef if $size < 0;
+ return if $size < 0;
my $sock = $self->{sock};
$size--;
@@ -166,7 +178,7 @@ sub __read_multi_bulk {
$list[ $_ ] = $self->__read_bulk( substr(<$sock>,1,-2) );
}
- warn "## list = ", dump( @list ) if $self->{debug};
+ warn "## list = ", Dumper( @list ) if $self->{debug};
return @list;
}
@@ -360,6 +372,14 @@ See also L for tie interface.
my $info_hash = $r->info;
+=head1 ENCODING
+
+Since Redis knows nothing about encoding, we are forcing utf-8 flag on all data received from Redis.
+This change is introduced in 1.2001 version.
+
+This allows us to round-trip utf-8 encoded characters correctly, but might be problem if you push
+binary junk into Redis and expect to get it back without utf-8 flag turned on.
+
=head1 AUTHOR
Dobrica Pavlinusic, C<< >>
@@ -410,7 +430,7 @@ L
=head1 COPYRIGHT & LICENSE
-Copyright 2009 Dobrica Pavlinusic, all rights reserved.
+Copyright 2009-2010 Dobrica Pavlinusic, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.