You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use an ordered set for registering heartbeats of devices connected to our backend via websockets. Discovering that Kredis stores scores as float timestamps, I realized I could use ZRANGE to retrieve device IDs that have either recent or stale heartbeat:
heartbeats=Kredis.ordered_set("devices:heartbeats")heartbeats.zrange("-inf",1.minute.ago.to_f,byscore: true)# returns device IDs with stale heartbeatheartbeats.zrange(1.minute.ago.to_f,"+inf",byscore: true)# returns device IDs with recent heartbeat
I recently created a helper method that accepts a time range to make this easier:
heartbeat_ids(...1.minute.ago)# stale heartbeatsheartbeat_ids(1.minute.ago..)# recent heartbeats
I was wondering whether there is interest in adding a similar method to Kredis::OrderedSet, or make #elements accept an optional time range.
The text was updated successfully, but these errors were encountered:
janko
changed the title
Retrieving elements from ordered set that have updated in given time interval
Retrieving elements from ordered set that were updated in given time interval
Aug 29, 2024
We use an ordered set for registering heartbeats of devices connected to our backend via websockets. Discovering that Kredis stores scores as float timestamps, I realized I could use
ZRANGE
to retrieve device IDs that have either recent or stale heartbeat:I recently created a helper method that accepts a time range to make this easier:
I was wondering whether there is interest in adding a similar method to
Kredis::OrderedSet
, or make#elements
accept an optional time range.The text was updated successfully, but these errors were encountered: