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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3e3619ec3a977b472348572202b324c813d550d43cc866ec1aab7dad8e463f0
4
- data.tar.gz: 920c49f0cfe443a71dd5dc8f112070ab8061bbe2d352c98b45026ceeed871f2e
3
+ metadata.gz: bd8ef47e0ef8b83252c6dc0878bf81b6963a6fe959c1f81d776087a255798421
4
+ data.tar.gz: 04af1db077a8ba58769bb0614830c2fd1395a3a777df1d304c6e63f48753a5bb
5
5
  SHA512:
6
- metadata.gz: 8f97bda6b251a100411c0338d2760aa1c2565f3ee1901f5f4971123cbe8b7a49fabf64ccc210775e9694263fd1a2a142641bcf81659776f746d05163640afda5
7
- data.tar.gz: 546b9246e3952a92452fe55cf574233b12d50f29bdeb345c7efe3ebf86bd3ab9a6ff4d22731438ae3258586caca530c1e7229ffee9b581a4a22b04f585dd4467
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 "kredis/railtie"
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
- require "kredis/type_casting"
11
+
12
+ require "kredis/railtie" if defined?(Rails::Railtie)
9
13
 
10
14
  module Kredis
11
- include Connections, Namespace, Types, TypeCasting
15
+ include Connections, Namespace, TypeCasting, Types
12
16
 
13
17
  extend self
14
18
 
@@ -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(&:flushdb)
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
@@ -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
 
@@ -1,33 +1,29 @@
1
- require "rails/railtie"
1
+ class Kredis::Railtie < ::Rails::Railtie
2
+ config.kredis = ActiveSupport::OrderedOptions.new
2
3
 
3
- module Kredis
4
- class Railtie < ::Rails::Railtie
5
- config.kredis = ActiveSupport::OrderedOptions.new
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
- initializer "kredis.logger" do
15
- Kredis.logger = config.kredis.logger || Rails.logger
16
- end
11
+ initializer "kredis.logger" do
12
+ Kredis.logger = config.kredis.logger || Rails.logger
13
+ end
17
14
 
18
- initializer "kredis.configurator" do
19
- Kredis.configurator = Rails.application
20
- end
15
+ initializer "kredis.configurator" do
16
+ Kredis.configurator = Rails.application
17
+ end
21
18
 
22
- initializer "kredis.attributes" do
23
- # No load hook for Active Model, just defer until after initialization.
24
- config.after_initialize do
25
- ActiveModel::Model.include Kredis::Attributes if defined?(ActiveModel::Model)
26
- end
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
- ActiveSupport.on_load(:active_record) do
29
- include Kredis::Attributes
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"
@@ -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
@@ -0,0 +1,13 @@
1
+ class Kredis::Types::Cycle < Kredis::Types::Counter
2
+ attr_accessor :values
3
+
4
+ alias index value
5
+
6
+ def value
7
+ values[index]
8
+ end
9
+
10
+ def next
11
+ set (index + 1) % values.size
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Kredis
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
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.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-05 00:00:00.000000000 Z
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.1.2
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.