kredis 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kredis might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/kredis.rb +7 -3
- data/lib/kredis/connections.rb +8 -1
- data/lib/kredis/migration.rb +1 -0
- data/lib/kredis/railtie.rb +20 -24
- data/lib/kredis/types.rb +5 -0
- data/lib/kredis/types/counter.rb +5 -1
- data/lib/kredis/types/cycle.rb +13 -0
- data/lib/kredis/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd8ef47e0ef8b83252c6dc0878bf81b6963a6fe959c1f81d776087a255798421
|
4
|
+
data.tar.gz: 04af1db077a8ba58769bb0614830c2fd1395a3a777df1d304c6e63f48753a5bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cae5b52d7156a5aae222962e9f328bcd954a09aae7d24ff272319ace142cec3ac78c18b7b6bf3a46403c00fbbf0561f9f60a554384195fd7208d88518f261ddf
|
7
|
+
data.tar.gz: 7b5e80312aa4daa05837697080e8ada67d9b1f59fda1f6902c9f9539caa745a703636f04d3576cb9dc86c7bbf23b8f74d0ba58b0beae7bd4aeb4e95abad180c6
|
data/README.md
CHANGED
@@ -64,6 +64,15 @@ counter.increment by: 2 # => SETEX "mycounter" 900 0 + INCR "mycounter"
|
|
64
64
|
sleep 6.seconds
|
65
65
|
0 == counter.value # => GET "mycounter"
|
66
66
|
|
67
|
+
cycle = Kredis.cycle "mycycle", values: %i[ one two three ]
|
68
|
+
:one == cycle.value
|
69
|
+
cycle.next
|
70
|
+
:two == cycle.value
|
71
|
+
cycle.next
|
72
|
+
:three == cycle.value
|
73
|
+
cycle.next
|
74
|
+
:one == cycle.value
|
75
|
+
|
67
76
|
enum = Kredis.enum "myenum", values: %w[ one two three ], default: "one"
|
68
77
|
"one" == enum.value
|
69
78
|
true == enum.one?
|
data/lib/kredis.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
require "
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext/module/attribute_accessors"
|
3
|
+
|
2
4
|
require "kredis/version"
|
3
5
|
|
4
6
|
require "kredis/connections"
|
5
7
|
require "kredis/namespace"
|
8
|
+
require "kredis/type_casting"
|
6
9
|
require "kredis/types"
|
7
10
|
require "kredis/attributes"
|
8
|
-
|
11
|
+
|
12
|
+
require "kredis/railtie" if defined?(Rails::Railtie)
|
9
13
|
|
10
14
|
module Kredis
|
11
|
-
include Connections, Namespace,
|
15
|
+
include Connections, Namespace, TypeCasting, Types
|
12
16
|
|
13
17
|
extend self
|
14
18
|
|
data/lib/kredis/connections.rb
CHANGED
@@ -13,6 +13,13 @@ module Kredis::Connections
|
|
13
13
|
|
14
14
|
def clear_all
|
15
15
|
logger&.info "[Kredis] Connections all cleared"
|
16
|
-
connections.each_value
|
16
|
+
connections.each_value do |connection|
|
17
|
+
if Kredis.namespace
|
18
|
+
keys = connection.keys("#{Kredis.namespace}:*")
|
19
|
+
connection.del keys if keys.any?
|
20
|
+
else
|
21
|
+
connection.flushdb
|
22
|
+
end
|
23
|
+
end
|
17
24
|
end
|
18
25
|
end
|
data/lib/kredis/migration.rb
CHANGED
@@ -5,6 +5,7 @@ class Kredis::Migration
|
|
5
5
|
|
6
6
|
def initialize(config = :shared)
|
7
7
|
@redis = Kredis.configured_for config
|
8
|
+
# TODO: Replace script loading with `copy` command once Redis 6.2+ is the minimum supported version.
|
8
9
|
@copy_sha = @redis.script "load", "redis.call('SETNX', KEYS[2], redis.call('GET', KEYS[1])); return 1;"
|
9
10
|
end
|
10
11
|
|
data/lib/kredis/railtie.rb
CHANGED
@@ -1,33 +1,29 @@
|
|
1
|
-
|
1
|
+
class Kredis::Railtie < ::Rails::Railtie
|
2
|
+
config.kredis = ActiveSupport::OrderedOptions.new
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
initializer "kredis.testing" do
|
8
|
-
ActiveSupport.on_load(:active_support_test_case) do
|
9
|
-
parallelize_setup { |worker| Kredis.namespace = "test-#{worker}" }
|
10
|
-
teardown { Kredis.clear_all }
|
11
|
-
end
|
4
|
+
initializer "kredis.testing" do
|
5
|
+
ActiveSupport.on_load(:active_support_test_case) do
|
6
|
+
parallelize_setup { |worker| Kredis.namespace = "test-#{worker}" }
|
7
|
+
teardown { Kredis.clear_all }
|
12
8
|
end
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
initializer "kredis.logger" do
|
12
|
+
Kredis.logger = config.kredis.logger || Rails.logger
|
13
|
+
end
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
initializer "kredis.configurator" do
|
16
|
+
Kredis.configurator = Rails.application
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
initializer "kredis.attributes" do
|
20
|
+
# No load hook for Active Model, just defer until after initialization.
|
21
|
+
config.after_initialize do
|
22
|
+
ActiveModel::Model.include Kredis::Attributes if defined?(ActiveModel::Model)
|
23
|
+
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
25
|
+
ActiveSupport.on_load(:active_record) do
|
26
|
+
include Kredis::Attributes
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
data/lib/kredis/types.rb
CHANGED
@@ -41,6 +41,10 @@ module Kredis::Types
|
|
41
41
|
Counter.new configured_for(config), namespaced_key(key), expires_in: expires_in
|
42
42
|
end
|
43
43
|
|
44
|
+
def cycle(key, values:, expires_in: nil, config: :shared)
|
45
|
+
Cycle.new configured_for(config), namespaced_key(key), values: values, expires_in: expires_in
|
46
|
+
end
|
47
|
+
|
44
48
|
def flag(key, config: :shared)
|
45
49
|
Flag.new configured_for(config), namespaced_key(key)
|
46
50
|
end
|
@@ -75,6 +79,7 @@ require "kredis/types/proxying"
|
|
75
79
|
|
76
80
|
require "kredis/types/scalar"
|
77
81
|
require "kredis/types/counter"
|
82
|
+
require "kredis/types/cycle"
|
78
83
|
require "kredis/types/flag"
|
79
84
|
require "kredis/types/enum"
|
80
85
|
require "kredis/types/list"
|
data/lib/kredis/types/counter.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Kredis::Types::Counter < Kredis::Types::Proxying
|
2
|
-
proxying :multi, :set, :incrby, :decrby, :get
|
2
|
+
proxying :multi, :set, :incrby, :decrby, :get, :del
|
3
3
|
|
4
4
|
attr_accessor :expires_in
|
5
5
|
|
@@ -20,4 +20,8 @@ class Kredis::Types::Counter < Kredis::Types::Proxying
|
|
20
20
|
def value
|
21
21
|
get.to_i
|
22
22
|
end
|
23
|
+
|
24
|
+
def reset
|
25
|
+
del
|
26
|
+
end
|
23
27
|
end
|
data/lib/kredis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Timm Hansen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-02-
|
12
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/kredis/type_casting.rb
|
57
57
|
- lib/kredis/types.rb
|
58
58
|
- lib/kredis/types/counter.rb
|
59
|
+
- lib/kredis/types/cycle.rb
|
59
60
|
- lib/kredis/types/enum.rb
|
60
61
|
- lib/kredis/types/flag.rb
|
61
62
|
- lib/kredis/types/list.rb
|
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
- !ruby/object:Gem::Version
|
87
88
|
version: '0'
|
88
89
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
+
rubygems_version: 3.2.5
|
90
91
|
signing_key:
|
91
92
|
specification_version: 4
|
92
93
|
summary: Higher-level data structures built on Redis.
|