Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

now using a cursor to pick the server - this way the retry-loop has a…

… chance to try different servers
  • Loading branch information...
commit c782b7c7a30ed39753a6f792ec5fb17b75864e9c 1 parent 3044f55
@tarekziade tarekziade authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 memcachepool/cache.py
View
9 memcachepool/cache.py
@@ -4,7 +4,6 @@
import pickle # NOQA
import errno
-import random
import socket
import time
@@ -38,6 +37,7 @@ def __init__(self, server, params):
wait_for_connection=self.socktimeout)
self._blacklist = {}
self.retries = int(params.get('MAX_RETRIES', 3))
+ self._pick_index = 0
def call(self, func, *args, **kwargs):
retries = 0
@@ -79,7 +79,12 @@ def _pick_server(self):
if not choices:
return None
- return random.choice(choices)
+ if self._pick_index >= len(choices):
+ self._pick_index = 0
+
+ choice = choices[self._pick_index]
+ self._pick_index += 1
+ return choice
def _blacklist_server(self, server):
self._blacklist[server] = time.time()
Please sign in to comment.
Something went wrong with that request. Please try again.