kredis 0.2.1 → 0.2.2

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: 8f1ad5de0aa1b64c083109609ec185ea81e35b3550fced4347f5bff12ff35832
4
- data.tar.gz: 85d287eb15524b0b668524a51820ffb3a64d4bccda398f07802abb5867b49b92
3
+ metadata.gz: f3e3619ec3a977b472348572202b324c813d550d43cc866ec1aab7dad8e463f0
4
+ data.tar.gz: 920c49f0cfe443a71dd5dc8f112070ab8061bbe2d352c98b45026ceeed871f2e
5
5
  SHA512:
6
- metadata.gz: cfb7cfa924d9a6ecb79febf81cc2b2479694b0e275219d53e031b01fe2296a23862eee96f6359d05f33fc333808638b39c187c9f641252de3435488df3f6e372
7
- data.tar.gz: cd06423690991d2a5364804e240aac27b88f792bc951623ce1e5f4f5a17946b817a05cfda9a4defb831e8e6c1d79ee0c3ab8523342d94c3a2259caca8609f1d9
6
+ metadata.gz: 8f97bda6b251a100411c0338d2760aa1c2565f3ee1901f5f4971123cbe8b7a49fabf64ccc210775e9694263fd1a2a142641bcf81659776f746d05163640afda5
7
+ data.tar.gz: 546b9246e3952a92452fe55cf574233b12d50f29bdeb345c7efe3ebf86bd3ab9a6ff4d22731438ae3258586caca530c1e7229ffee9b581a4a22b04f585dd4467
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Kredis (Keyed Redis) encapsulates higher-level types and data structures around a single key, so you can interact with them as coherent objects rather than isolated procedural commands. These higher-level structures can be configured as attributes within Active Models and Active Records using a declarative DSL.
4
4
 
5
- Kredis is configured using env-aware yaml files, using `Rails.application.config_for`, so you can locate the data structures on separate redis instances, if you've reached a scale where a single shared instance is no longer sufficient.
5
+ Kredis is configured using env-aware YAML files, using `Rails.application.config_for`, so you can locate the data structures on separate Redis instances, if you've reached a scale where a single shared instance is no longer sufficient.
6
6
 
7
7
  Kredis provides namespacing support for keys such that you can safely run parallel testing against the data structures without different tests trampling each others data.
8
8
 
@@ -154,7 +154,7 @@ test:
154
154
  <<: *development
