redis_batch 0.0.2 → 0.0.3

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: ead79130daaa5dd59b528e53f0069b2d7520f2b40001e611ea0e1ce97baadc33
4
- data.tar.gz: c63abeed3e5f550ea5ce84356ac4183e9042fec24e12d87c72a6210240846d57
3
+ metadata.gz: 21c8d0fc6fa834d58afff202ad63597688d3ec0943cba4f06d82e0033201b820
4
+ data.tar.gz: fe2a7c88467d02c85e205d726b53c6aff4f191d0c08aa7d88831c0414bdbcd6a
5
5
  SHA512:
6
- metadata.gz: 9db50906c0891b09654a35d151096df5ebdd89b8fa6b854645d6eba5223840876f16fed94f3299bb12497f59dc92933169b4b67a73fb2609b82df810ab9d195e
7
- data.tar.gz: 34ad2d47797b5e5fe7d73da4a300072e8a028ecb6f8a9fb971c42d7b67d5a0ee0cab5bf8e39ed763bc330bd0ec719a5a944e4d6d2df54525e69feeed284c19fb
6
+ metadata.gz: db65fe573cc1e50e53e870f620944dedb9d941309019ba06e068b2b49d8c9c6ff7b04b3352f560afeb2d487626fddd27cc26455c678685a021d29ee68d99198a
7
+ data.tar.gz: 1bbcf4b38252e74cd8e59ff705ee21c79ad9833f80933ca6b05f366da44a99225c0198e368bc691ee9022f85a56df2c847a61f5845a3a2a52cc60ca04a602f33
@@ -0,0 +1,42 @@
1
+ module RedisBatch
2
+ class Lua
3
+ def self.function_load(redis)
4
+ redis.call("FUNCTION", "LOAD", "REPLACE", redis_batch_lua)
5
+ end
6
+
7
+ def self.redis_batch_lua
8
+ <<~LUA
9
+ #!lua name=redis_batch
10
+
11
+ local function lmove(keys, args)
12
+ local count = tonumber(args[1])
13
+ local source = keys[1]
14
+ local target = keys[2]
15
+ local llen = redis.call("LLEN", source)
16
+ if llen < count then
17
+ count = llen
18
+ end
19
+ local values = {}
20
+ for i=1,count do
21
+ values[i] = redis.call("LMOVE", source, target, 'LEFT', 'RIGHT')
22
+ end
23
+ return values
24
+ end
25
+
26
+ redis.register_function('rb_lmove', lmove)
27
+
28
+ local function lrestore(keys, args)
29
+ local source = keys[1]
30
+ local target = keys[2]
31
+ local llen = redis.call("LLEN", source)
32
+ for i=1,llen do
33
+ redis.call("LMOVE", source, target, 'RIGHT', 'LEFT')
34
+ end
35
+ return llen
36
+ end
37
+
38
+ redis.register_function('rb_lrestore', lrestore)
39
+ LUA
40
+ end
41
+ end
42
+ end
@@ -3,7 +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
+ @client.with { |redis| RedisBatch::Lua.function_load(redis) }
7
7
  end
8
8
 
9
9
  def add(*items)
data/lib/redis_batch.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'redis'
2
- require './lib/redis_batch/configurable'
3
- require './lib/redis_batch/client'
4
- require './lib/redis_batch/functions'
5
- require './lib/redis_batch/queue'
2
+ require 'redis_batch/configurable'
3
+ require 'redis_batch/lua'
4
+ require 'redis_batch/client'
5
+ require 'redis_batch/queue'
6
6
 
7
7
  module RedisBatch
8
8
  Error = Class.new(StandardError)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Avemark
@@ -34,6 +34,7 @@ files:
34
34
  - lib/redis_batch.rb
35
35
  - lib/redis_batch/client.rb
36
36
  - lib/redis_batch/configurable.rb
37
+ - lib/redis_batch/lua.rb
37
38
  - lib/redis_batch/queue.rb
38
39
  homepage: https://github.com/avemark/redis_batch_rb
39
40
  licenses: