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 +4 -4
- data/README.md +4 -3
- data/lib/redis/helper.rb +15 -3
- data/lib/redis/helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9158b2e2f6026d24b0861d6a257f3edb475c1d03
|
4
|
+
data.tar.gz: 2646c37f2ef7d789b4b9714127298d132b78809f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
31
|
-
redis.get(
|
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(
|
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)
|
15
|
-
# redis.get(
|
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(
|
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を生成する
|
data/lib/redis/helper/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|