Redis教程

redis中获取区间数据及获取总条数

本文主要是介绍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)))

 

这篇关于redis中获取区间数据及获取总条数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!