本文整理汇总了Python中redis.client.StrictRedis类的典型用法代码示例。如果您正苦于以下问题:Python StrictRedis类的具体用法?Python StrictRedis怎么用?Python StrictRedis使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StrictRedis类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rfunc
def rfunc(info):
#
info.setdefault('host', '127.0.0.1')
info.setdefault('port', 6379)
#
conn_kwargs = dict(
host=info['host'],
port=int(info['port']),
)
#
print('# Connect')
print(pformat(conn_kwargs, indent=4, width=1))
#
conn = None
try:
#
conn = StrictRedis(**conn_kwargs)
#
res = '\n'.join('{:<30}: {}'.format(k, v) for k, v in conn.info().items())
#
print('# Result')
print(res)
finally:
#
conn = None
示例2: Record
class Record(object):
def __init__(self,host='127.0.0.1',port=6379):
self.r=StrictRedis()
def run(self):
while True:
value=self.r.rpop('alerts')
if value:
obj=json.loads(value)
keyredis=obj['src_ip']+'_'+str(obj['src_port'])+'_'+ obj['dest_ip']+'_'+str(obj['dest_port'])
entry=self.r.get(keyredis)
if entry:
restruct=json.loads(entry)
else:
restruct={}
if not 'http' in restruct:
restruct['http']=[]
if not 'alerts' in restruct:
restruct['alerts']=[]
if not 'files' in restruct:
restruct['files']=[]
if 'alert' in obj:
restruct['alerts'].append(obj['alert']['signature'])
if 'fileinfo' in obj:
restruct['files'].append(obj['fileinfo'])
if 'http' in obj:
restruct['http'].append(obj['http'])
if len(restruct)>0:
self.r.set(keyredis, json.dumps(restruct))
else:
sleep(1)
示例3: redis
class redis(object):
def __init__(self,host='127.0.0.1',port=6379):
self.r = StrictRedis(host,port)
def rec(self,k,v):
self.r.set(k, v)
def rpush(self,v):
self.r.rpush('alerts',v)
示例4: main
def main():
r = StrictRedis(host='localhost', port=6379, db=0)
ps = r.pubsub()
ps.subscribe("logs")
data = ps.listen()
print(data)
示例5: rewrite_redis_aof_job
def rewrite_redis_aof_job():
current_veil_env = get_current_veil_env()
if not hasattr(current_veil_env.config, 'redis_servers'):
return
for host, port in current_veil_env.config.redis_servers:
client = StrictRedis(host=host, port=port)
if client.config_get('appendonly')['appendonly'] != 'yes':
continue
client.bgrewriteaof()
示例6: __init_rd
def __init_rd(self, master=False):
if self.rd is None:
if master:
self.rd = StrictRedis(host=_redis_servers[0][0], port=_redis_servers[0][1], db=_redis_servers[0][2])
self._master_rd = True
else:
server = random.choice(_redis_servers)
self.rd = StrictRedis(host=server[0], port=server[1], db=server[2])
self._master_rd = False
elif master and not self._master_rd:
self.rd = StrictRedis(host=_redis_servers[0][0], port=_redis_servers[0][1], db=_redis_servers[0][2])
self._master_rd = True
示例7: __init__
def __init__(self):
# Load the GeoIP databases into class attributes since they each need 20+ MB in memory
if not self.__class__._geoip4:
self.__class__._geoip4 = GeoIP(Config.GEOIP_PATH_V4, MEMORY_CACHE)
if not self.__class__._geoip6:
self.__class__._geoip6 = GeoIP(Config.GEOIP_PATH_V6, MEMORY_CACHE)
self.redis = StrictRedis(Config.REDIS['HOST'], Config.REDIS['PORT'], Config.REDIS['DB'])
示例8: redis
def redis(app=None):
app = app_or_default(app)
if not hasattr(app, "redbeat_redis") or app.redbeat_redis is None:
app.redbeat_redis = StrictRedis.from_url(app.conf.REDBEAT_REDIS_URL, decode_responses=True)
return app.redbeat_redis
示例9: flushdb
def flushdb(self):
"""Destroy every shard's db
"""
for pool in self.pool_map.values():
con = StrictRedis.from_url(pool.url, connection_pool=pool)
self.log.debug("flushing shard member: %s", con)
con.flushdb()
del con
示例10: __init__
def __init__(self, dispatcher, db_host, db_port, db_num, db_pw):
self.dispatcher = dispatcher
pool = ConnectionPool(max_connections=2, db=db_num, host=db_host, port=db_port, password=db_pw)
self.redis = StrictRedis(connection_pool=pool)
self.encoder = JSONEncoder()
self.decoder = JSONDecoder()
self.class_map = {}
self.object_map = {}
示例11: __init__
def __init__(self,config):
if self._validateConfig(config):
self._r = StrictRedis(host=config[REDIS_DATASOURCE_CONFIG][REDIS_DATASOURCE_CONFIG_HOST],
port=config[REDIS_DATASOURCE_CONFIG][REDIS_DATASOURCE_CONFIG_PORT],
db=config[REDIS_DATASOURCE_CONFIG][REDIS_DATASOURCE_CONFIG_DB])
logger.debug("Obtained internal redis handler" + str(self._r))
else:
raise BaseException("Error validating config ")
示例12: __init__
def __init__(self, config, section):
from redis.client import StrictRedis
self.conn = StrictRedis(
config.get(section, 'redis-server'),
config.getint(section, 'redis-port'),
config.getint(section, 'redis-db'),
decode_responses=True
)
示例13: __init__
def __init__(self, redis_connection=None, locker=None, *args, **kwargs):
self.__redis_connection = redis_connection
if self.__redis_connection is None:
self.__redis_connection = StrictRedis.from_url(current_app.conf.CELERY_REDIS_SCHEDULER_URL)
self._schedule = EntryProxy(self.__redis_connection)
self._locker = locker
if self._locker is None:
self._locker = Redlock([current_app.conf.CELERY_REDIS_SCHEDULER_URL])
super(ChardScheduler, self).__init__(*args, **kwargs)
示例14: details
def details(topic, pages):
client = StrictRedis()
with client.pipeline(transaction=False) as pipeline:
pipeline.hgetall(topic)
pipeline.zcard('{}/pages'.format(topic))
pipeline.zrange('{}/pages'.format(topic), pages * -1, -1, withscores=True)
results = pipeline.execute()
def header(label):
return '\n'.join(('-' * 80, label, '-' * 80))
print header('CONFIGURATION')
print tabulate.tabulate(results[0].items(), headers=('key', 'value'))
print ''
print header('PAGES ({} total)'.format(results[1]))
print tabulate.tabulate(results[2], headers=('page', 'offset'))
示例15: RedisDataSource
class RedisDataSource(AbstractDataSource):
_r = None
def __init__(self,config):
if self._validateConfig(config):
self._r = StrictRedis(host=config[REDIS_DATASOURCE_CONFIG][REDIS_DATASOURCE_CONFIG_HOST],
port=config[REDIS_DATASOURCE_CONFIG][REDIS_DATASOURCE_CONFIG_PORT],
db=config[REDIS_DATASOURCE_CONFIG][REDIS_DATASOURCE_CONFIG_DB])
logger.debug("Obtained internal redis handler" + str(self._r))
else:
raise BaseException("Error validating config ")
def update(self,item):
self.store(item)
def store(self,item):
self._r.set(item.getHash(), item.getValue())
def get(self,item):
return self._r.get(item.getHash())
def exists(self,item):
return self.get(item) is not None
def all(self):
result = []
# Obtain all keys
keys = self._r.keys()
#For each key, get value
for k in keys:
value = self._r.get(k)
result.append(BaseItem({"origin":"redis"},value))
#return result
return result
def _validateConfig(self,config):
validator = MultipleConfigValidator(
{VALIDATORS_LIST:[ContainsKeyConfigValidator({KEY_VALUE:REDIS_DATASOURCE_CONFIG})]})
if not validator.validate(config):
raise BaseException("Config validation error : does not contain " + REDIS_DATASOURCE_CONFIG)
# Validate redis datasource config
validator = MultipleConfigValidator(
{VALIDATORS_LIST:[ContainsKeysConfigValidator({KEYS_LIST:[REDIS_DATASOURCE_CONFIG_DB,
REDIS_DATASOURCE_CONFIG_HOST,
REDIS_DATASOURCE_CONFIG_PORT]})]})
if not validator.validate(config[REDIS_DATASOURCE_CONFIG]):
raise BaseException("Config validation error : config not complete ")
return True
def delete(self,item):
self._r.delete(item.getHash())