Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 591145b16751f24ca7fdf0d0414ee606bcd195c9 1 parent 7236d71
Adam Lindsay authored

Showing 1 changed file with 16 additions and 6 deletions. Show diff stats Hide diff stats

  1. 22  redish/proxy.py
22  redish/proxy.py
@@ -56,6 +56,9 @@ def __getitem__(self, key):
56 56
         """Return a proxy type according to the native redis type 
57 57
         associated with the key."""
58 58
         typ = self.type(key)
  59
+        if typ == 'string':
  60
+            # because strings can be empty, check before "empties"
  61
+            return int_or_str(self.get(key), key, self)
59 62
         if key in self.empties:
60 63
             if typ == 'none':
61 64
                 return self.empties[key]
@@ -63,23 +66,25 @@ def __getitem__(self, key):
63 66
                 self.empties.pop(key)
64 67
         if typ == 'none':
65 68
             raise KeyError(key)
66  
-        elif typ == 'string':
67  
-            return int_or_str(self.get(key), key, self)
68 69
         else:
69 70
             return TYPE_MAP[typ](key, self)
70 71
     
71 72
     def __setitem__(self, key, value):
72 73
         """Copy the contents of the value into the redis store."""
  74
+        if key in self.empties:
  75
+            del self.empties[key]
73 76
         if isinstance(value, (int, types.Int)):
74 77
             self.set(key, int(value))
75 78
             return
76 79
         elif isinstance(value, basestring):
77 80
             self.set(key, encode(value, "UTF-8"))
78 81
             return
79  
-        if not value and value != None:
80  
-            self.empties[key] = REV_TYPE_MAP[type(value)](key, self)
81  
-        elif value and key in self.empties:
82  
-            self.empties.pop(key)
  82
+        if not value:
  83
+            if self.exists(key):
  84
+                self.delete(key)
  85
+            if value != None:
  86
+                self.empties[key] = REV_TYPE_MAP[type(value)](key, self)
  87
+            return
83 88
         pline = self.pipeline()
84 89
         if self.exists(key):
85 90
             pline = pline.delete(key)
@@ -103,3 +108,8 @@ def __contains__(self, key):
103 108
         """
104 109
         return self.exists(key) or key in self.empties
105 110
     
  111
+    def __delitem__(self, key):
  112
+        if key in self.empties:
  113
+            del self.empties[key]
  114
+        self.delete(key)
  115
+    

0 notes on commit 591145b

Please sign in to comment.
Something went wrong with that request. Please try again.