kredis 1.2.0 → 1.3.0

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: ef7140930b42a8d19b49568c233c1b0c9b1e799f5d8d6948e96442a2bc74e7c1
4
- data.tar.gz: 205fc23eb761dba14f10ffd52506ad748b0a19c2799d75a059841d17fbe9080e
3
+ metadata.gz: 3e96a50da4e56bf4088baa6bb6cb7583820ca235a52139b4aa9144b9f9d8585b
4
+ data.tar.gz: f975deffae4581e3a5d8c208ac2c1bed13686b7d4c1c367289b3f8e5f803b235
5
5
  SHA512:
6
- metadata.gz: e95afce53e43f5ee10f527f41854a058ccd98c34d0d52394d99addcd0e774409c5aa1bf26d06e291fc12a3f5e7e50fffdffc686ed26e2926fe36709a08da90be
7
- data.tar.gz: c03d6654a1cdb7680bad60efd2287b82f4ac720362d3c65935629beeeb466c54ff08341e5016173dca19ac1bb67cf48de52c296ddfd3a17fbb6d230090c6b38a
6
+ metadata.gz: ffc338f0f5f0d975c85d5b207c0ace88bd96d7f5047bd0bcd5ad7b600b1e0165df30d6c8af3ef6f51f89b97ea0bf696a2a440b337921076f5676d5562323761e
7
+ data.tar.gz: de2eb9f5e51df31f9765b2dc5dec59105dc61019818aacacaecc6f1df9a0e99547c5d684baae17f14eeaee1acb64c12a9fb0de919741bffde71e3b55746218f4
@@ -30,9 +30,15 @@ class Kredis::Migration
30
30
  end
31
31
  end
32
32
 
33
- def delete_all(key_pattern)
34
- each_key_batch_matching(key_pattern) do |keys, pipeline|
35
- pipeline.del *keys
33
+ def delete_all(*key_patterns)
34
+ log_migration "DELETE ALL #{key_patterns.inspect}" do
35
+ if key_patterns.length > 1
36
+ @redis.del *key_patterns
37
+ else
38
+ each_key_batch_matching(key_patterns.first) do |keys, pipeline|
39
+ pipeline.del *keys
40
+ end
41
+ end
36
42
  end
37
43
  end
38
44
 
@@ -4,16 +4,16 @@ class Kredis::Types::Counter < Kredis::Types::Proxying
4
4
  attr_accessor :expires_in
5
5
 
6
6
  def increment(by: 1)
7
- multi do |pipeline|
8
- pipeline.set 0, ex: expires_in, nx: true
9
- pipeline.incrby by
7
+ multi do
8
+ set 0, ex: expires_in, nx: true
9
+ incrby by
10
10
  end[-1]
11
11
  end
12
12
 
13
13
  def decrement(by: 1)
14
- multi do |pipeline|
15
- pipeline.set 0, ex: expires_in, nx: true
16
- pipeline.decrby by
14
+ multi do
15
+ set 0, ex: expires_in, nx: true
16
+ decrby by
17
17
  end[-1]
18
18
  end
19
19
 
@@ -1,5 +1,5 @@
1
1
  class Kredis::Types::List < Kredis::Types::Proxying
2
- proxying :lrange, :lrem, :lpush, :rpush, :exists?, :del
2
+ proxying :lrange, :lrem, :lpush, :ltrim, :rpush, :exists?, :del
3
3
 
4
4
  attr_accessor :typed
5
5
 
@@ -8,16 +8,16 @@ class Kredis::Types::List < Kredis::Types::Proxying
8
8
  end
9
9
  alias to_a elements
10
10
 
11
- def remove(*elements, pipeline: nil)
12
- types_to_strings(elements, typed).each { |element| (pipeline || proxy).lrem 0, element }
11
+ def remove(*elements)
12
+ types_to_strings(elements, typed).each { |element| lrem 0, element }
13
13
  end
14
14
 
15
- def prepend(*elements, pipeline: nil)
16
- (pipeline || proxy).lpush types_to_strings(elements, typed) if elements.flatten.any?
15
+ def prepend(*elements)
16
+ lpush types_to_strings(elements, typed) if elements.flatten.any?
17
17
  end
18
18
 
19
- def append(*elements, pipeline: nil)
20
- (pipeline || proxy).rpush types_to_strings(elements, typed) if elements.flatten.any?
19
+ def append(*elements)
20
+ rpush types_to_strings(elements, typed) if elements.flatten.any?
21
21
  end
22
22
  alias << append
23
23
 
@@ -2,19 +2,21 @@ class Kredis::Types::Proxy
2
2
  require_relative "proxy/failsafe"
3
3
  include Failsafe
4
4
 
5
- attr_accessor :redis, :key
5
+ attr_accessor :key
6
+
7
+ thread_mattr_accessor :pipeline
6
8
 
7
9
  def initialize(redis, key, **options)
8
10
  @redis, @key = redis, key
9
11
  options.each { |key, value| send("#{key}=", value) }
