redis / hiredis-py

Python wrapper for hiredis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Differentiating between bool False and not-enough-data

tjstum opened this issue · comments

Hi there,

In RESP3, there are now native boolean Redis types. I see that #104, there's support for converting this to Python True/False. However, gets returns False when there's not enough data in the buffer.

Is there any thought to how to differentiate between an actual response with False (#f\r\n) and communicating to the caller that there isn't enough data? The two ideas I've thought of are a sentinel object (like NOT_ENOUGH_DATA = object()) or raising an exception. Both of those are pretty rough on backward compatibility, though.
Using None isn't an option, since Redis already had that as a return type (and now just spells it differently in RESP3)

To keep backwards compatibility maybe Reader could grow an additional keyword argument with default e.g. Reader(..., not_enough_data=False)? I suspect most clients are still using resp2 anyway, so it would not be a huge change for newer clients interested in resp3 to use something like Reader(..., not_enough_data=NOT_ENOUGH_DATA) where NOT_ENOUGH_DATA is some singleton (I'd personally probably use Ellipsis here).