Collectr
Abstraction for thread-safe collections (array, hash, set, bag).
Installation
Add this line to your application's Gemfile:
gem 'collectr'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install collectr
Usage
require 'collectr/redis/redis_hash'
x = Collectr::RedisHash.new('example')
x[3] = 7
x[3]
=> 7
x.fetch(3) { 88 }
=> 7
x.fetch(:not_found) { 88 }
=> 88
require 'collectr/redis/redis_hash_expiry'
x = Collectr::RedisHashExpiry.new('example', expires_in: 60)
x['purple'] = :blue
x['purple']
=> "blue"
sleep 61
x['purple']
=> nil
x.write('nine', 9, expires_in: 2)
x['nine']
require 'collectr/memory/memory_hash'
x = Collectr::MemoryHash.new('example')
x[:a] = 'abc'
x[:a]
=> "abc"
require 'collectr/redis/redis_array'
array = Collectr::RedisArray.new('arr', max_size: 3)
array.clear
array << 'a'
array << 'b'
array.to_a
=> ["a", "b"]
Contributing
- Fork it ( https://github.com/[my-github-username]/collectr/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request