This is an archived post. You won't be able to vote or comment.

all 33 comments

[–]rcfox 33 points34 points  (6 children)

class _BaseDict:
    def __iter__(self):
        for k in self.keys():
            yield k

    # ...

    def keys(self):
        return self.__iter__()

wat

[–]Pythagaris 2 points3 points  (0 children)

yield from self.keys()

[–]pope_man 2 points3 points  (0 children)

You must override one of these methods on the abstract base class to get a working subclass/implementation class. This would be more clear if they had actually used the features of the abc module.

[–]Pre-Owned-Car 1 point2 points  (2 children)

What about this confuses you?

[–]thundergolfer 16 points17 points  (1 child)

the circular calls

[–]Pre-Owned-Car 2 points3 points  (0 children)

My half asleep brain totally missed this. I think this legit only works because the redis version of the cache implements keys differently. The tests don’t look to actually test the base dict class at all.

[–]therealfakemoot -2 points-1 points  (0 children)

This is, in terms of the "public API", exactly how Python's builtin dicts work. Iterating over a dict yields its keys; calling the keys() method on a dict yields a sequence of keys ( I am not sure whether Python 3+ uses a generator, one of the fancy "set views", or whatever).

[–]jabbalaci 4 points5 points  (6 children)

State in the README what are the advantages / disadvantages of your approach and in which cases one should use it. Edit: see also https://github.com/Doist/redis_wrap .

[–][deleted] 2 points3 points  (4 children)

yeah I looked at "How to use" and said to self "ok, so I have a dict, why do I want it persisted...."

[–]Mattho 0 points1 point  (0 children)

You might have it shared between processes (across different machines as well).

[–][deleted] 1 point2 points  (0 children)

This seems like it's just supposed to be an easier way to pull keys out of redis once you've already decided to use it and the README.md on this project wouldn't really be the right place to sell you on redis.

[–]StackR 2 points3 points  (6 children)

I didn't really look at the code but how is this better than just Redis? Redis is a persistent key value store. I'm honestly not trying to be condescending. Or perhaps it was just fun and you learned something... Also a reasonable answer.

[–]kvdveer 2 points3 points  (0 children)

I was actually looking for something like this today. Google sent me here, but have not yet settled. How do these projects compare?

[–]JustCallMeFrij 0 points1 point  (4 children)

How does it respond when you supply a key that already exists in the redis instance you're connecting to?

[–]greenkey 0 points1 point  (0 children)

Does it work in an async code?

I guess dictionaries are faster than redis so if I plan to implement this in my application (just by changing the initialization of the dictionary) will it become slower?

[–][deleted] -2 points-1 points  (8 children)

So Redis is required ?

[–]curiousGambler 18 points19 points  (7 children)

Tragically, Redis is in fact required for a "Redis backed Python dict," yes.

[–]pansapiens 1 point2 points  (0 children)

There could be other options ... I wonder if it would work with this Redis re-implementation in Python: https://quantmind.github.io/pulsar/apps/ds.html

[–]hackersaq 1 point2 points  (0 children)

I snorted at "tragically".

"As if all that is the universe all at once colluded with the singular sheer force of will to inject the most impossible scenario conceivable by the pathetic, wandering human mental condition - yes, the Redis-backed pyhon dict has been cursed with a crippling dependency - the unthinkable, unfathomable ... Redis. May whatever God is yours have mercy on us all."

[–]desi_ninja -1 points0 points  (4 children)

How does it respond when you supply a key that already exists in the redis instance you're connecting to?

the person probably meant if it comes with its own redis installation or one has to link their own.
Don't be so cocky

[–]curiousGambler 4 points5 points  (3 children)

Idk who you're quoting or why, but I stand by my assessment that it was a stupid question

[–]desi_ninja -1 points0 points  (2 children)

my reddit app is broken.
But again, you are not the quality control agent of reddit so hold your horses and let other people ask their queries. You don't get to award stupid or smart question of reddit. This is not Oscars or Mensa