5. redis管道, 发布订阅, 模拟队列

it2022-05-08  10

一. 发布订阅

#订阅scribe 127.0.0.1:6379> SUBSCRIBE "channel_1" Reading messages... (press Ctrl-C to quit) 1) "subscribe" 2) "channel_1" 3) (integer) 1 1) "message" 2) "channel_1" 3) "haha" 1) "message" 2) "channel_1" 3) "hello world" #发布消息publish 127.0.0.1:6379> publish "channel_1" haha (integer) 1 127.0.0.1:6379> publish "channel_1" "hello world" (integer) 1

二. 模拟队列

普通队列 : 对list进行lpush , rpop优先级队列 : brpop list1 list2 list3 timeout // 先从list1取,list1没有数据了再从list2取

三. pipline管道

redis的管道相当于把多条命令批处理, 使原来多条命令需要多次连接服务器转为多条命令连接一次服务器pipline在命令行下没有,jedis有 /** pipline */ public void test3(){ Pipeline pipelined = jedis.pipelined(); for (int i = 0; i < 100; i++) { pipelined.set("str"+i,i+""); } pipelined.sync(); // 提交管道 }

转载于:https://www.cnblogs.com/72808ljup/p/5208519.html


最新回复(0)