mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
29 lines
479 B
Ruby
29 lines
479 B
Ruby
require "redis"
|
|
|
|
class Redis
|
|
class Pipeline < Redis
|
|
BUFFER_SIZE = 50_000
|
|
|
|
def initialize(redis)
|
|
@redis = redis
|
|
@commands = []
|
|
end
|
|
|
|
def execute_command(data)
|
|
@commands << data
|
|
write_and_read if @commands.size >= BUFFER_SIZE
|
|
end
|
|
|
|
def finish
|
|
write_and_read
|
|
end
|
|
|
|
def write_and_read
|
|
@redis.execute_command(@commands.join, true)
|
|
@redis.read_socket
|
|
@commands.clear
|
|
end
|
|
|
|
end
|
|
end
|