1. Lucian Brănescu-Mihăilă
  2. mapredis

Commits

Lucian Brănescu-Mihăilă  committed 69b2485 Draft

More complete String. Counter.

  • Participants
  • Parent commits 04c4fc9
  • Branches default

Comments (0)

Files changed (1)

File data.py

View file
 
 
 class String(object):
-    def __init__(self, name):
+    def __init__(self, name, content=None):
         self.name = name
 
+        if content and isinstance(str, content):
+            r.set(self.name, content)
+
+    def __repr__(self):
+        return repr(r.get(self.name))
+
+    def __len__(self):
+        return r.strlen(self.name)
+
+    def __getitem__(self, index):
+        if isinstance(slice, index):
+            return r.getrange(self.name,
+                              slice.start or 0,
+                              slice.stop or len(self))
+        else:
+            return r.getbit(self.name)
+
+
+class Counter(object):
+    def __init__(self, name, value=None):
+        self.name = name
+
+        if value and isinstance(int, value):
+            r.set(self.name, value)
+
+    def __repr__(self):
+        return r.get(self.name)
+
+    def incr(self):
+        r.incr(self.name)
+
+    def decr(self):
+        r.decr(self.name)
+
 
 class List(object):
     def __init__(self, name, iterable=None):