#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Victor"
# Date: 2019/12/18
from rediscluster import StrictRedisCluster
INTERVAL_TIME = 1800
REDIS_NODES = [
{'host': '172.25.xx.70', 'port': '7000'},
{'host': '172.xxx.102.71', 'port': '7000'},
{'host': '172.16.1x9.72', 'port': '7000'},
{'host': '172.16.x79.75', 'port': '7000'},
{'host': '172.16.xx.76', 'port': '7000'},
]
class RedisApi():
@classmethod
def redis_conn(cls, startup_nodes=REDIS_NODES, max_connections=1000):
redisObject = None
try:
redisObject = StrictRedisCluster(startup_nodes=startup_nodes, max_connections=max_connections)
except Exception as e:
print("redis conn error : %s" % e)
return redisObject
if __name__ == '__main__':
"""
/data/anaconda3/bin/python check_redis.py
"""
idfa = "4BD4D979-892C-49D7-AFE4-40AD30F011D8"
redisObj = RedisApi().redis_conn()
new_rdfa = str(idfa)
if len(new_rdfa) > 3:
required_3 = idfa[0:3]
join_str = "IDFA:" + "rr_app_news:" + required_3
# redis的hget和hexists方法
from_timestamp = redisObj.hget(join_str, new_rdfa)
he_timestamp = redisObj.hexists(join_str, new_rdfa)
print("from_timestamp exists: ", from_timestamp)
print("from_timestamp exists: ", he_timestamp)
# 查不到的时候的结果
# from_timestamp exists: None
# from_timestamp exists: False