10
12
  end
11
13
 
12
- def multi(&block)
13
- # NOTE: to be removed when Redis 4 compatibility gets dropped
14
- return redis.multi unless block
15
-
16
- redis.multi do |pipeline|
17
- block.call(Kredis::Types::Proxy.new(pipeline, key))
14
+ def multi(*args, **kwargs, &block)
15
+ redis.multi(*args, **kwargs) do |pipeline|
16
+ self.pipeline = pipeline
17
+ block.call
18
+ ensure
19
+ self.pipeline = nil
18
20
  end
19
21
  end
20
22
 
@@ -27,6 +29,10 @@ class Kredis::Types::Proxy
27
29
  end
28
30
 
29
31
  private
32
+ def redis
33
+ pipeline || @redis
34
+ end
35
+
30
36
  def log_message(method, *args, **kwargs)
31
37
  args = args.flatten.reject(&:blank?).presence
32
38
  kwargs = kwargs.reject { |_k, v| v.blank? }.presence
@@ -1,14 +1,14 @@
1
1
  require "active_support/core_ext/module/delegation"
2
2
 
3
3
  class Kredis::Types::Proxying
4
- attr_accessor :proxy, :redis, :key
4
+ attr_accessor :proxy, :key
5
5
 
6
6
  def self.proxying(*commands)
7
7
  delegate *commands, to: :proxy
8
8
  end
9
9
 
10
10
  def initialize(redis, key, **options)
11
- @redis, @key = redis, key
11
+ @key = key
12
12
  @proxy = Kredis::Types::Proxy.new(redis, key)
13
13
  options.each { |key, value| send("#{key}=", value) }
14
14
  end
@@ -8,19 +8,19 @@ class Kredis::Types::Set < Kredis::Types::Proxying
8
8
  end
9
9
  alias to_a members
10
10
 
11
- def add(*members, pipeline: nil)
12
- (pipeline || proxy).sadd types_to_strings(members, typed) if members.flatten.any?
11
+ def add(*members)
12
+ sadd types_to_strings(members, typed) if members.flatten.any?
13
13
  end
14
14
  alias << add
15
15
 
16
- def remove(*members, pipeline: nil)
17
- (pipeline || proxy).srem types_to_strings(members, typed) if members.flatten.any?
16
+ def remove(*members)
17
+ srem types_to_strings(members, typed) if members.flatten.any?
18
18
  end
19
19
 
20
20
  def replace(*members)
21
- multi do |pipeline|
22
- pipeline.del
23
- add members, pipeline: pipeline
21
+ multi do
22
+ del
23
+ add members
24
24
  end
25
25
  end
26
26
 
@@ -8,10 +8,10 @@ class Kredis::Types::UniqueList < Kredis::Types::List
8
8
  elements = Array(elements).uniq
9
9
  return if elements.empty?
10
10
 
11
- multi do |pipeline|
12
- remove elements, pipeline: pipeline
13
- super(elements, pipeline: pipeline)
14
- pipeline.ltrim 0, (limit - 1) if limit
11
+ multi do
12
+ remove elements
13
+ super
14
+ ltrim 0, (limit - 1) if limit
15
15
  end
16
16
  end
17
17
 
@@ -19,10 +19,10 @@ class Kredis::Types::UniqueList < Kredis::Types::List
19
19
  elements = Array(elements).uniq
20
20
  return if elements.empty?
21
21
 
22
- multi do |pipeline|
23
- remove elements, pipeline: pipeline
24
- super(elements, pipeline: pipeline)
25
- pipeline.ltrim -limit, -1 if limit
22
+ multi do
23
+ remove elements
24
+ super
25
+ ltrim -limit, -1 if limit
26
26
  end
27
27
  end
28
28
  alias << append
@@ -1,3 +1,3 @@
1
1
  module Kredis
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/kredis.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "active_support"
2
2
  require "active_support/core_ext/module/attribute_accessors"
3
+ require "active_support/core_ext/module/attribute_accessors_per_thread"
3
4
 
4
5
  require "kredis/version"
5
6
 
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: 1.2.0
4
+ version: 1.3.0
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: 2022-04-30 00:00:00.000000000 Z
12
+ date: 2022-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -29,16 +29,22 @@ dependencies:
29
29
  name: redis
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '4.2'
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '6'
35
38
  type: :runtime
36
39
  prerelease: false
37
40
  version_requirements: !ruby/object:Gem::Requirement
38
41
  requirements:
39
- - - "~>"
42
+ - - ">="
40
43
  - !ruby/object:Gem::Version
41
44
  version: '4.2'
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '6'
42
48
  - !ruby/object:Gem::Dependency
43
49
  name: rails
44
50
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
115
  - !ruby/object:Gem::Version
110
116
  version: '0'
111
117
  requirements: []
112
- rubygems_version: 3.2.32
118
+ rubygems_version: 3.3.20
113
119
  signing_key:
114
120
  specification_version: 4
115
121
  summary: Higher-level data structures built on Redis.