feat: remove stale ONLINE_PRESENCE contact keys in redis (#9558)
50% of Redis memory size comes from ONLINE_PRESENCE keys. This PR adds a periodic job to remove stale keys from all accounts.
This commit is contained in:
10
app/services/internal/remove_stale_redis_keys_service.rb
Normal file
10
app/services/internal/remove_stale_redis_keys_service.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Internal::RemoveStaleRedisKeysService
|
||||
pattr_initialize [:account_id!]
|
||||
|
||||
def perform(account_id)
|
||||
range_start = (Time.zone.now - PRESENCE_DURATION).to_i
|
||||
# exclusive minimum score is specified by prefixing (
|
||||
# we are clearing old records because this could clogg up the sorted set
|
||||
::Redis::Alfred.zremrangebyscore(presence_key(account_id, 'Contact'), '-inf', "(#{range_start}")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user