-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Version
redis 7.2.3
/ redis-py 5.0.7
Platform
macOS Sonoma 14.5
Description
Hi everyone,
I noticed an inconsistency between the zrevrange
and zrevrank
functions regarding score casting behavior.
The zrevrange
function has both withscore
and score_cast_func
parameters:
def zrevrange(
self,
name: KeyT,
start: int,
end: int,
withscores: bool = False,
score_cast_func: Union[type, Callable] = float,
) -> ResponseT:
According to the docstring, the score_cast_func
is a callable used to cast the score return value.
However, the zrevrank
function only has a withscore
parameter and casts to float by default, this discrepancy led to the following code in my project:
x = redis_client.zrevrange(
"test",
0,
-1,
withscores=True,
score_cast_func=int,
)
y = redis_client.zrevrank(
"test",
"test",
withscore=True,
)
y = int(y)
Question
Why does the zrevrange
function offer the flexibility of score_cast_func
while zrevrank
does not? Given the similar nature of these functions, shouldn’t they both support the same score casting logic for consistency?
Proposal
For a more consistent API, I suggest adding the score_cast_func
parameter to the zrevrank
function, similar to its implementation in zrevrange
.