-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed changes regarding generics and symmetry with dictionaries #8
Comments
We initially designed the RedisCache around the In short, for the methods you're proposing, you'd still fetch the entire hashset from Redis, but then discard parts of the output internally, but we'd drop half of it. I'm kinda leaning against that, because it associates the RedisCache quite closely to the workings of a dictionary, which is a promise we can't keep. |
This is included in the new release, which also makes the increment/decrement operations atomic from a Redis point of view. |
Is this a new release of Redis that you're referring to, and is it already in a state that we can migrate to it? How do you feel about the generics? |
Increment and decrement now return the new value in version 0.3.0. It's been released to PyPI Thursday, so you should be able to migrate to that version. Could you explain your idea about generics for the type? The types supported by the framework are specific: By supporting generics on the various Redis types, we may give the impression that we support storing generic types. We don't, we only support the four specific types listed in the alias and we use the aliases to indicate which specific types we expect for the various arguments (and return types). Now, my experience with generics is limited to the "oh, nice, we can do this in Python now", would the implementation of these generics come on top of the existing implementation just so people can type hint a specific redis cache (e.g., say "this RedisCache maps |
Yes, it would give people the option of specifying which of all redis-compatible types a specific RedisCache is intended to deal with.
Based on my understanding of the specification of I can't speak to how often people find the presence of generics misleading about what behavior is legal, though in theory anyone who understands how they work would be able to recognize that only certain types would be valid for |
I have a few changes in mind, but I wanted to verify that these are changes we'd want before I potentially clutter the commit history with them.
Generics
These two type aliases are currently defined as follows:
If we redefine them using
TypeVar
then we can have generics forRedisCache
andRedisQueue
, but that might count as a backwards-incompatible change depending on what the spec is intended to guarantee about those aliases.Other dict methods
Currently
items
is the only view method implemented, and I believekeys
andvalues
is feasible, though I'm not sure if that affords us any functionality overfor key, _ in await cache.items()
.increment
anddecrement
returning the new valueThis is the change I'm least sure of since it would actually make the API slightly less symmetric with regular dicts, but it might be a nice quality of life feature for
increment
anddecrement
to return the new value after performing the increment/decrement operation so that you don't need back-to-back calls toget
andset
if you need to know what the result is.If we decide we want that, I suppose this is in a grey area for backwards compatibility since someone might depend on those methods returning
None
for some reason.The text was updated successfully, but these errors were encountered: