nebulex_redis_adapter
nebulex_redis_adapter copied to clipboard
sending binary term data to neblux has surprising result when read
iex(4)> object = %{a: "b"}
%{a: "b"}
iex(5)> object_bin = :erlang.term_to_binary(object)
<<131, 116, 0, 0, 0, 1, 119, 1, 97, 109, 0, 0, 0, 1, 98>>
iex(6)> NebulexRedisBinTerm.Cache.put("object_bin", object_bin)
:ok
iex(7)> NebulexRedisBinTerm.Cache.get("object_bin")
%{a: "b"}
iex(8)>
Notice how I am sending a binary to put but when I call get its coming out as a term. I would expect to get the binary back from nebulex since I converted it before sending the binary.
A theory I had was maybe term_to_binary is a noop when run on binaried terms. but this proved false:
ex(2)> object = %{a: "b"}
%{a: "b"}
iex(3)> object_bin = :erlang.term_to_binary(object)
<<131, 116, 0, 0, 0, 1, 119, 1, 97, 109, 0, 0, 0, 1, 98>>=
iex(5)> object_bin_2 = :erlang.term_to_binary(object_bin)
<<131, 109, 0, 0, 0, 15, 131, 116, 0, 0, 0, 1, 119, 1, 97, 109, 0, 0, 0, 1, 98>>
iex(6)> :erlang.binary_to_term(object_bin_2)
<<131, 116, 0, 0, 0, 1, 119, 1, 97, 109, 0, 0, 0, 1, 98>>
iex(7)>
I made a minimal reproduction here. https://github.com/trashhalo/nebulex_redis_bin_term
Steps to reproduce:
- clone repo
- mix deps.get
- mix test
Expected behavior:
- test passes or sending binary data to nebulex results in returning binary data