Module: SolidRedis::RESP
- Defined in:
- lib/solid_redis/resp.rb
Defined Under Namespace
Classes: Reader
Constant Summary collapse
- CRLF =
"\r\n"
Class Method Summary collapse
Class Method Details
.encode(command) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/solid_redis/resp.rb', line 9 def encode(command) command = command.flatten(1) raise ArgumentError, "Redis command cannot be empty" if command.empty? command.each_with_object(+"*#{command.length}#{CRLF}") do |argument, buffer| value = encode_argument(argument) buffer << "$#{value.bytesize}#{CRLF}#{value}#{CRLF}" end end |
.encode_argument(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/solid_redis/resp.rb', line 19 def encode_argument(value) case value when String then value when Symbol, Integer, Float then value.to_s when true then "1" when false then "0" when nil then "" else value.to_s end end |