Class: RDB::Dumpers::AOF
Constant Summary
collapse
- REDIS_AOF_REWRITE_ITEMS_PER_CMD =
64
Instance Method Summary
collapse
-
#buffer_full?(state) ⇒ Boolean
-
#buffer_some?(state) ⇒ Boolean
-
#end_hash(key, state) ⇒ Object
-
#end_list(key, state) ⇒ Object
-
#end_set(key, state) ⇒ Object
-
#end_sortedset(key, state) ⇒ Object
-
#flush(command, state) ⇒ Object
-
#handle(command, state, key, *arguments) ⇒ Object
-
#hset(key, field, value, state) ⇒ Object
-
#pexpireat(key, expiration, state) ⇒ Object
-
#reset_buffer(state) ⇒ Object
-
#rpush(key, member, state) ⇒ Object
-
#sadd(key, member, state) ⇒ Object
-
#serialize_command(command, arguments) ⇒ Object
-
#set(key, value, state) ⇒ Object
-
#start_database(database) ⇒ Object
-
#start_hash(key, length, state) ⇒ Object
-
#start_list(key, length, state) ⇒ Object
-
#start_set(key, length, state) ⇒ Object
-
#start_sortedset(key, length, state) ⇒ Object
-
#variadic? ⇒ Boolean
-
#zadd(key, score, member, state) ⇒ Object
#<<, #dump, #initialize, #with_streams
#accept_key?, #end_database, #end_rdb, #skip_object, #start_rdb
Instance Method Details
#buffer_full?(state) ⇒ Boolean
#buffer_some?(state) ⇒ Boolean
103
104
105
|
# File 'lib/rdb/dumpers/aof.rb', line 103
def buffer_some?(state)
state.info[:buffer].length > 0
end
|
#end_hash(key, state) ⇒ Object
70
71
72
|
# File 'lib/rdb/dumpers/aof.rb', line 70
def end_hash(key, state)
flush(:hmset, state)
end
|
#end_list(key, state) ⇒ Object
34
35
36
|
# File 'lib/rdb/dumpers/aof.rb', line 34
def end_list(key, state)
flush(:rpush, state)
end
|
#end_set(key, state) ⇒ Object
46
47
48
|
# File 'lib/rdb/dumpers/aof.rb', line 46
def end_set(key, state)
flush(:sadd, state)
end
|
#end_sortedset(key, state) ⇒ Object
58
59
60
|
# File 'lib/rdb/dumpers/aof.rb', line 58
def end_sortedset(key, state)
flush(:zadd, state)
end
|
#flush(command, state) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/rdb/dumpers/aof.rb', line 83
def flush(command, state)
if buffer_some?(state)
self << serialize_command(command, [state.key] + state.info[:buffer].flatten)
reset_buffer(state)
end
end
|
#handle(command, state, key, *arguments) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/rdb/dumpers/aof.rb', line 74
def handle(command, state, key, *arguments)
if variadic?
state.info[:buffer].push(arguments)
flush(command, state) if buffer_full?(state)
else
self << serialize_command(command, [key, *arguments])
end
end
|
#hset(key, field, value, state) ⇒ Object
66
67
68
|
# File 'lib/rdb/dumpers/aof.rb', line 66
def hset(key, field, value, state)
handle(variadic? ? :hmset : :hset, state, key, field, value)
end
|
#pexpireat(key, expiration, state) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/rdb/dumpers/aof.rb', line 12
def pexpireat(key, expiration, state)
command = if state.info[:precision] == :second
expiration = (expiration / 1000).to_i
:pexpire
else
:pexpireat
end
self << serialize_command(command, [key, expiration])
end
|
#reset_buffer(state) ⇒ Object
99
100
101
|
# File 'lib/rdb/dumpers/aof.rb', line 99
def reset_buffer(state)
state.info[:buffer] = [];
end
|
#rpush(key, member, state) ⇒ Object
30
31
32
|
# File 'lib/rdb/dumpers/aof.rb', line 30
def rpush(key, member, state)
handle(:rpush, state, key, member)
end
|
#sadd(key, member, state) ⇒ Object
42
43
44
|
# File 'lib/rdb/dumpers/aof.rb', line 42
def sadd(key, member, state)
handle(:sadd, state, key, member)
end
|
#serialize_command(command, arguments) ⇒ Object
90
91
92
93
|
# File 'lib/rdb/dumpers/aof.rb', line 90
def serialize_command(command, arguments)
buffer = "*#{arguments.length + 1}\r\n$#{command.length}\r\n#{command.upcase}\r\n"
buffer << arguments.map { |arg| "$#{arg.to_s.length}\r\n#{arg}\r\n" }.join
end
|
#set(key, value, state) ⇒ Object
22
23
24
|
# File 'lib/rdb/dumpers/aof.rb', line 22
def set(key, value, state)
self << serialize_command(:set, [key, value])
end
|
#start_database(database) ⇒ Object
8
9
10
|
# File 'lib/rdb/dumpers/aof.rb', line 8
def start_database(database)
self << serialize_command(:select, [database])
end
|
#start_hash(key, length, state) ⇒ Object
62
63
64
|
# File 'lib/rdb/dumpers/aof.rb', line 62
def start_hash(key, length, state)
reset_buffer(state)
end
|
#start_list(key, length, state) ⇒ Object
26
27
28
|
# File 'lib/rdb/dumpers/aof.rb', line 26
def start_list(key, length, state)
reset_buffer(state)
end
|
#start_set(key, length, state) ⇒ Object
38
39
40
|
# File 'lib/rdb/dumpers/aof.rb', line 38
def start_set(key, length, state)
reset_buffer(state)
end
|
#start_sortedset(key, length, state) ⇒ Object
50
51
52
|
# File 'lib/rdb/dumpers/aof.rb', line 50
def start_sortedset(key, length, state)
reset_buffer(state)
end
|
#variadic? ⇒ Boolean
95
96
97
|
# File 'lib/rdb/dumpers/aof.rb', line 95
def variadic?
@options[:variadic] ||= false
end
|
#zadd(key, score, member, state) ⇒ Object
54
55
56
|
# File 'lib/rdb/dumpers/aof.rb', line 54
def zadd(key, score, member, state)
handle(:zadd, state, key, score, member)
end
|