Redis::Helper
Redisを扱うクラスで利用するモジュール
Redis::Objectsがmulti使えないとかアレっていう @i2bskn さん等の想いのカケラ。
Installation
Add this line to your application's Gemfile:
gem "redis-helper"
And then execute:
$ bundle
Or install it yourself as:
$ gem install redis-helper
Usage
class Foo < ActiveRecord::Base
include Redis::Helper
define_attr_keys :bar_count
def
# bar_count_key == attr_key(:bar_count) == "Foo:<id>:bar_count"
redis.get().to_i
end
def (count)
# ttl_to(self.end_at) => self.end_at - Time.current
redis.setex(, ttl_to(self.end_at), count)
end
end
foo = Foo.find(id)
foo.(10)
foo. => 10
Contributing
- Fork it ( https://github.com/Narazaka/redis-helper/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