forked from memcachier/examples-django
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pylibmc_test.py
47 lines (39 loc) · 1.05 KB
/
pylibmc_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import pylibmc
import sys
import time
mc_srvs = os.environ.get('MEMCACHIER_SERVERS', '').split(',')
mc_user = os.environ.get('MEMCACHIER_USERNAME', '')
mc_pass = os.environ.get('MEMCACHIER_PASSWORD', '')
mc = pylibmc.Client(
mc_srvs,
username=mc_user,
password=mc_pass,
binary=True,
behaviors={
# Enable faster IO
'tcp_nodelay': True,
'tcp_keepalive': True,
# Timeout settings
'connect_timeout': 2000, # ms
'send_timeout': 750 * 1000, # us
'receive_timeout': 750 * 1000, # us
'_poll_timeout': 2000, # ms
# Better failover
'ketama': True,
'remove_failed': 1,
'retry_timeout': 2,
'dead_timeout': 30,
}
)
print mc.behaviors
mc["get_key"] = "value"
while True:
try:
time.sleep(0.5)
print mc["get_key"]
except KeyboardInterrupt:
print "Exit..."
break
except:
print "Unexpected error:", sys.exc_info()[0]