Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ Installation
------------
Redisco requires redis-py 2.0.0 so get it first.

.. code-block:: bash

pip install redis

Then install redisco.

.. code-block:: bash

pip install redisco


Expand Down Expand Up @@ -53,7 +57,7 @@ Well, expect things to be broken. Really broken.
Models
------

::
.. code-block:: python

from redisco import models
class Person(models.Model):
Expand Down Expand Up @@ -149,7 +153,7 @@ Class options
You can specify some options in your Model to control the behaviour of the
back scene.

::
.. code-block:: python

class User(models.Model):
firstname = models.Attribute()
Expand Down Expand Up @@ -179,7 +183,7 @@ Managers are attached to Model attributes by looking for a ``__attr_name__``
class attribute. If not present, then it defaults to the lowercase attribute
name in the Model.

::
.. code-block:: python

class User(models.Model):
firstname = models.Attribute()
Expand Down Expand Up @@ -215,7 +219,7 @@ of the attribute. The callable should return a list of errors.
Model.validate will also be called before saving the instance. Override it
to validate instances not related to attributes.

::
.. code-block:: python

def not_me(field_name, value):
if value == 'Me':
Expand All @@ -242,7 +246,7 @@ Queries
Queries are executed using a manager, accessed via the objects class
attribute.

::
.. code-block:: python

Person.objects.all()
Person.objects.filter(name='Conchita')
Expand All @@ -257,7 +261,7 @@ Redisco has a limited support for queries involving ranges -- it can only
filter fields that are numeric, i.e. DateField, DateTimeField, IntegerField,
and FloatField. The zfilter method of the manager is used for these queries.

::
.. code-block:: python

Person.objects.zfilter(created_at__lt=datetime(2010, 4, 20, 5, 2, 0))
Person.objects.zfilter(created_at__gte=datetime(2010, 4, 20, 5, 2, 0))
Expand All @@ -271,6 +275,9 @@ structures: lists, sets, sorted set. Anything done to the container is
persisted to Redis.

Sets

.. code-block:: python

>>> from redisco.containers import Set
>>> s = Set('myset')
>>> s.add('apple')
Expand All @@ -296,6 +303,9 @@ Sets
set(['kiwi', 'orange', 'guava', 'apple'])

Lists

.. code-block:: python

>>> from redisco.containers import List
>>> l = List('alpha')
>>> l.append('a')
Expand All @@ -314,6 +324,9 @@ Lists


Sorted Sets

.. code-block:: python

>>> zset = SortedSet('zset')
>>> zset.members
['d', 'a', 'b', 'c']
Expand All @@ -336,6 +349,9 @@ Sorted Sets


Dicts/Hashes

.. code-block:: python

>>> h = cont.Hash('hkey')
>>> len(h)
0
Expand All @@ -353,6 +369,8 @@ Additional Info on Containers
Some methods of the Redis client that require the key as the first argument
can be accessed from the container itself.

.. code-block:: python

>>> l = List('mylist')
>>> l.lrange(0, -1)
0
Expand All @@ -374,7 +392,7 @@ All models and containers use a global Redis client object to
interact with the key-value storage. By default, it connects
to localhost:6379, selecting db 0. If you wish to specify settings:

::
.. code-block:: python

import redisco
redisco.connection_setup(host='localhost', port=6380, db=10)
Expand All @@ -384,6 +402,8 @@ The arguments to connect are simply passed to the redis.Redis init method.
For the containers, you can specify a second argument as the Redis client.
That client object will be used instead of the default.

.. code-block:: python

>>> import redis
>>> r = redis.Redis(host='localhost', port=6381)
>>> Set('someset', r)
Expand All @@ -396,11 +416,15 @@ Redisco uses nose for testing.

Install nosetests:

$ pip install nose
.. code-block:: bash

pip install nose

And test:

$ nosetests
.. code-block:: bash

nosetests


Credits
Expand Down