我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用memcache.Client()。
def import_preferred_memcache_lib(self, servers): """Returns an initialized memcache client. Used by the constructor.""" try: import pylibmc except ImportError: pass else: return pylibmc.Client(servers) try: from google.appengine.api import memcache except ImportError: pass else: return memcache.Client() try: import memcache except ImportError: pass else: return memcache.Client(servers) # backwards compatibility
def _get_server(self, key): if isinstance(key, tuple): serverhash, key = key else: serverhash = serverHashFunction(key) if not self.buckets: return None, None for i in range(Client._SERVER_RETRIES): server = self.buckets[serverhash % len(self.buckets)] if server.connect(): # print("(using server %s)" % server,) return server, key serverhash = serverHashFunction(str(serverhash) + str(i)) return None, None
def kestel_info(): MYSQL = Mysql.MYSQL(USER, PASSWORD, HOST, PORT, DB) cmd = "truncate table kestrel;" MYSQL.Run(cmd) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('172.16.16.50', 22222)) INFOS = json.loads(sock.recv(86400)) for key in INFOS: try: if 'kestrel_' in key: for ip_key in INFOS[key]: if '172.16.' in ip_key: ip = ip_key.split(':')[0] ks = kestrel.Client(['%s:22133' % ip.strip()]) st = ks.stats()[1]['queues'] for k in st: v = st[k] data = (ip,'22133', str(k.replace("'", "")), str(v['items'])) cmd = "insert into kestrel (kestrel_ip,kestrel_port,kestrel_key,kestrel_num) values('%s',%s,'%s',%s);" % data MYSQL.Run(cmd) except: continue
def _get_server(self, key): if isinstance(key, tuple): serverhash, key = key else: serverhash = serverHashFunction(key) if not self.buckets: return None, None for i in range(Client._SERVER_RETRIES): server = self.buckets[serverhash % len(self.buckets)] if server.connect(): # print("(using server %s)" % server,) return server, key serverhash = str(serverhash) + str(i) if isinstance(serverhash, six.text_type): serverhash = serverhash.encode('ascii') serverhash = serverHashFunction(serverhash) return None, None
def daily_open(self): # ????memcache python realtime.py daily_open 2 today = self.tools.d_date('%Y%m%d') mcache = memcache.Client(['127.0.0.1:11211']) #today = 20160725 #_hash2 = "%s==black_list" % today ax = self.mysql.getRecord("select * from s_stock_list where dateline=%s " % today) black_list = {} for i in range(0, len(ax)): ms = re.findall(re.compile(r'\*|N|ST|??|??'), ax[i]['name']) if ax[i]['run_market'] > 40000000000 or ax[i]['listing_date'] == 0 or ms: black_list[ax[i]['s_code']] = 1 _hash = "%s==%s" % (today, ax[i]['s_code']) has = mcache.get(_hash) if has: continue _top = float(ax[i]['last_close']) * 1.1 _bottom = float(ax[i]['last_close']) * 0.9 d = {'open': ax[i]['open'], 'last_close': ax[i]['last_close'], 's_code': ax[i]['s_code'], 'top': _top, 'bottom': _bottom} mcache.set(_hash, d, 66400)