-
Notifications
You must be signed in to change notification settings - Fork 338
Using Redis
bravemaster619 edited this page Jul 12, 2020
·
5 revisions
Redis support is implemented using Modis, so you can create apps and notifications using an API almost identical to ActiveRecord.
- Add
gem 'rpush-redis'
to your Gemfile. - Set
config.client = :redis
inrpush.rb
.- Set
config.redis_options
if needed.
- Set
- That's it!
You can use the following method instead:
Rpush::Gcm::App.where(name: 'android_app').first
Rpush leaves completed notifications in Redis. If you do not clear them out, Redis will eventually fill up and run out of memory.
We handle this via a daily job that sets the expiration of completed notifications:
redis.keys('rpush:notifications:*').each do |key|
next unless redis.ttl(key) == -1
next unless redis.type(key) == 'hash'
next if redis.hget(key, 'delivered').nil?
redis.expire(key, 24.hours.to_i)
end