Avoid exceptions accessing nonexistent etags in RedisGrainStorage #9147
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a Redis-only solution for the issue which was reported to affect both ADO.NET and Redis. #3516 (comment)
The workaround so far was to avoid clearing nonexistent state, but that put the burden on the user of the persistence layer. In case of a third-party library using the persistence layer, this would require patching it.
Cause
The Redis built-in LUA engine has a peculiarity that it properly returns "nil" for nonexistent results when accessed e.g. through the
EVAL "script"
command, but within the script it translate these "nil" to "false", which makes "==nil" checks behave in a non-intuitive manner.redis/redis#2721
Solution
As recommended by @ReubenBond, the C# code that builds up the argument list and calls the LUA script was left untouched. The empty string as a proxy for a null was kept. Next to that, the LUA nil behaviour was taken into account to check something for its absence: (not something or something='') instead of "==nil" which doesn't work as expected intuitively.
Next to this solution, some equivalent fix for ADO.NET will be required to address further #3516
Microsoft Reviewers: Open in CodeFlow