Anonymous avatar Anonymous committed 15b9d55

Run all setting operations through handle_set, in preparation for adding EXPIRES

Comments (0)

Files changed (1)

 from collections import deque
+def _parse_int(value, default=0):
+    if isinstance(value, str):
+        # int() can't deal with '1.23', so let's strip off everything after a .
+        value = value.split('.')[0]
+    try:
+        return int(value)
+    except ValueError:
+        return default
 class RedisConstant(object):
     def __init__(self, type):
         self.type = type
         return self.handle_incrby(client, key, 1)
     def handle_incrby(self, client, key, by):
+        by = _parse_int(by, 0)
-            client.table[key] = int(client.table[key])
-            client.table[key] += int(by)
-        except (KeyError, TypeError, ValueError):
-            client.table[key] = 1
+            value = _parse_int(client.table[key]) + by
+        except (KeyError, TypeError):
+            value = by
+        self.handle_set(client, key, value, False)
         self.log(client, 'INCRBY %s %s -> %s' % (key, by, client.table[key]))
         return client.table[key]
         self.log(client, 'SELECT %s' % db)
         return True
-    def handle_set(self, client, key, data):
+    def handle_set(self, client, key, data, log_it=True):
         client.table[key] = data
-        self.log(client, 'SET %s -> %s' % (key, data))
+        if log_it:
+            self.log(client, 'SET %s -> %s' % (key, data))
         return True
     def handle_setnx(self, client, key, data):
         if key in client.table:
             self.log(client, 'SETNX %s -> %s FAILED' % (key, data))
             return 0
-        client.table[key] = data
+        self.handle_set(client, key, data, False)
         self.log(client, 'SETNX %s -> %s' % (key, data))
         return 1
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.