redis队列
连接redis
单连接方式
REDIS_CONN_PARAMS={ "host":'127.0.0.1', "password":'123456', "port":6379, "encoding":'utf-8' } conn=redis.Redis(**REDIS_CONN_PARAMS)
连接池方式
POOL =redis.ConnectionPool( host='127.0.0.1', port=6379,password="123456", encoding='utf8', max_connections=1000) conn=redis.Redis(connection_pool=POOL)
redis查看队列消息命令

登录redis
redis-cli -h 127.0.0.1 -p 6379 -a 123456
查看队列长度 llen 队列名
llen DAY02_TASK_QUEUE
获取部分队列信息 lrange 队列名 起始位置 终止位置(-1表示末尾)
lrange DAY02_TASK_QUEUE 0 -1
获取队列消息的三种方式
第一种:一次性全部获取
conn=redis.Redis(connection_pool=POOL) total_count=conn.llen("DAY02_TASK_QUEUE") res=conn.lrange("DAY02_TASK_QUEUE",start=0,end=total_count)
第二种 一个一个获取
conn=redis.Redis(connection_pool=POOL) total_count=conn.llen("DAY02_TASK_QUEUE") for index in range(total_count): ele=conn.lindex("DAY02_TASK_QUEUE",index) print(ele)
第三种 一次获取部分
conn=redis.Redis(connection_pool=POOL) total_count=conn.llen("DAY02_TASK_QUEUE") has_fetch_count=0 while has_fetch_count < total_count: ele_list=conn.lrange("DAY02_TASK_QUEUE",start=has_fetch_count,end=has_fetch_count+3) has_fetch_count+=len(ele_list) print(ele_list)
启动redis服务

redis-server.exe redis.windows.conf

redis-server --service-stop
redis-server --service-start
详细链接:https://blog.csdn.net/qq_39720249/article/details/101576119
浙公网安备 33010602011771号