Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (30 sloc) 1.68 KB



Add this line to your application's Gemfile:

gem 'sidekiq_custom_serializer', git: 'git://'

And then execute:

$ bundle

Story behind this repo:

This gem is a patch for Sidekiq. It overrides the way Sidekiq saves references to objects in Redis, and the way it retrieves them back.

If you use #delay method on an ActiveRecord instance, the custom serializer will serialize the instance into a string, and know how to deserialize it back when the task runs.

For example:


will save under redis SIDEKIQ@User@1 and SIDEKIQ@User@2 along with the method name. Then, when the task runs, it'll fetch the user objects by ID from the DB.

Instead of creating worker classes for each background job and grow your app code, this gem will easily let you use current methods without changing the parameters they get to use IDs nor storing huge YAML dumps in Redis.

This Gem supplies ActiveRecord, classes and modules serialization and deserialization out of the box. For other things, you can define two methods (below is the implementation for ActiveRecord):

  1. Instance method for serialization:
def sidekiq_serialize
  1. Class method for deserialization:
def self.sidekiq_deserialize(string)
  where(id: string.to_i).first

Every argument in Redis with SIDEKIQ@ prefix will be inspected. The string after the first @ is the class name, and then the ID or any other parameter, that will be passed to the sidekiq_deserialize(string) method.