Redis FAQ

1. Redis do asynchronous queue

一般使用list结构作为队列,rpush生产消息,lpop消费消息。当lpop没有消息的时候,要适当sleep一会再重试。
127.0.0.1:7003> rpush key 1
(integer) 1
127.0.0.1:7003> rpush key 2
(integer) 2
127.0.0.1:7003> rpush key 3
(integer) 3
127.0.0.1:7003> lrange key 0 -1
1) "1"
2) "2"
3) "3"
127.0.0.1:7003> lpop key
"1"
127.0.0.1:7003> lrange key 0 -1
1) "2"
2) "3"

Disadvantages:

In the case where the consumer goes offline, the produced messages will be lost, so professional message queues such as rabbitmq, etc. have to be used.

2. Redis produces once and consumes many times

使用pub/sub主题订阅者模式,可以实现1:N的消息队列。

3. Redis real-time message push

redis开启key失效推送,将需要推送的userid和推送信息作为key存入redis,从现在到推送时间作为可以、
有效期。开个客户端监听key失效信息,推送对应key。

java code implementation

Published 200 original articles · praised 13 · 40,000+ views

Guess you like

Origin blog.csdn.net/u013919153/article/details/105617342