redis中获取区间数据及获取总条数
import redis REDIS_ITEMS_HOST: str = host REDIS_ITEMS_PASSWORD: str = pwd REDIS_ITEMS_DB: int = 4 #查询DB4 REDIS_ITEMS_PORT: int = 6379 new_r = redis.Redis(host=REDIS_ITEMS_HOST, password=REDIS_ITEMS_PASSWORD, port=REDIS_ITEMS_PORT, db=REDIS_ITEMS_DB) new_key = 'XXX' # redis key old_key = 'XXX' new_r_list = new_r.zrangebyscore(new_key, start, end) new_r_data = [info.decode('utf-8') for info in new_r_list] old_r_list = old_r.zrangebyscore(old_key, start, end) old_r_data = [info.decode('utf-8') for info in old_r_list]
#end = datetime.datetime.now().timestamp() * 1000
#start = int((datetime.datetime.now() - datetime.timedelta(days=3)).timestamp() * 1000)
end = 1650268800000
start = 1650267600000
print("条数:",new_r.zcount(new_key, start, end))
#比较两个redis的差异
print('旧存在,新不存在',set(old_r_data).difference(set(new_r_data)))