]>
Commit | Line | Data |
---|---|---|
57172ffb | 1 | require "redis" |
2 | ||
3 | class Redis | |
4 | class Pipeline < Redis | |
5 | BUFFER_SIZE = 50_000 | |
6 | ||
7 | def initialize(redis) | |
8 | @redis = redis | |
9 | @commands = [] | |
10 | end | |
38210f7f | 11 | |
12 | def execute_command(data) | |
13 | @commands << data | |
14 | write_and_read if @commands.size >= BUFFER_SIZE | |
57172ffb | 15 | end |
38210f7f | 16 | |
17 | def finish | |
18 | write_and_read | |
19 | end | |
20 | ||
21 | def write_and_read | |
22 | @redis.execute_command(@commands.join, true) | |
23 | @redis.read_socket | |
57172ffb | 24 | @commands.clear |
25 | end | |
26 | ||
27 | end | |
d7fc9edb | 28 | end |