Skip to content

Instantly share code, notes, and snippets.

@lericson
Created December 4, 2011 17:02
Show Gist options
  • Save lericson/1430689 to your computer and use it in GitHub Desktop.
Save lericson/1430689 to your computer and use it in GitHub Desktop.
Failover test
import _pylibmc, pylibmc
from time import time, sleep
mc = pylibmc.Client(["127.0.0.1:11211", "127.0.0.1:11212"])
mc.behaviors.update({"remove_failed": 2,
"ketama": True,
"ketama_hash": True,
"_retry_timeout": 2})
print "libmemcached", _pylibmc.libmemcached_version
__import__("pprint").pprint(mc.behaviors)
t0 = time()
td = lambda: "%03.02f" % (time() - t0)
while True:
sleep(5)
try:
print td(), "set =>",
print mc.set("foo", "bar")
sleep(0.125)
print td(), "get =>",
print mc.get("foo")
sleep(0.125)
except pylibmc.Error as e:
print "failed", type(e), e
sleep(0.125)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment