Permalink
Browse files

more on redish.proxy in README

  • Loading branch information...
1 parent 4df82b2 commit 6136bab9bacbcb09088483bdacc0d58fb4edaa47 @atl atl committed Jun 1, 2010
Showing with 42 additions and 12 deletions.
  1. +30 −9 README.rst
  2. +12 −3 redish/types.py
View
@@ -498,28 +498,44 @@ score)`` tuples::
redish.proxy
============
-The proxy submodule offers a different view on the redis datastore:
-it exposes the strings, integers, lists, hashes, sets and sorted sets within
-the datastore transparently, as if they were native Python objects accessed
-by key on the proxy object. For example::
+The proxy submodule offers a different view on the redis datastore: it exposes
+the strings, integers, lists, hashes, sets and sorted sets within the
+datastore transparently, as if they were native Python objects accessed by key
+on the proxy object. They do not store serialized objects as with the rest of
+redish. For example::
>>> from redish import proxy
>>> r = proxy.Proxy()
-
+
+Key access yields an object that acts like the Python equivalent of the
+underlying Redis structure. That structure can be read and modified as if it
+is native, local object. Here, that object acts like a dict::
+
>>> r['mydict']
{'father': 'Frank Costanza', 'name': 'George Louis Costanza', 'mother': 'Estelle Costanza'}
>>> r['mydict']['name']
'George Louis Costanza'
>>> r['mydict']['name'] = "Georgie"
>>> r['mydict']['name']
'Georgie'
-
+
+Sometimes, it may be convenient to assign a variable to the proxy object, and
+use that in subsequent operations::
+
>>> ss = r['myset']
>>> 'George' in ss
True
>>> 'Ringo' in ss
False
-
+
+The Proxy object is a subclass of a normal redis.Client object, and so
+supports the same methods (other than `__getitem__`, `__setitem__`,
+`__contains__`, and `__delitem__`). The object that the proxy object returns
+is an instance of one of the classes from redish.types (with the exception of
+unicode: those are simply serialized/unserialized from the underlying redis
+data store as UTF-8).
+::
+
>>> r['mycounter'] = 1
>>> cc = r['mycounter']
>>> cc += 1
@@ -528,13 +544,18 @@ by key on the proxy object. For example::
'3'
>>> type(cc)
<class 'redish.types.Int'>
-
+
+Since redis does not support empty sets, lists, or hashes, the proxy object
+will (thread-)locally 'remember' keys that are explicitly set as empty types.
+It does not currently remember container types that have been emptied as a
+product of operations on the underlying store::
+
>>> r['newlist'] = []
>>> r['newlist'].extend([1,2])
>>> len(r['newlist'])
2
-For more information, see the documentation.
+For more information, see the redish.proxy documentation.
Installation
============
View
@@ -60,7 +60,9 @@ def __getslice__(self, i, j):
def _as_list(self):
return self.client.lrange(self.name, 0, -1)
-
+
+ copy = _as_list
+
def append(self, value):
"""Add ``value`` to the end of the list."""
return self.client.rpush(self.name, value)
@@ -130,7 +132,9 @@ def __len__(self):
def _as_set(self):
return self.client.smembers(self.name)
-
+
+ copy = _as_set
+
def add(self, member):
"""Add element to set.
@@ -296,7 +300,9 @@ def update(self, iterable):
def _as_set(self):
return self.client.zrange(self.name, 0, -1)
-
+
+ copy = _as_set
+
def items(self):
return self.client.zrange(self.name, 0, -1, withscores=True)
@@ -421,6 +427,8 @@ def update(self, other):
def _as_dict(self):
return self.client.hgetall(self.name)
+
+ copy = _as_dict
class Queue(Type):
@@ -675,6 +683,7 @@ def __int__(self):
def __repr__(self):
return repr(int(self))
+ copy = __int__
def is_zsettable(s):
"""quick check that all values in a dict are reals"""

0 comments on commit 6136bab

Please sign in to comment.