X-Git-Url: http://git.rot13.org/?p=perl-Redis.git;a=blobdiff_plain;f=lib%2FRedis.pm;h=8df6779a2d5b1ed08a897aaaedebcffa27a81bd0;hp=3cc595ea8d3f02bc155274833c17ba4b170f0ecb;hb=10440d1d2a277071cc6ef8022aebe76c0b3f0169;hpb=d33128faa51a25fa9f2fc748319e5a9da18d1906 diff --git a/lib/Redis.pm b/lib/Redis.pm index 3cc595e..8df6779 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -6,6 +6,7 @@ use strict; use IO::Socket::INET; use Data::Dumper; use Carp qw/confess/; +use Encode; =head1 NAME @@ -77,6 +78,8 @@ our $AUTOLOAD; sub AUTOLOAD { my $self = shift; + use bytes; + my $sock = $self->{sock} || die "no server connected"; my $command = $AUTOLOAD; @@ -115,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); @@ -149,11 +153,12 @@ 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 $!; + Encode::_utf8_on($v); warn "<< ",Dumper($v),$/ if $self->{debug}; } my $crlf; @@ -163,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--; @@ -367,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<< >>