]>
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 | |
11 | ||
d7fc9edb | 12 | def execute_command(data) |
57172ffb | 13 | @commands << data |
14 | write_and_read if @commands.size >= BUFFER_SIZE | |
15 | end | |
16 | ||
17 | def finish | |
18 | write_and_read | |
19 | end | |
20 | ||
21 | def write_and_read | |
d7fc9edb | 22 | @redis.execute_command(@commands.join, true) |
57172ffb | 23 | @redis.read_socket |
24 | @commands.clear | |
25 | end | |
26 | ||
27 | end | |
d7fc9edb | 28 | end |