madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r23038: LJSUP-13604: Local cache [internal]

Committer: sbelyaev
LJSUP-13604: Local cache [internal]
U   trunk/cgi-bin/LJ/LocalCache/BerkeleyDB.pm
U   trunk/cgi-bin/LJ/LocalCache/Redis.pm
Modified: trunk/cgi-bin/LJ/LocalCache/BerkeleyDB.pm
===================================================================
--- trunk/cgi-bin/LJ/LocalCache/BerkeleyDB.pm	2012-10-03 09:17:02 UTC (rev 23037)
+++ trunk/cgi-bin/LJ/LocalCache/BerkeleyDB.pm	2012-10-03 09:17:58 UTC (rev 23038)
@@ -119,6 +119,7 @@
 sub set {
     my ($class, $key, $data, $expire) = @_;
 
+    $data ||= '';
     $expire ||= 10 * 60;
     my $expire_time = time() + $expire; 
     my $cache_data = "$expire_time:$data";

Modified: trunk/cgi-bin/LJ/LocalCache/Redis.pm
===================================================================
--- trunk/cgi-bin/LJ/LocalCache/Redis.pm	2012-10-03 09:17:02 UTC (rev 23037)
+++ trunk/cgi-bin/LJ/LocalCache/Redis.pm	2012-10-03 09:17:58 UTC (rev 23038)
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use utf8;
+use Encode;
 use Redis;
 
 my $local_connection;
@@ -19,14 +19,8 @@
         }
     }    
 
-    if ($local_connection) {
-        $local_connection = undef
-            unless $local_connection->ping;
-        return $local_connection;
-    }
-     
-    $local_connection = eval { Redis->new(encoding => undef, 
-                                          debug => 0) };
+    $local_connection = eval { Redis->new( encoding => undef,
+                                           debug => 0) };
     if ($@ && $LJ::IS_DEV_SERVER) {
         warn "get read connection error: $@";
     }
@@ -42,11 +36,11 @@
     $master_connection = eval { Redis->new(
         server => $LJ::MASTER_REDIS_LIGTH_CACHE,
         debug  => 0,
-        encoding => undef); 
+        encoding => undef ); 
     };
     
     if ($@ && $LJ::IS_DEV_SERVER) {
-        warn "get write conenction error: $@" if $LJ::IS_DEV_SERVER;
+        warn "get write conenction error: $@";
         return;
     }
 
@@ -61,9 +55,9 @@
     }
 
     my $value = $connection->get($key);
-
-    return unless $value;
-    return utf8::encode($value);
+    # Redis 1.2001 enable utf8 for received data
+    Encode::_utf8_off($value);
+    return $value;
 }
 
 sub get_multi {
@@ -82,7 +76,8 @@
         my $value = shift @data;
 
         if ($value) {
-            $result->{$key} = utf8::encode($value); 
+            Encode::_utf8_off($value);
+            $result->{$key} = $value;
         } else {
             push @{$not_fetched_keys}, $key;
         }
@@ -94,13 +89,13 @@
 sub set {
     my ($class, $key, $value, $expire) = @_;
     my $connection = __get_write_conneciton();
-    if (!$connection || !$value) {
+    if (!$connection) {
         return 0;
     }
 
     my $result = $connection->set( $key, 
-                                   utf8::decode($value) );
-
+                                   $value);
+    
     if ($expire) {
         $connection->expire($key, $expire);
     }
@@ -186,7 +181,6 @@
         return 0;
     }
 
-    $value = utf8::decode($value);
     return $connection->rpush($key, $value);    
 }
 
@@ -198,7 +192,6 @@
         return 0;
     }
 
-    $value = utf8::decode($value);
     return $connection->lpush($key, $value);
 }
 
@@ -212,7 +205,8 @@
 
     my $value = $connection->lpop($key);
     return unless $value;
-    return unf8::encode($value);
+    Encode::_utf8_off($value);
+    return return $value;;
 }
 
 sub rpop {
@@ -225,9 +219,9 @@
 
     my $value = $connection->rpop($key);
     return unless $value;
-    return unf8::encode($value);
+    Encode::_utf8_off($value);
+    return $value;
 }
 
 1;
 
-

Tags: livejournal, madeon, pm, sbelyaev
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments