4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/redis/sender.rb', line 4
def send_redis data
collect = []
if Symbol === data
collect << data
elsif NilClass === data
collect << :'$-1'
elsif FalseClass === data
collect << :':0'
elsif TrueClass === data
collect << :':1'
elsif Float === data and data.nan?
collect << :':0'
elsif Float === data and (data.infinite? || 0) > 0
collect << :':inf'
elsif Float === data and (data.infinite? || 0) < 0
collect << :':-inf'
elsif Hash === data
collect << "*#{data.size * 2}"
data.each do |key, value|
key = key.to_s
value = value.to_s
collect << "$#{key.bytesize}"
collect << key
collect << "$#{value.bytesize}"
collect << value
end
elsif Enumerable === data and !(String === data)
collect << "*#{data.size}"
data.each do |element|
element = element.to_s
collect << "$#{element.bytesize}"
collect << element
end
else
data = data.to_s
collect << "$#{data.bytesize}"
collect << data
end
collect << ''
send_data collect.join "\r\n"
end
|