redis_batch 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/redis_batch/lua.rb +42 -0
- data/lib/redis_batch/queue.rb +1 -1
- data/lib/redis_batch.rb +4 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21c8d0fc6fa834d58afff202ad63597688d3ec0943cba4f06d82e0033201b820
|
4
|
+
data.tar.gz: fe2a7c88467d02c85e205d726b53c6aff4f191d0c08aa7d88831c0414bdbcd6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/redis_batch/queue.rb
CHANGED
data/lib/redis_batch.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'redis'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
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.
|
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:
|