Skip to content
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 in rpush.rb.
    • Set config.redis_options if needed.
  • That's it!

Important

find_by_name cannot be used in rpush-redis

You can use the following method instead:

Rpush::Gcm::App.where(name: 'android_app').first

Database Cleanup

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