Permalink
Browse files

added __contains__

  • Loading branch information...
1 parent 791dc62 commit c1ed1f0b08d5ffa511cf780f777fa59e64e16690 @atl atl committed May 27, 2010
Showing with 7 additions and 1 deletion.
  1. +7 −1 redish/proxy.py
View
@@ -48,7 +48,10 @@ def __init__(self, **kwargs):
The `miss` argument accepts a function of one argument to which
it passes a key, if the key is unknown in the datastore. By default
it returns a "None". Another possibility for more strict checking
- is passing in a KeyError.
+ is passing in a KeyError. If a user attempts to initialize a redis
+ key with an empty container, that container is kept in the (local
+ threading) proxy object so that subsequent accesses keep the
+ right type without throwing KeyErrors.
"""
try:
self.miss = kwargs.pop('miss')
@@ -102,3 +105,6 @@ def __setitem__(self, key, value):
pline = pline.zadd(key, k, v)
pline.execute()
+ def __contains__(self, key):
+ return self.exists(key) or key in self.empties
+

0 comments on commit c1ed1f0

Please sign in to comment.