madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r23376: LJSUP-14388: [internal] Simplify local r...

Committer: sbelyaev
LJSUP-14388: [internal] Simplify local redis connection managment
U   trunk/cgi-bin/LJ/LocalCache/Redis.pm
Modified: trunk/cgi-bin/LJ/LocalCache/Redis.pm
===================================================================
--- trunk/cgi-bin/LJ/LocalCache/Redis.pm	2012-11-28 07:47:05 UTC (rev 23375)
+++ trunk/cgi-bin/LJ/LocalCache/Redis.pm	2012-11-28 08:38:20 UTC (rev 23376)
@@ -7,9 +7,8 @@
 use Redis;
 
 my $local_connection;
-my $master_connection;
 
-sub __get_read_connection {
+sub __get_connection {
     if ($local_connection) {
         if ($local_connection->ping) {
             return $local_connection;
@@ -22,38 +21,15 @@
                                            sock   => $LJ::LOCAL_REDIS_UNIX_SOCKET,
                                            debug => 0) };
     if ($@ && $LJ::IS_DEV_SERVER) {
-        warn "get read connection error: $@";
+        warn "connection error: $@";
     }
 
     return $local_connection;
 }
 
-sub __get_write_conneciton {
-    if ($master_connection) {
-        return $master_connection;
-    }  
-
-    if (! $LJ::MASTER_REDIS_LIGTH_CACHE) {
-        return __get_read_connection();
-    } 
-
-    $master_connection = eval { Redis->new(
-        server => $LJ::MASTER_REDIS_LIGTH_CACHE,
-        debug  => 0,
-        encoding => undef ); 
-    };
-    
-    if ($@ && $LJ::IS_DEV_SERVER) {
-        warn "get write conenction error: $@";
-        return;
-    }
-
-    return $master_connection;
-}
-
 sub get {
     my ($class,$key) = @_;
-    my $connection = __get_read_connection();
+    my $connection = __get_connection();
     if (!$connection) {
         return;
     }
@@ -64,7 +40,7 @@
 sub get_multi {
     my ($class, $keys, $not_fetched_keys) = @_;
 
-    my $connection = __get_read_connection();
+    my $connection = __get_connection();
     if (!$connection) {
         @$not_fetched_keys = @$keys;
         return;
@@ -88,7 +64,7 @@
 
 sub set {
     my ($class, $key, $value, $expire) = @_;
-    my $connection = __get_write_conneciton();
+    my $connection = __get_connection();
     if (!$connection) {
         return 0;
     }
@@ -105,7 +81,7 @@
 
 sub expire {
     my ($class, $key, $expire) = @_;
-    my $connection = __get_write_conneciton();
+    my $connection = __get_connection();
     if (!$connection) {
         return 0;
     }
@@ -120,7 +96,7 @@
 
 sub delete {
     my ($class, $key) = @_;
-    my $connection = __get_write_conneciton();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return 0;
@@ -131,7 +107,7 @@
 
 sub incr {
     my ($class, $key, $value) = @_;
-    my $connection = __get_write_connection();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return 0;
@@ -147,7 +123,7 @@
 
 sub decr {
     my ($class, $key, $value) = @_;
-    my $connection = __get_write_connection();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return 0;
@@ -164,7 +140,7 @@
 
 sub exists {
     my ($class, $key) = @_;
-    my $connection = __get_read_connection();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return 0;
@@ -175,7 +151,7 @@
 
 sub rpush {
     my ($class, $key, $value) = @_;
-    my $connection = __get_write_connection();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return 0;
@@ -186,7 +162,7 @@
 
 sub lpush {
     my ($class, $key, $value) = @_;
-    my $connection = __get_write_connection();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return 0;
@@ -197,7 +173,7 @@
 
 sub lpop {
     my ($class, $key) = @_;
-    my $connection = __get_read_connection();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return undef;
@@ -208,7 +184,7 @@
 
 sub rpop {
     my ($class, $key) = @_;
-    my $connection = __get_read_connection();
+    my $connection = __get_connection();
 
     if (!$connection) {
         return undef;

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