# \[Redis\] MessageBus 和 Redis 是如何协同工作的

**URL:** <https://meta.discourse.org/t/redis-how-are-messagebus-and-redis-working/90229>\
**Category:** Development\
**Created:** [2018年六月19日 16:37 UTC](https://meta.discourse.org/t/redis-how-are-messagebus-and-redis-working/90229 "2018-06-19T16:37:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjay1](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sanjay1](https://meta.discourse.org/u/Sanjay1)\
**Post date:** [2018年六月19日 16:37 UTC](https://meta.discourse.org/t/redis-how-are-messagebus-and-redis-working/90229/1 "2018-06-19T16:37:05Z")

</div>

Hi All,

I kind of started investigating how, Redis is used with Discourse and this lead me to MessageBus gem,

And looking into the gem as well as the code, I can see is used to interface with Redis its self via another Gem called Redis,

Can someone please explain how all this interact, and why there is a need for MessageBus, instead just use Redis ruby Gem ?

Thanks

---

<div class="post-metadata">

**Author:** ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)\
**Post date:** [2018年六月19日 18:00 UTC](https://meta.discourse.org/t/redis-how-are-messagebus-and-redis-working/90229/2 "2018-06-19T18:00:16Z")

</div>

MessageBus and Redis serve very different purposes.

Redis is an in-memory database, used to store state on the server that is more or less volatile. Some examples are scheduled jobs, session data, rate limiting data, …

MessageBus is a system that is used to push messages to the client. For example, if you’re on Discourse while someone replies here, you’ll see a blue number appear an your avatar immediately – that piece of information was sent from the server to your browser through MessageBus.

---

<div class="post-metadata">

**Author:** ![Sanjay1](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sanjay1](https://meta.discourse.org/u/Sanjay1)\
**Post date:** [2018年六月19日 18:12 UTC](https://meta.discourse.org/t/redis-how-are-messagebus-and-redis-working/90229/3 "2018-06-19T18:12:42Z")

</div>

@fefrei Thanks for replying.

And I kind of get the purpose of Redis, but I also know that it has a supports for pub/sub architecture. And I was under the impression that MessageBus, was using Redis gem to publish messages on Redis,

And also following your answer, how does MessageBus keeps track of the state if , in your example the blue bar appearing if someone is replying to my message.

Thanks

---

<div class="post-metadata">

**Author:** ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)\
**Post date:** [2018年六月19日 18:13 UTC](https://meta.discourse.org/t/redis-how-are-messagebus-and-redis-working/90229/4 "2018-06-19T18:13:49Z")

</div>

For questions about MessageBus internals, @sam likely is the right person to ask 🙂
