Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds usage notice for Python3 #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down Expand Up @@ -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``


Expand Down Expand Up @@ -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``


Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
15 changes: 12 additions & 3 deletions rejson/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand Down