madeon (madeon) wrote in changelog,
madeon
madeon
changelog

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

Committer: sbelyaev
LJSUP-13604: Local cache [internal]
U   trunk/cgi-bin/LJ/LocalCache/Redis.pm
Modified: trunk/cgi-bin/LJ/LocalCache/Redis.pm
===================================================================
--- trunk/cgi-bin/LJ/LocalCache/Redis.pm	2012-09-17 10:35:29 UTC (rev 22900)
+++ trunk/cgi-bin/LJ/LocalCache/Redis.pm	2012-09-17 10:50:27 UTC (rev 22901)
@@ -4,15 +4,28 @@
 use strict;
 use warnings;
 
+use Redis;
+
 my $local_connection;
 my $master_connection;
 
 sub __get_read_connection {
     if ($local_connection) {
+        if ($local_connection->ping) {
+            return $local_connection;
+        } else {
+            $local_connection = undef;
+        }
+    }    
+
+    if ($local_connection) {
+        $local_connection = undef
+            unless $local_connection->ping;
         return $local_connection;
     }
      
-    $local_connection = eval { Redis->new(encoding => undef) };
+    $local_connection = eval { Redis->new(encoding => undef, 
+                                          debug => 0) };
     if ($@ && $LJ::IS_DEV_SERVER) {
         warn "get read connection error: $@";
     }
@@ -46,7 +59,9 @@
         return;
     }
 
-    return $connection->get($key);
+    my $recv_data = $connection->get($key);
+
+    return utf8::decode($recv_data);
 }
 
 sub get_multi {
@@ -65,7 +80,7 @@
         my $value = shift @data;
 
         if ($value) {
-            $result->{$key} = $value; 
+            $result->{$key} = utf8::encode($value); 
         } else {
             push @{$not_fetched_keys}, $key;
         }
@@ -82,7 +97,7 @@
     }
 
     my $result = $connection->set( $key, 
-                                   $value );
+                                   utf8::decode($value) );
     $connection->expire($key, $expire);
     return $result;
 }

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