I've been using the Redis library for the past few months to build an OpenResty application and I've realized that all of the empty responses from the library are wrapped around ngx.null. This make it harder to unit test smaller pieces of code in pure Lua, as standard Lua has no ngx.null value.
It could be mocked when unit testing Lua files, but feels like an ugly workaround. Another issue is that it can't be worked around (by using if not ngx.null) since it's a truthy value which is counter-intuitive.
So why does the lua-resty-redis API return ngx.null instead of using Lua's nil value?
I've been using the Redis library for the past few months to build an OpenResty application and I've realized that all of the empty responses from the library are wrapped around
ngx.null. This make it harder to unit test smaller pieces of code in pure Lua, as standard Lua has nongx.nullvalue.It could be mocked when unit testing Lua files, but feels like an ugly workaround. Another issue is that it can't be worked around (by using
if not ngx.null) since it's a truthy value which is counter-intuitive.So why does the lua-resty-redis API return
ngx.nullinstead of using Lua'snilvalue?