本文整理匯總了Python中redis._compat.iteritems方法的典型用法代碼示例。如果您正苦於以下問題:Python _compat.iteritems方法的具體用法?Python _compat.iteritems怎麽用?Python _compat.iteritems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis._compat
的用法示例。
在下文中一共展示了_compat.iteritems方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from redis import _compat [as 別名]
# 或者: from redis._compat import iteritems [as 別名]
def __init__(self, sentinels, min_other_sentinels=0, sentinel_kwargs=None,
**connection_kwargs):
# if sentinel_kwargs isn't defined, use the socket_* options from
# connection_kwargs
if sentinel_kwargs is None:
sentinel_kwargs = {
k: v
for k, v in iteritems(connection_kwargs)
if k.startswith('socket_')
}
self.sentinel_kwargs = sentinel_kwargs
self.sentinels = [Redis(hostname, port, **self.sentinel_kwargs)
for hostname, port in sentinels]
self.min_other_sentinels = min_other_sentinels
self.connection_kwargs = connection_kwargs
示例2: run_in_thread
# 需要導入模塊: from redis import _compat [as 別名]
# 或者: from redis._compat import iteritems [as 別名]
def run_in_thread(self, sleep_time=0):
'''
Replacement for the default PubSub run_in_thread method from
http://github.com/andymccurdy/redis-py/master/redis/client.py
'''
for channel, handler in iteritems(self.channels):
if handler is None:
raise PubSubError("Channel: '%s' has no handler registered" % channel)
for pattern, handler in iteritems(self.channels):
if handler is None:
raise PubSubError("Pattern: '%s' has no handler registered" % pattern)
pubsub = self
class WorkerThread(threading.Thread):
''' Listens for messages on subscriptions '''
def __init__(self, *args, **kwargs):
super(WorkerThread, self).__init__(*args, **kwargs)
self.daemon = True
self._running = False
def run(self):
''' loop while running on subscriptions '''
if self._running:
return
self._running = True
while self._running and pubsub.subscribed:
pubsub.get_message(ignore_subscribe_messages=True)
mod_time.sleep(sleep_time)
def stop(self):
''' stops the main loop '''
self._running = False
self.join()
thread = WorkerThread()
thread.start()
return thread
示例3: __init__
# 需要導入模塊: from redis import _compat [as 別名]
# 或者: from redis._compat import iteritems [as 別名]
def __init__(self, sentinels, min_other_sentinels=0, sentinel_kwargs=None,
**connection_kwargs):
# if sentinel_kwargs isn't defined, use the socket_* options from
# connection_kwargs
if sentinel_kwargs is None:
sentinel_kwargs = dict([(k, v)
for k, v in iteritems(connection_kwargs)
if k.startswith('socket_')
])
self.sentinel_kwargs = sentinel_kwargs
self.sentinels = [StrictRedis(hostname, port, **self.sentinel_kwargs)
for hostname, port in sentinels]
self.min_other_sentinels = min_other_sentinels
self.connection_kwargs = connection_kwargs