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
12 changes: 10 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
@@ -134,6 +134,14 @@ Creates a new ReJSON client.
``encoder`` should be an instance of a ``json.JSONEncoder`` class
``decoder`` should be an instance of a ``json.JSONDecoder`` class

**IMPORTANT**: With Python 3 the redis-py client defaults to returning bytes
instead of string replies. To overcome this, make sure that you
initialize the class with its ``decode_responses`` argument set to
``True``, e.g.:

```py
rj = Client(host='localhost', port=6379, decode_responses=True)
```

### jsonarrappend
```py
@@ -210,7 +218,7 @@ def jsonarrtrim(self, name, path, start, stop)



Trim the array JSON value under ``path`` at key ``name`` to the
Trim the array JSON value under ``path`` at key ``name`` to the
inclusive range given by ``start`` and ``stop``


@@ -248,7 +256,7 @@ def jsonmget(self, path, *args)



Gets the objects stored as a JSON values under ``path`` from
Gets the objects stored as a JSON values under ``path`` from
keys ``args``


14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

[![Mailing List](https://img.shields.io/badge/Mailing%20List-RedisJSON-blue)](https://groups.google.com/forum/#!forum/redisjson)
[![Gitter](https://badges.gitter.im/RedisLabs/RedisJSON.svg)](https://gitter.im/RedisLabs/RedisJSON?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

rejson-py is a package that allows storing, updating and querying objects as
JSON documents in a [Redis](https://redis.io) database that is extended with the
[ReJSON module](https://github.com/redislabsmodules/rejson). The package extends
@@ -67,6 +67,18 @@ $ pip install rejson
print '{} is a non-ascii string'.format(rj.jsonget('non-ascii', Path('.non_ascii_string'), no_escape=True))
```

## Python 2 vs. 3

The following is an excerpt from [redis-py's README "Getting Started" section](https://github.com/andymccurdy/redis-py/blob/master/README.rst#getting-started):

> By default, all responses are returned as bytes in Python 3 and str in Python 2. The user is responsible for decoding to Python 3 strings or Python 2 unicode objects.
Because of that, when using this client with Python 3, you initialize it with the base class's `decode_responses` argument set to `True`, e.g.:

```py
rj = Client(host='localhost', port=6379, decode_responses=True)
```

## Encoding/Decoding

rejson-py uses Python's [json](https://docs.python.org/2/library/json.html).
15 changes: 12 additions & 3 deletions rejson/client.py
Original file line number Diff line number Diff line change
@@ -44,6 +44,15 @@ def __init__(self, encoder=None, decoder=None, *args, **kwargs):
``encoder`` should be an instance of a ``json.JSONEncoder`` class
``decoder`` should be an instance of a ``json.JSONDecoder`` class
IMPORTANT: With Python 3 the redis-py client defaults to returning bytes
instead of string replies. To overcome this, make sure that you
initialize the class with its ``decode_responses`` argument set to
``True``, e.g.:
```
rj = Client(host='localhost', port=6379, decode_responses=True)
```
"""
self.setEncoder(encoder)
self.setDecoder(decoder)
@@ -69,7 +78,7 @@ def __init__(self, encoder=None, decoder=None, *args, **kwargs):
}
for k, v in six.iteritems(MODULE_CALLBACKS):
self.set_response_callback(k, v)

def setEncoder(self, encoder):
"""
Sets the client's encoder
@@ -124,7 +133,7 @@ def jsonget(self, name, *args, no_escape=False):

def jsonmget(self, path, *args):
"""
Gets the objects stored as a JSON values under ``path`` from
Gets the objects stored as a JSON values under ``path`` from
keys ``args``
"""
pieces = []
@@ -228,7 +237,7 @@ def jsonarrpop(self, name, path=Path.rootPath(), index=-1):

def jsonarrtrim(self, name, path, start, stop):
"""
Trim the array JSON value under ``path`` at key ``name`` to the
Trim the array JSON value under ``path`` at key ``name`` to the
inclusive range given by ``start`` and ``stop``
"""
return self.execute_command('JSON.ARRTRIM', name, str_path(path), start, stop)