Repository is archived
No commit activity in last 3 years
No release in over 3 years
Redis pushes a message (notification) to a channel when an active record entry is created or deleted
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
~> 3.2.0

Runtime

>= 3.0.0
 Project Readme

BetterCallRedis

Build Status

Active Record Callback that pushes a notification on a Redis channel when an active record model is created or deleted.

Installation

Add this line to your application's Gemfile:

gem 'better_call_redis'

And then execute:

$ bundle

Or install it yourself as:

$ gem install better_call_redis

Usage

Initializer

All those initialize options are optional. "Redis.new" will be used with default connection options if not specified. "bettercallredis:notification" is the default namespace. "deleted_attributes" for logically deleted active record models (ex: table column deleted or cancelled). Default is an empty array.

BetterCallRedis::configure do |bcr|
  bcr.redis              = Redis.new
  bcr.namespace          = "bettercallredis:notification"
  bcr.deleted_attributes = %w(deleted cancelled)
end

Include in your active record model(s)

Include the following in your active record model class to enable redis channel notification messages.

include BetterCallRedis::ActiveRecord

Redis message

Example for save a new record of class User << ActiveRecord::Base

{:class_name => "User", :message => 1}.to_json

Example for deleting an existing record of class User << ActiveRecord::Base

{:class_name => "User", :message => -1}.to_json

Contributing

  1. Fork it ( https://github.com/[my-github-username]/better_call_redis/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Thanks