Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Redis pubsub, is it possible to pass an object to the PUBLISH command?

Tags:

redis

I have an application which inserts record to a postgresql table and after the insert, I want to send a PUBLISH command to redis. Is it possible to pass an object of that record to redis' PUBLISH command so the subscriber on the other end will receive the object too?

like image 989
Marconi Avatar asked Mar 04 '11 07:03

Marconi


People also ask

What does Redis publish do?

In a Redis Cluster clients can publish to every node. The cluster makes sure that published messages are forwarded as needed, so clients can subscribe to any channel by connecting to any one of the nodes.

How does Redis Pubsub work?

Redis Pub/Sub implements the messaging system where the senders (in redis terminology called publishers) sends the messages while the receivers (subscribers) receive them. The link by which the messages are transferred is called channel. In Redis, a client can subscribe any number of channels.

When a message is published with the Publish command does Redis guarantee the order of messages in a single node?

1 Answer. Show activity on this post. First of all, if you are using PUBLISH, then it is blocking and returns only after messages have been delivered, so yes the order is guaranteed.

Is Redis publish blocking?

To start with, the publish isnt blocking the process. In the pub/sub system, the publisher pushes the message, and the subscriber is an always blocking synchronous process.


2 Answers

Redis has no meaning of "objects", all redis gets are bytes, specifically strings!
So when you want to publish an object you have to serialize it some way and deserialize it on the subscriber.

like image 101
Tobias P. Avatar answered Sep 28 '22 04:09

Tobias P.


Yes, but because redis stores strings rather than objects, you'll need to serialize/unserialize objects as part of the PUBLISH process. JSON is an ideal format for this.

like image 22
sanityinc Avatar answered Sep 28 '22 05:09

sanityinc