redis-objects-periodical 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +14 -13
- data/CHANGELOG.md +40 -0
- data/Gemfile.lock +2 -2
- data/README.md +41 -0
- data/lib/redis/base_value_object.rb +27 -0
- data/lib/redis/objects/periodical/version.rb +1 -1
- data/lib/redis/objects/periodical_values.rb +44 -0
- data/lib/redis/periodical_value.rb +15 -0
- data/lib/redis-objects-periodical.rb +3 -0
- data/redis-objects-periodical.gemspec +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be8af0088e6ff4a0d8e8e26185acd940452d08f123b1820eef198f636db7b1f7
|
4
|
+
data.tar.gz: 3cd7b2fbb4ea2fd2bd6e53c3d0798ec4bb1e93b89760a4a6fec48b0215fc072e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 284c3aca951719e4efd85195dbd6457061732a1507821b173cf8e61e879e75fc751694b2540b6716b087ec311ad71c3c9e6d59a29f46f25552e0ae5586baf715
|
7
|
+
data.tar.gz: 5fafbcc175c1303535e6e23ee9df14f41a1db5006515416171f15e73f38ee5192e6a0b9adfa6fdfb1ef94c351768bd543c7d9b08e1ce8d1e1de0ac84f621ae1b
|
data/.rubocop_todo.yml
CHANGED
@@ -10,16 +10,17 @@
|
|
10
10
|
# Configuration parameters: AllowedConstants.
|
11
11
|
Style/Documentation:
|
12
12
|
Exclude:
|
13
|
-
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
-
|
18
|
-
-
|
19
|
-
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
13
|
+
- "spec/**/*"
|
14
|
+
- "test/**/*"
|
15
|
+
- "lib/redis-objects-periodical.rb"
|
16
|
+
- "lib/redis/base_counter_object.rb"
|
17
|
+
- "lib/redis/base_hash_key_object.rb"
|
18
|
+
- "lib/redis/base_set_object.rb"
|
19
|
+
- "lib/redis/base_value_object.rb"
|
20
|
+
- "lib/redis/recurring_at_intervals.rb"
|
21
|
+
- "lib/redis/recurring_at_intervals/annual.rb"
|
22
|
+
- "lib/redis/recurring_at_intervals/daily.rb"
|
23
|
+
- "lib/redis/recurring_at_intervals/hourly.rb"
|
24
|
+
- "lib/redis/recurring_at_intervals/minutely.rb"
|
25
|
+
- "lib/redis/recurring_at_intervals/monthly.rb"
|
26
|
+
- "lib/redis/recurring_at_intervals/weekly.rb"
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,45 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## v0.7.0 (Feb 12, 2023)
|
4
|
+
|
5
|
+
### Feature
|
6
|
+
|
7
|
+
- [#128](https://github.com/ryz310/redis-object-daily-counter/pull/128) Support`Redis::Value` as a periodical object ([@ryz310](https://github.com/ryz310))
|
8
|
+
|
9
|
+
> The periodical values automatically switches the save destination when the date changes.
|
10
|
+
>
|
11
|
+
> ```rb
|
12
|
+
> class Homepage
|
13
|
+
> include Redis::Objects
|
14
|
+
>
|
15
|
+
> daily_value :cache, expireat: -> { Time.now + 2_678_400 } # about a month
|
16
|
+
>
|
17
|
+
> def id
|
18
|
+
> 1
|
19
|
+
> end
|
20
|
+
> end
|
21
|
+
>
|
22
|
+
> homepage = Homepage.new
|
23
|
+
>
|
24
|
+
> # 2021-04-01
|
25
|
+
> homepage.cache.value = 'a'
|
26
|
+
>
|
27
|
+
> # 2021-04-02 (next day)
|
28
|
+
> homepage.cache.value = 'b'
|
29
|
+
>
|
30
|
+
> # 2021-04-03 (next day)
|
31
|
+
> homepage.cache.value = 'c'
|
32
|
+
>
|
33
|
+
> homepage.cache[Date.new(2021, 4, 1)] # => 'a'
|
34
|
+
> homepage.cache[Date.new(2021, 4, 1), 3] # => ['a', 'b', 'c']
|
35
|
+
> homepage.cache[Date.new(2021, 4, 1)..Date.new(2021, 4, 2)] # => ['a', 'b']
|
36
|
+
>
|
37
|
+
> homepage.cache.delete_at(Date.new(2021, 4, 1))
|
38
|
+
> homepage.cache.range(Date.new(2021, 4, 1), Date.new(2021, 4, 3)) # => [nil, 'b', 'c']
|
39
|
+
> homepage.cache.at(Date.new(2021, 4, 2)) # => #<Redis::Value key="homepage:1:cache:2021-04-02">
|
40
|
+
> homepage.cache.at(Date.new(2021, 4, 2)).value # 'b'
|
41
|
+
> ```
|
42
|
+
|
3
43
|
## v0.6.0 (Feb 12, 2023)
|
4
44
|
|
5
45
|
### Feature
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -32,6 +32,7 @@ class Homepage
|
|
32
32
|
daily_counter :pv, expireat: -> { Time.now + 2_678_400 } # about a month
|
33
33
|
daily_hash_key :browsing_history, expireat: -> { Time.now + 2_678_400 } # about a month
|
34
34
|
daily_set :dau, expireat: -> { Time.now + 2_678_400 } # about a month
|
35
|
+
daily_value :cache, expireat: -> { Time.now + 2_678_400 } # about a month
|
35
36
|
|
36
37
|
def id
|
37
38
|
1
|
@@ -99,6 +100,46 @@ homepage.pv.at(Date.new(2021, 4, 2)).value # 2
|
|
99
100
|
- `minutely_counter`
|
100
101
|
- Key format: `model_name:id:field_name:yyyy-mm-ddThh:mi`
|
101
102
|
|
103
|
+
### Periodical Values
|
104
|
+
|
105
|
+
The periodical values automatically switches the save destination when the date changes.
|
106
|
+
|
107
|
+
```rb
|
108
|
+
# 2021-04-01
|
109
|
+
homepage.cache.value = 'a'
|
110
|
+
|
111
|
+
# 2021-04-02 (next day)
|
112
|
+
homepage.cache.value = 'b'
|
113
|
+
|
114
|
+
# 2021-04-03 (next day)
|
115
|
+
homepage.cache.value = 'c'
|
116
|
+
|
117
|
+
homepage.cache[Date.new(2021, 4, 1)] # => 'a'
|
118
|
+
homepage.cache[Date.new(2021, 4, 1), 3] # => ['a', 'b', 'c']
|
119
|
+
homepage.cache[Date.new(2021, 4, 1)..Date.new(2021, 4, 2)] # => ['a', 'b']
|
120
|
+
|
121
|
+
homepage.cache.delete_at(Date.new(2021, 4, 1))
|
122
|
+
homepage.cache.range(Date.new(2021, 4, 1), Date.new(2021, 4, 3)) # => [nil, 'b', 'c']
|
123
|
+
homepage.cache.at(Date.new(2021, 4, 2)) # => #<Redis::Value key="homepage:1:cache:2021-04-02">
|
124
|
+
homepage.cache.at(Date.new(2021, 4, 2)).value # 'b'
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Periodical Values Family
|
128
|
+
|
129
|
+
- `annual_value`
|
130
|
+
- Key format: `model_name:id:field_name:yyyy`
|
131
|
+
- Redis is a highly volatile key-value store, so I don't recommend using it.
|
132
|
+
- `monthly_value`
|
133
|
+
- Key format: `model_name:id:field_name:yyyy-mm`
|
134
|
+
- `weekly_value`
|
135
|
+
- Key format: `model_name:id:field_name:yyyyWw`
|
136
|
+
- `daily_value`
|
137
|
+
- Key format: `model_name:id:field_name:yyyy-mm-dd`
|
138
|
+
- `hourly_value`
|
139
|
+
- Key format: `model_name:id:field_name:yyyy-mm-ddThh`
|
140
|
+
- `minutely_value`
|
141
|
+
- Key format: `model_name:id:field_name:yyyy-mm-ddThh:mi`
|
142
|
+
|
102
143
|
### Periodical Hashes
|
103
144
|
|
104
145
|
The periodical hashes also automatically switches the save destination when the date changes.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
module BaseValueObject
|
5
|
+
private
|
6
|
+
|
7
|
+
def get_redis_object(key)
|
8
|
+
Redis::Value.new(key)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_value_from_redis(key)
|
12
|
+
unmarshal(redis.get(key))
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_values_from_redis(keys)
|
16
|
+
redis.mget(*keys).map { |v| unmarshal(v) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete_from_redis(key)
|
20
|
+
redis.del(key)
|
21
|
+
end
|
22
|
+
|
23
|
+
def empty_value
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'redis/periodical_value'
|
4
|
+
|
5
|
+
Redis::PERIODICALS.each do |periodical| # rubocop:disable Metrics/BlockLength
|
6
|
+
new_module = Module.new
|
7
|
+
new_module.module_eval <<~RUBY, __FILE__, __LINE__ + 1
|
8
|
+
def self.included(klass)
|
9
|
+
klass.extend ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def #{periodical}_value(name, options = {})
|
14
|
+
redis_objects[name.to_sym] = options.merge(:type => :value)
|
15
|
+
|
16
|
+
mod = Module.new do
|
17
|
+
define_method(name) do
|
18
|
+
Redis::#{periodical.capitalize}Value.new(
|
19
|
+
redis_field_key(name), redis_field_redis(name), redis_options(name)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
define_method(:"#\{name}=") do |value|
|
23
|
+
public_send(name).value = value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if options[:global]
|
28
|
+
extend mod
|
29
|
+
|
30
|
+
# dispatch to class methods
|
31
|
+
define_method(name) do
|
32
|
+
self.class.public_send(name)
|
33
|
+
end
|
34
|
+
define_method(:"#\{name}=") do |value|
|
35
|
+
self.class.public_send(:"#\{name}=", value)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
include mod
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
RUBY
|
43
|
+
Redis::Objects.const_set("#{periodical.capitalize}Values", new_module)
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "#{File.dirname(__FILE__)}/recurring_at_intervals"
|
4
|
+
require "#{File.dirname(__FILE__)}/base_value_object"
|
5
|
+
|
6
|
+
Redis::PERIODICALS.each do |periodical|
|
7
|
+
require "#{File.dirname(__FILE__)}/recurring_at_intervals/#{periodical}"
|
8
|
+
|
9
|
+
new_class = Class.new(Redis::Value) do
|
10
|
+
include Redis::RecurringAtIntervals
|
11
|
+
include Redis::BaseValueObject
|
12
|
+
include const_get("Redis::RecurringAtIntervals::#{periodical.capitalize}")
|
13
|
+
end
|
14
|
+
Redis.const_set("#{periodical.capitalize}Value", new_class)
|
15
|
+
end
|
@@ -9,6 +9,7 @@ class Redis
|
|
9
9
|
autoload :"#{periodical.capitalize}Counter", 'redis/periodical_counter'
|
10
10
|
autoload :"#{periodical.capitalize}HashKey", 'redis/periodical_hash_key'
|
11
11
|
autoload :"#{periodical.capitalize}Set", 'redis/periodical_set'
|
12
|
+
autoload :"#{periodical.capitalize}Value", 'redis/periodical_value'
|
12
13
|
end
|
13
14
|
|
14
15
|
module Objects
|
@@ -16,6 +17,7 @@ class Redis
|
|
16
17
|
autoload :"#{periodical.capitalize}Counters", 'redis/objects/periodical_counters'
|
17
18
|
autoload :"#{periodical.capitalize}Hashes", 'redis/objects/periodical_hashes'
|
18
19
|
autoload :"#{periodical.capitalize}Sets", 'redis/objects/periodical_sets'
|
20
|
+
autoload :"#{periodical.capitalize}Values", 'redis/objects/periodical_values'
|
19
21
|
end
|
20
22
|
|
21
23
|
class << self
|
@@ -29,6 +31,7 @@ class Redis
|
|
29
31
|
klass.send :include, const_get("Redis::Objects::#{periodical.capitalize}Counters")
|
30
32
|
klass.send :include, const_get("Redis::Objects::#{periodical.capitalize}Hashes")
|
31
33
|
klass.send :include, const_get("Redis::Objects::#{periodical.capitalize}Sets")
|
34
|
+
klass.send :include, const_get("Redis::Objects::#{periodical.capitalize}Values")
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.required_ruby_version = '>= 2.7.0'
|
31
31
|
|
32
|
-
spec.add_dependency 'redis-objects'
|
32
|
+
spec.add_dependency 'redis-objects', '~> 1.0'
|
33
33
|
|
34
34
|
# For more information and examples about making a new gem, checkout our
|
35
35
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-objects-periodical
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryz310
|
@@ -14,16 +14,16 @@ dependencies:
|
|
14
14
|
name: redis-objects
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
description: Extends Redis::Objects to switch automatically the save destination within
|
28
28
|
Redis on changing dates.
|
29
29
|
email:
|
@@ -54,13 +54,16 @@ files:
|
|
54
54
|
- lib/redis/base_counter_object.rb
|
55
55
|
- lib/redis/base_hash_key_object.rb
|
56
56
|
- lib/redis/base_set_object.rb
|
57
|
+
- lib/redis/base_value_object.rb
|
57
58
|
- lib/redis/objects/periodical/version.rb
|
58
59
|
- lib/redis/objects/periodical_counters.rb
|
59
60
|
- lib/redis/objects/periodical_hashes.rb
|
60
61
|
- lib/redis/objects/periodical_sets.rb
|
62
|
+
- lib/redis/objects/periodical_values.rb
|
61
63
|
- lib/redis/periodical_counter.rb
|
62
64
|
- lib/redis/periodical_hash_key.rb
|
63
65
|
- lib/redis/periodical_set.rb
|
66
|
+
- lib/redis/periodical_value.rb
|
64
67
|
- lib/redis/recurring_at_intervals.rb
|
65
68
|
- lib/redis/recurring_at_intervals/annual.rb
|
66
69
|
- lib/redis/recurring_at_intervals/daily.rb
|