diff --git a/lib/redis/connection/command_helper.rb b/lib/redis/connection/command_helper.rb index 04b89113a..f14f90a87 100644 --- a/lib/redis/connection/command_helper.rb +++ b/lib/redis/connection/command_helper.rb @@ -12,11 +12,13 @@ def build_command(args) if i.is_a? Array i.each do |j| j = j.to_s + j = j.encoding == Encoding::BINARY ? j : j.b command << "$#{j.bytesize}" command << j end else i = i.to_s + i = i.encoding == Encoding::BINARY ? i : i.b command << "$#{i.bytesize}" command << i end diff --git a/test/client_test.rb b/test/client_test.rb index 30f7e2cff..7bcbb25cd 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -73,4 +73,13 @@ def resolve end assert_equal 'Error connecting to Redis on 127.0.0.5:999 (Errno::ECONNREFUSED)', error.message end + + def test_mixed_encoding + r.call("MSET", "fée", "\x00\xFF".b, "じ案".encode(Encoding::SHIFT_JIS), "\t".encode(Encoding::ASCII)) + assert_equal "\x00\xFF", r.call("GET", "fée") + assert_equal "\t", r.call("GET", "じ案".encode(Encoding::SHIFT_JIS)) + + r.call("SET", "\x00\xFF", "fée") + assert_equal "fée", r.call("GET", "\x00\xFF".b) + end end