Project

punchline

0.0
No commit activity in last 3 years
No release in over 3 years
Persistent redis based min-priority queue.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
>= 0
~> 3.1.0
~> 0.7.1

Runtime

>= 3.0.0
 Project Readme

Build Status Dependency Status Coverage Status Code Climate Gem Version

Punchline

Punchline is a Redis backed Minimum Priority Queue with enforced uniqueness and atomicity fuelled by lua scripts.

Motivation

At Doceo, we needed a way to atomically keep track of dirty records that needed reprocessing, whilst also avoiding doing extra work if records are marked as dirty and haven't been processed yet.

Prerequisites

  • Redis 2.6+

Currently tested against Ruby 2.0.0, 2.1.0 and JRuby

Installation

Add this line to your application's Gemfile:

gem 'punchline', '~> 0.1.0'

Or live on the bleeding edge

gem 'punchline', github: 'catkins/punchline'

And then execute:

$ bundle install

Usage

require 'punchline'

# optionally override Punchline with your own Redis client, eg. Redis::Namespace
redis_url = ENV["REDIS_URL"] || "redis://localhost:6379"
client = Redis.new url: redis_url
namespaced_client = Redis::Namespace.new Rails.env, client

Punchline.configure do |config|
  config.redis = namespaced_client
end

# create a queue
queue = Punchline::MinQueue.new :awesome_key
queue.length # => 0

# add a key - priority defaults to current timestamp (Time.now.to_i)
queue.enqueue 'hello!' # => true

queue.length # => 1

# shortly after... higher priority score is rejected
queue.enqueue 'hello!' # => false

queue.length # => 1

# original key is retrieved
queue.dequeue # => { :priority => 1411405014, :value => "hello!" }

# queue is now empty
queue.length # => 0

# optionally set your own priority value
queue.enqueue 'hello!', priority: 155 # => true

# fetch all without dequeuing
queue.enqueue 'hello!'
queue.enqueue 'adding values!'
queue.all # [{:value=>"hello!", :priority=>155}, {:value=>"adding values!", :priority=>1411446073}]

# clear out queue
queue.clear!
queue.all # => []
queue.length # => 0

Contributing

  1. Fork it ( http://github.com/catkins/punchline/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 new Pull Request