155
155
  ```
156
156
 
157
- Additional configurations can be added under `config/redis/*.yml` and referenced when a type is created.
157
+ Additional configurations can be added under `config/redis/*.yml` and referenced when a type is created, e.g. `Kredis.string("mystring", config: :strings)` would lookup `config/redis/strings.yml`. Under the hood `Kredis.configured_for` is called which'll pass the configuration on to `Redis.new`.
158
158
 
159
159
 
160
160
  ## License
@@ -41,7 +41,7 @@ class Kredis::Migration
41
41
  cursor = "0"
42
42
  begin
43
43
  cursor, keys = @redis.scan(cursor, match: key_pattern, count: SCAN_BATCH_SIZE)
44
- @redis.multi { yield keys }
44
+ @redis.pipelined { yield keys }
45
45
  end until cursor == "0"
46
46
  end
47
47
 
@@ -6,8 +6,8 @@ module Kredis
6
6
 
7
7
  initializer "kredis.testing" do
8
8
  ActiveSupport.on_load(:active_support_test_case) do
9
- parallelize_setup { |worker| Kredis.namespace = "test-#{worker}" }
10
- parallelize_teardown { Kredis.clear_all }
9
+ parallelize_setup { |worker| Kredis.namespace = "test-#{worker}" }
10
+ teardown { Kredis.clear_all }
11
11
  end
12
12
  end
13
13
 
@@ -16,7 +16,7 @@ module Kredis::TypeCasting
16
16
  when TrueClass, FalseClass
17
17
  value ? "t" : "f"
18
18
  when Time, DateTime, ActiveSupport::TimeWithZone
19
- value.to_f
19
+ value.iso8601(9)
20
20
  when Hash
21
21
  JSON.dump(value)
22
22
  else
@@ -33,7 +33,7 @@ module Kredis::TypeCasting
33
33
  when :decimal then value.to_d
34
34
  when :float then value.to_f
35
35
  when :boolean then value == "t" ? true : false
36
- when :datetime then Time.at(value.to_i)
36
+ when :datetime then Time.iso8601(value)
37
37
  when :json then JSON.load(value)
38
38
  end if value.present?
39
39
  end
@@ -1,6 +1,7 @@
1
- require "active_support/core_ext/enumerable"
2
-
3
1
  class Kredis::Types::Proxy
2
+ require_relative "proxy/failsafe"
3
+ include Failsafe
4
+
4
5
  attr_accessor :redis, :key
5
6
 
6
7
  def initialize(redis, key, **options)
@@ -13,14 +14,16 @@ class Kredis::Types::Proxy
13
14
  end
14
15
 
15
16
  def method_missing(method, *args, **kwargs)
16
- Kredis.logger&.debug log_message(method, *args, **kwargs)
17
- redis.public_send method, key, *args, **kwargs
17
+ failsafe do
18
+ Kredis.logger&.debug log_message(method, *args, **kwargs)
19
+ redis.public_send method, key, *args, **kwargs
20
+ end
18
21
  end
19
22
 
20
23
  private
21
24
  def log_message(method, *args, **kwargs)
22
- args = args.flatten.compact_blank.presence
23
- kwargs = kwargs.compact_blank.presence
25
+ args = args.flatten.reject(&:blank?).presence
26
+ kwargs = kwargs.reject { |_k, v| v.blank? }.presence
24
27
  type_name = self.class.name.split("::").last
25
28
 
26
29
  "[Kredis #{type_name}] #{method.upcase} #{key} #{args&.inspect} #{kwargs&.inspect}".chomp
@@ -0,0 +1,26 @@
1
+ module Kredis::Types::Proxy::Failsafe
2
+ def initialize(*)
3
+ super
4
+ @fail_safe_suppressed = false
5
+ end
6
+
7
+ def failsafe
8
+ yield
9
+ rescue Redis::BaseError
10
+ raise if fail_safe_suppressed?
11
+ end
12
+
13
+ def suppress_failsafe_with(returning: nil)
14
+ old_fail_safe_suppressed, @fail_safe_suppressed = @fail_safe_suppressed, true
15
+ yield
16
+ rescue Redis::BaseError
17
+ returning
18
+ ensure
19
+ @fail_safe_suppressed = old_fail_safe_suppressed
20
+ end
21
+
22
+ private
23
+ def fail_safe_suppressed?
24
+ @fail_safe_suppressed
25
+ end
26
+ end
@@ -13,6 +13,10 @@ class Kredis::Types::Proxying
13
13
  options.each { |key, value| send("#{key}=", value) }
14
14
  end
15
15
 
16
+ def failsafe(returning: nil, &block)
17
+ proxy.suppress_failsafe_with(returning: returning, &block)
18
+ end
19
+
16
20
  private
17
21
  delegate :type_to_string, :string_to_type, :types_to_strings, :strings_to_types, to: :Kredis
18
22
  end
@@ -29,7 +29,7 @@ class Kredis::Types::Set < Kredis::Types::Proxying
29
29
  end
30
30
 
31
31
  def size
32
- scard
32
+ scard.to_i
33
33
  end
34
34
 
35
35
  def take
@@ -6,23 +6,25 @@ class Kredis::Types::Slots < Kredis::Types::Proxying
6
6
  attr_accessor :available
7
7
 
8
8
  def reserve
9
- if block_given?
10
- begin
11
- if reserve
12
- yield
9
+ failsafe returning: false do
10
+ if block_given?
11
+ begin
12
+ if reserve
13
+ yield
14
+ true
15
+ else
16
+ false
17
+ end
18
+ ensure
19
+ release
20
+ end
21
+ else
22
+ if incr <= available
13
23
  true
14
24
  else
25
+ release
15
26
  false
16
27
  end
17
- ensure
18
- release
19
- end
20
- else
21
- if incr <= available
22
- true
23
- else
24
- release
25
- false
26
28
  end
27
29
  end
28
30
  end
@@ -32,7 +34,9 @@ class Kredis::Types::Slots < Kredis::Types::Proxying
32
34
  end
33
35
 
34
36
  def available?
35
- get.to_i < available
37
+ failsafe returning: false do
38
+ get.to_i < available
39
+ end
36
40
  end
37
41
 
38
42
  def reset
@@ -1,3 +1,3 @@
1
1
  module Kredis
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kredis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Timm Hansen
8
8
  - David Heinemeier Hansson
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-03 00:00:00.000000000 Z
12
+ date: 2021-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -39,7 +39,7 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '4.2'
42
- description:
42
+ description:
43
43
  email: david@hey.com
44
44
  executables: []
45
45
  extensions: []
@@ -60,6 +60,7 @@ files:
60
60
  - lib/kredis/types/flag.rb
61
61
  - lib/kredis/types/list.rb
62
62
  - lib/kredis/types/proxy.rb
63
+ - lib/kredis/types/proxy/failsafe.rb
63
64
  - lib/kredis/types/proxying.rb
64
65
  - lib/kredis/types/scalar.rb
65
66
  - lib/kredis/types/set.rb
@@ -70,7 +71,7 @@ homepage: https://github.com/rails/kredis
70
71
  licenses:
71
72
  - MIT
72
73
  metadata: {}
73
- post_install_message:
74
+ post_install_message:
74
75
  rdoc_options: []
75
76
  require_paths:
76
77
  - lib
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  version: '0'
87
88
  requirements: []
88
89
  rubygems_version: 3.1.2
89
- signing_key:
90
+ signing_key:
90
91
  specification_version: 4
91
92
  summary: Higher-level data structures built on Redis.
92
93
  test_files: []