fix: WRONGTYPE checks for LLEN/HGETALL and full negative-index support in LRANGE#1
Open
biswajeetdev wants to merge 1 commit into
Open
fix: WRONGTYPE checks for LLEN/HGETALL and full negative-index support in LRANGE#1biswajeetdev wants to merge 1 commit into
biswajeetdev wants to merge 1 commit into
Conversation
…t in LRANGE - LLEN and HGETALL now return WRONGTYPE error when key holds a non-matching type, matching Redis spec and preventing AttributeError crashes on HGETALL - LRANGE now supports full negative-index semantics: LRANGE key 0 -1 returns all elements, LRANGE key -3 -1 returns the last three (previously only stop=-1 was handled, all other negative values silently produced wrong results)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Three Redis spec compliance fixes caught while testing with
redis-cli:Bug 1 —
LRANGEonly handledstop == -1Redis supports full negative-index semantics:
LRANGE key 0 -1returns all elements,LRANGE key -3 -1returns the last three. The previous implementation special-cased onlystop == -1and passed all other negative values straight to Python slice, producing silently wrong results:Fixed with proper translation using
length + indexbefore slicing.Bug 2 —
LLENmissing WRONGTYPE guardCalling
LLENon a key that holds a string or hash would silently returnlen(string)orlen(dict_keys)instead of the standard Redis WRONGTYPE error. Addedisinstance(lst, list)guard.Bug 3 —
HGETALLcould crash with AttributeErrorstore.get(key) or {}falls through to{}for falsy values, but for a non-empty list the stored value is returned as-is. Calling.items()on a list raisesAttributeError, which is not caught by the outerexcept (ValueError, IndexError)— killing the client connection. Added explicitisinstance(h, dict)check.Test