redis-stream | streaming redis client for node | Stream Processing library
kandi X-RAY | redis-stream Summary
kandi X-RAY | redis-stream Summary
streaming redis client for node
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- reply to redis
redis-stream Key Features
redis-stream Examples and Code Snippets
Community Discussions
Trending Discussions on redis-stream
QUESTION
I have a spring boot web application with the functionality to update an entity called StudioLinking
. This entity describes a temporary, mutable, descriptive logical link between two IoT devices for which my web app is their cloud service. The Links between these devices are ephemeral in nature, but the StudioLinking
Entity persists on the database for reporting purposes. StudioLinking
is stored to the SQL based datastore in the conventional way using Spring Data/ Hibernate. From time to time this StudioLinking entity will be updated with new information from a Rest API. When that link is updated the devices need to respond (change colors, volume, etc). Right now this is handled with polling every 5 seconds but this creates lag from when a human user enters an update into the system and when the IoT devices actually update. It could be as little as a millisecond or up to 5 seconds! Clearly increasing the frequency of the polling is unsustainable and the vast majority of the time there are no updates at all!
So, I am trying to develop another Rest API on this same application with HTTP Long Polling which will return when a given StudioLinking entity is updated or after a timeout. The listeners do not support WebSocket or similar leaving me with Long Polling. Long polling can leave a race condition where you have to account for the possibility that with consecutive messages one message may be "lost" as it comes in between HTTP requests (while the connection is closing and opening, a new "update" might come in and not be "noticed" if I used a Pub/Sub).
It is important to note that this "subscribe to updates" API should only ever return the LATEST and CURRENT version of the StudioLinking
, but should only do so when there is an actual update or if an update happened since the last checkin. The "subscribe to updates" client will initially POST an API request to setup a new listening session and pass that along so the server knows who they are. Because it is possible that multiple devices will need to monitor updates to the same StudioLinking
entity. I believe I can acomplish this by using separately named consumers in the redis XREAD. (keep this in mind for later in the question)
After hours of research I believe the way to acomplish this is using redis streams.
I have found these two links regarding Redis Streams in Spring Data Redis:
https://www.vinsguru.com/redis-reactive-stream-real-time-producing-consuming-streams-with-spring-boot/ https://medium.com/@amitptl.in/redis-stream-in-action-using-java-and-spring-data-redis-a73257f9a281
I also have read this link about long polling, both of these links just have a sleep timer during the long polling which is for demonstration purposes but obviously I want to do something useful.
https://www.baeldung.com/spring-deferred-result
And both these links were very helpful. Right now I have no problem figuring out how to publish the updates to the Redis Stream - (this is untested "pseudo-code" but I don't anticipate having any issues implementing this)
...ANSWER
Answered 2020-Aug-25 at 17:39Why don't you use a blocking polling mechanism? No need to use fancy stuff of spring-data-redis. Just use simple blocking read of 5 seconds, so this call might take around 6 seconds or so. You can decrease or increase the blocking timeout.
QUESTION
I'am trying to implement a java application with redis streams where every consomer consumes exactly one message. Like a pipeline/queue where every consumer takes exactly one message, processes it and after finishing the consumer takes the next message which was not processed so far in the stream. What works is that every message is consumed by exactly one consumer (with xreadgroup).
I started with this tutorial from redislabs
The code:
...ANSWER
Answered 2020-Aug-17 at 09:39Notice that XREADGROUP can get COUNT
argument.
See the JavaDoc how to do it in Lettuce
xreadgroup, by passing XReadArgs.
QUESTION
I needed to simulate two scenarios in which a piece of data would be inserted into the Redis database every 100ms
using redis.xadd("stream_name", {"key": "value"}, maxlen=100, approximate=False)
which is the function of the Redis-Stream
data type. I want to keep the insertion timestamp
of the Redis database the same in both scenarios
Therefore, I also need to set the same start time
, so that at the same start time and the same loop interval
which is 100ms
, the insertion time which is used xadd function of two Redis data should be consistent.
I looked up and found that the Apscheduler
was a good timing task, but its interval was only up to seconds
, not milliseconds
.
I don't know what better way to implement my scenario requirements.
I would appreciate it if you could tell me how to solve it?
...ANSWER
Answered 2020-Jun-28 at 14:46Not really sure if this will satisfy your requirements but the time.sleep()
function can do milliseconds via decimal argument.
QUESTION
I'm trying to use Spring Data Redis to consume a Redis Stream using consumer groups, but keep getting the following exception:
...ANSWER
Answered 2020-Apr-27 at 19:25Answering my own question. It seems as though you do need to explicitly create the stream and group first, even though not mentioned anywhere in the docs. Although there should really be a better way to initialize an empty stream other than publishing a message to it.
QUESTION
Bussiness Objective
I'm creating a dashboard that will depend on some time-series and I'll use Redis to implement it. I'm new to using Redis and I'm trying to use Redis-Streams to count the elements in a stream.
...ANSWER
Answered 2020-Jan-21 at 16:16While the Redis Stream data structure doesn't support this, you can use a Sorted Set alongside it for keeping track of message ranges.
Basically, for each message ID you get from XADD
- e.g. "1579551316273-0" - you need to do a ZADD conversation:9:ids 0 1579551316273-0
. Then, you can use ZLEXCOUNT
to get the "length" of a range.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install redis-stream
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page