redis-helper 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f8a91bd9c3a1637aeb3459abfa889f481fc8a57
4
- data.tar.gz: 5bcb97d1fa9b302f3eb34eb6163ea8db5c63a22d
3
+ metadata.gz: 9158b2e2f6026d24b0861d6a257f3edb475c1d03
4
+ data.tar.gz: 2646c37f2ef7d789b4b9714127298d132b78809f
5
5
  SHA512:
6
- metadata.gz: 420927ee72553a458e32c89da390f9814cd3c46b47da61c84eb8061ec242dde87dad555b0cf1caa0e7b0aa74351372582b28badc7f5095ec7125fdf323b0aa06
7
- data.tar.gz: da61908ece984ba363d22f54309d43f87a5feab499e6b73a9c65704e41f45fc81f6845d79e29186d49aacb50574c6631ea1e15bf7337e46f2243a50981f4dc92
6
+ metadata.gz: b8ba219bd493173ff38f407ac4fff7c41b865dbcf5cf3b5b33eaca06b428da05aa68909ecd605245ca1f8a2e4a98270af9a5c9777c8a5041cf2d5f9ab414e098
7
+ data.tar.gz: 5e8f455b382c4c332c26f64dfa1c7cceafc8b17fdc4d3e5bb26ad4341d2983b06a7e29d90794cd73d610e8a7c2519d42877700766f10aa937ea271e61174ff57
data/README.md CHANGED
@@ -25,15 +25,16 @@ Or install it yourself as:
25
25
  ```ruby
26
26
  class Foo < ActiveRecord::Base
27
27
  include Redis::Helper
28
+ define_attr_keys :bar_count
28
29
 
29
30
  def bar_count
30
- # attr_key(:bar_count) => "Foo:<id>:bar_count"
31
- redis.get(attr_key(:bar_count)).to_i
31
+ # bar_count_key == attr_key(:bar_count) == "Foo:<id>:bar_count"
32
+ redis.get(bar_count_key).to_i
32
33
  end
33
34
 
34
35
  def update_bar_count(count)
35
36
  # ttl_to(self.end_at) => self.end_at - Time.current
36
- redis.setex(attr_key(:bar_count), ttl_to(self.end_at), count)
37
+ redis.setex(bar_count_key, ttl_to(self.end_at), count)
37
38
  end
38
39
  end
39
40
 
data/lib/redis/helper.rb CHANGED
@@ -9,15 +9,16 @@ require "redis/helper/version"
9
9
  # @example
10
10
  # class Foo < ActiveRecord::Base
11
11
  # include Redis::Helper
12
+ # define_attr_keys :bar_count
12
13
  #
13
14
  # def bar_count
14
- # # attr_key(:bar_count) => "Foo:<id>:bar_count"
15
- # redis.get(attr_key(:bar_count)).to_i
15
+ # # bar_count_key == attr_key(:bar_count) == "Foo:<id>:bar_count"
16
+ # redis.get(bar_count_key).to_i
16
17
  # end
17
18
  #
18
19
  # def update_bar_count(count)
19
20
  # # ttl_to(self.end_at) => self.end_at - Time.current
20
- # redis.setex(attr_key(:bar_count), ttl_to(self.end_at), count)
21
+ # redis.setex(bar_count_key, ttl_to(self.end_at), count)
21
22
  # end
22
23
  # end
23
24
  #
@@ -45,6 +46,17 @@ class Redis
45
46
  def redis
46
47
  @redis ||= ::Redis.current
47
48
  end
49
+
50
+ # 固定キーメソッドを作成する
51
+ # @param [Array<String|Symbol>] names キー名
52
+ # @param [String|Symbol] unique_attr インスタンスの固有キーとして使用するメソッド名
53
+ def define_attr_keys(*names, unique_attr: nil)
54
+ names.each do |name|
55
+ define_method(:"#{name}_key") do
56
+ attr_key(name, unique_attr)
57
+ end
58
+ end
59
+ end
48
60
  end
49
61
 
50
62
  # instance固有のkeyとattr_nameからkeyを生成する
@@ -1,6 +1,6 @@
1
1
  class Redis
2
2
  module Helper
3
3
  # バージョン
4
- VERSION = "1.0.0".freeze
4
+ VERSION = "1.1.0".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis