Cannot pass boolean from ruby to lua using hiredis.


Recently while looking through a redis db I discovered that it had a lot of empty string values. It turns out that using hiredis, you cannot pass a nil / false value from ruby to lua scripts. Some code was expecting a nil variable in ruby to evaluate to false in the lua script. However the hiredis extension converts everything to strings and therefore the nil value gets converted to an empty string.

See https://github.com/pietern/hiredis-rb/blob/a4c7326e0e485750825bb8845b843dff96420794/ext/hiredis_ext/connection.c#L289

for the internal details.

A have a quick irb session confirms the same:

  1. irb(main):001:0> nil.to_s
    => ""

See http://pastebin.com/DtPrjds5 for a more detailed script.

Gotta be careful with such stuff. 

No comments:

Post a Comment