redis_batch 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d205bf5fdc9bfb375f6666e1017413f9bb2ecbdb8d696912cb9b658f3910ffed
4
- data.tar.gz: 8b7521a379d318634fa2a6c8e5cf42398af416414b2fec89e1a0f9bd40e18087
3
+ metadata.gz: ead79130daaa5dd59b528e53f0069b2d7520f2b40001e611ea0e1ce97baadc33
4
+ data.tar.gz: c63abeed3e5f550ea5ce84356ac4183e9042fec24e12d87c72a6210240846d57
5
5
  SHA512:
6
- metadata.gz: 357499ea517316f46c7b80dc43d14269656141f345afb8db1cc56a8dab790bcf6fbef8b95121b7480dbdd6fb6162c572182830550ba9637c191d13a99e5ec82d
7
- data.tar.gz: 685246ee83f7a97946efebf7193477cd6aee5c75ace9b92e5f5bb75cf134a4d36968e11519bd3458b8da4b65c622701193e3b622c25615fd19bfb17c747646a4
6
+ metadata.gz: 9db50906c0891b09654a35d151096df5ebdd89b8fa6b854645d6eba5223840876f16fed94f3299bb12497f59dc92933169b4b67a73fb2609b82df810ab9d195e
7
+ data.tar.gz: 34ad2d47797b5e5fe7d73da4a300072e8a028ecb6f8a9fb971c42d7b67d5a0ee0cab5bf8e39ed763bc330bd0ec719a5a944e4d6d2df54525e69feeed284c19fb
@@ -3,6 +3,7 @@ module RedisBatch
3
3
  def initialize(namespace = self.class.name)
4
4
  @namespace = namespace
5
5
  @client = Client.instance
6
+ @client.with { |redis| Functions.function_load(redis) }
6
7
  end
7
8
 
8
9
  def add(*items)
@@ -19,9 +20,8 @@ module RedisBatch
19
20
 
20
21
  def abort_all
21
22
  return unless processing?
22
- keys = @client.with { |redis| redis.keys("#{@namespace}_takeout_*") }
23
- client.with do |redis|
24
- keys.each do |key|
23
+ @client.with do |redis|
24
+ redis.keys("#{@namespace}_takeout_*").each do |key|
25
25
  abort_processing(key, redis)
26
26
  end
27
27
  end
@@ -29,9 +29,7 @@ module RedisBatch
29
29
 
30
30
  def take(count: 1, client: @client)
31
31
  values = client.with do |redis|
32
- redis.multi do |transaction|
33
- count.times.map { transaction.lmove(queue_key, take_key, :left, :right) }
34
- end
32
+ redis.call("FCALL", "rb_lmove", 2, queue_key, take_key, count)
35
33
  end
36
34
  yield values
37
35
  client.with { |redis| redis.del(take_key) }
@@ -43,10 +41,7 @@ module RedisBatch
43
41
  private
44
42
 
45
43
  def abort_processing(key, redis)
46
- recover_count = redis.llen(key)
47
- redis.multi do |transaction|
48
- recover_count.times { transaction.lmove(take_key, queue_key, :right, :left) }
49
- end
44
+ redis.call("FCALL", "rb_lrestore", 2, key, queue_key)
50
45
  end
51
46
 
52
47
  def queue_key
data/lib/redis_batch.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'redis'
2
2
  require './lib/redis_batch/configurable'
3
3
  require './lib/redis_batch/client'
4
+ require './lib/redis_batch/functions'
4
5
  require './lib/redis_batch/queue'
5
6
 
6
7
  module RedisBatch
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Avemark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-03 00:00:00.000000000 Z
11
+ date: 2024-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis