Skip to content
Browse files

Added API reference

  • Loading branch information...
1 parent c0a5838 commit aebcf26be59b82457f4bcc6b3be1e264cdade5c4 Ask Solem committed Apr 29, 2010
View
8 Changelog
@@ -0,0 +1,8 @@
+================
+ Change History
+================
+
+0.0.1 [2010-04-29 04:40 P.M CET]
+================================
+
+* Initial release.
View
0 docs/changelog.rst
No changes.
View
1 docs/changelog.rst
View
3 docs/index.rst
@@ -1,4 +1,4 @@
-redish Documentation
+Redish Documentation
==================================
Contents:
@@ -7,6 +7,7 @@ Contents:
:maxdepth: 3
introduction
+ reference/index
changelog
View
37 docs/introduction.rst
@@ -1,37 +0,0 @@
-============================================================================
-redish - Pythonic Redis abstraction built on top of redis-py
-============================================================================
-
-:Version: 0.0.1
-
-Introduction
-============
-
-.. Please write an introduction to your package here.
-
-Installation
-============
-
-You can install ``redish`` either via the Python Package Index (PyPI)
-or from source.
-
-To install using ``pip``,::
-
- $ pip install redish
-
-
-To install using ``easy_install``,::
-
- $ easy_install redish
-
-
-If you have downloaded a source tarball you can install it
-by doing the following,::
-
- $ python setup.py build
- # python setup.py install # as root
-
-Examples
-========
-
-.. Please write some examples using your package here.
View
1 docs/introduction.rst
View
16 docs/reference/index.rst
@@ -0,0 +1,16 @@
+===============
+ API Reference
+===============
+
+:Release: |version|
+:Date: |today|
+
+.. toctree::
+ :maxdepth: 2
+
+ redish.client
+ redish.types
+ redish.models
+ redish.serialization
+ redish.utils
+
View
8 docs/reference/redish.client.rst
@@ -0,0 +1,8 @@
+==========================
+ Database - redish.client
+==========================
+
+.. currentmodule:: redish.client
+
+.. automodule:: redish.client
+ :members:
View
8 docs/reference/redish.models.rst
@@ -0,0 +1,8 @@
+========================
+ Models - redish.models
+========================
+
+.. currentmodule:: redish.models
+
+.. automodule:: redish.models
+ :members:
View
8 docs/reference/redish.serialization.rst
@@ -0,0 +1,8 @@
+======================================
+ Serialization - redish.serialization
+======================================
+
+.. currentmodule:: redish.serialization
+
+.. automodule:: redish.serialization
+ :members:
View
8 docs/reference/redish.types.rst
@@ -0,0 +1,8 @@
+==========================
+ Datatypes - redish.types
+==========================
+
+.. currentmodule:: redish.types
+
+.. automodule:: redish.types
+ :members:
View
8 docs/reference/redish.utils.rst
@@ -0,0 +1,8 @@
+==========================
+ Utilities - redish.utils
+==========================
+
+.. currentmodule:: redish.utils
+
+.. automodule:: redish.utils
+ :members:
View
26 redish/serialization.py
@@ -9,21 +9,45 @@
class Serializer(object):
+ """Base class for serializers.
+
+ :keyword encoding: Optional encoding applied after serialization,
+ and before deserialization.
+
+ Example using compression::
+
+ >>> s = Pickler(encoding="zlib")
+ >>> val = s.encode({"foo: "bar"})
+ >>> s.decode(val)
+
+ Serializers must implement the :meth:`serialize` and :meth:`deserialize`
+ methods. Both take a single argument, which is the value to
+ serialize/deserialize.
+
+ """
def __init__(self, encoding=None):
self.encoding = encoding
def encode(self, value):
+ """Encode value."""
value = self.serialize(value)
if self.encoding:
value = value.encode(self.encoding)
return value
def decode(self, value):
+ """Decode value."""
if self.encoding:
value = value.decode(self.encoding)
return self.deserialize(value)
+ def serialize(self, value):
+ raise NotImplementedError("Serializers must implement serialize()")
+
+ def deserialize(self, value):
+ raise NotImplementedError("Serializers must implement deserialize()")
+
class Plain(Serializer):
"""A pass-through serializer.
@@ -55,7 +79,9 @@ def deserialize(self, value):
class JSON(Serializer):
def serialize(self, value):
+ """Encode value to JSON format."""
return anyjson.serialize(value)
def deserialize(self, value):
+ """Decode JSON to Python object."""
return anyjson.deserialize(value)
View
5 redish/types.py
@@ -6,13 +6,15 @@
class Type(object):
+ """Base-class for Redis datatypes."""
def __init__(self, name, client):
self.name = mkey(name)
self.client = client
def Id(name, client):
+ """Return the next value for an unique id."""
return "%s:%s" % (name, client.incr("ids:%s" % (name, )), )
@@ -237,6 +239,7 @@ def remove(self, member):
raise KeyError(member)
def revrange(self, start=0, stop=-1):
+ stop = stop is None and -1 or stop
return self.client.zrevrange(self.name, start, stop)
def increment(self, member, amount=1):
@@ -268,8 +271,8 @@ def _as_set(self):
return self.client.zrange(self.name, 0, -1)
-
class Dict(Type):
+ """A dictionary."""
def __init__(self, name, client, initial=None, **extra):
super(Dict, self).__init__(name, client)

0 comments on commit aebcf26

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