diff --git a/README.rst b/README.rst index 72d9edfab..faadd7adb 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -53,7 +57,7 @@ Well, expect things to be broken. Really broken. Models ------ -:: +.. code-block:: python from redisco import models class Person(models.Model): @@ -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() @@ -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() @@ -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': @@ -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') @@ -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)) @@ -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') @@ -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') @@ -314,6 +324,9 @@ Lists Sorted Sets + +.. code-block:: python + >>> zset = SortedSet('zset') >>> zset.members ['d', 'a', 'b', 'c'] @@ -336,6 +349,9 @@ Sorted Sets Dicts/Hashes + +.. code-block:: python + >>> h = cont.Hash('hkey') >>> len(h) 0 @@ -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 @@ -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) @@ -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) @@ -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