Permalink
Browse files

item deletion and edge cases when key is None or ''

  • Loading branch information...
1 parent 7236d71 commit 591145b16751f24ca7fdf0d0414ee606bcd195c9 @atl atl committed May 27, 2010
Showing with 16 additions and 6 deletions.
  1. +16 −6 redish/proxy.py
View
@@ -56,30 +56,35 @@ def __getitem__(self, key):
"""Return a proxy type according to the native redis type
associated with the key."""
typ = self.type(key)
+ if typ == 'string':
+ # because strings can be empty, check before "empties"
+ return int_or_str(self.get(key), key, self)
if key in self.empties:
if typ == 'none':
return self.empties[key]
else:
self.empties.pop(key)
if typ == 'none':
raise KeyError(key)
- elif typ == 'string':
- return int_or_str(self.get(key), key, self)
else:
return TYPE_MAP[typ](key, self)
def __setitem__(self, key, value):
"""Copy the contents of the value into the redis store."""
+ if key in self.empties:
+ del self.empties[key]
if isinstance(value, (int, types.Int)):
self.set(key, int(value))
return
elif isinstance(value, basestring):
self.set(key, encode(value, "UTF-8"))
return
- if not value and value != None:
- self.empties[key] = REV_TYPE_MAP[type(value)](key, self)
- elif value and key in self.empties:
- self.empties.pop(key)
+ if not value:
+ if self.exists(key):
+ self.delete(key)
+ if value != None:
+ self.empties[key] = REV_TYPE_MAP[type(value)](key, self)
+ return
pline = self.pipeline()
if self.exists(key):
pline = pline.delete(key)
@@ -103,3 +108,8 @@ def __contains__(self, key):
"""
return self.exists(key) or key in self.empties
+ def __delitem__(self, key):
+ if key in self.empties:
+ del self.empties[key]
+ self.delete(key)
+

0 comments on commit 591145b

Please sign in to comment.