Skip to main content

Easily store, index, and modify Python dicts in Redis (with flexible searching)

Project description

On install, the sample settings.ini file will be copied to the ~/.config/redis-helper directory.

Install latest tag of redis-helper from pypi

% pip install redis-helper

Install latest commit on master of redis-helper from github

% pip install git+git://github.com/kenjyco/redis-helper

Local development setup

% git clone https://github.com/kenjyco/redis-helper
% cd redis-helper
% python3 setup.py test     # optional, requires 'setuptools'
% ./dev-setup.bash

The dev-setup.bash script will create a virtual environment in the ./venv directory with extra dependencies (ipython, pdbpp, pytest), then copy settings.ini to the ~/.config/redis-helper directory.

Running tests in development setup

% venv/bin/py.test tests

or

% venv/bin/py.test -vsx -rs --pdb tests

The py.test options will run tests in a verbose manner and output the reason why tests were skipped (if any were skipped). If there are any failing tests, py.test will stop on the first failure and drop you into the debugger.

Usage

>>> import redis_helper as rh
>>> collection = rh.RedThing(..., index_fields='field1,field3')
>>> hash_id = collection.add(field1='', field2='', field3='', ...)
>>> collection.add(...)
>>> collection.add(...)
>>> collection.update(hash_id, field1='', field4='', ...)
>>> change_history = collection.old_data_for_hash_id(hash_id)
>>> data = collection.get(hash_id)
>>> some_data = collection.get(hash_id, 'field1,field3')
>>> results = collection.find(...)
>>> results2 = collection.find('field1:val,field3:val', ...)
>>> results3 = collection.find(..., get_fields='field2,field4')
>>> counts = collection.find(count=True, ...)
>>> top_indexed = collection.index_field_info()
>>> collection.delete(hash_id, ...)

Background

A Python dictionary is a very useful container for grouping facts about some particular entity. Dictionaries have keys that map to values (so if we want to retrieve a particular value stored in a dictionary, we can access it through its key). The dictionary itself is accessed by its variable name.

Redis is a data structure server (among other things). It is great for storing various types of objects that can be accessed between different programs and processes. When your program stops running, objects that you have stored in Redis will remain. To retreive an object from Redis, you must access it through its key name (kind of like a Python variable name). The redis Python package provides the StrictRedis class, which contains methods that correspond to all of the Redis server commands.

A Redis hash is most similar to a Python dictionary. A “key” in a Python dictionary is analogous to a “field” in a Redis hash (since “key” means something different in Redis).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_helper-0.2.7-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file redis_helper-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for redis_helper-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 14117f5a9a1112edbf41c087b5fd97e808ebab4fdbc0726efbd8252d8156d2dc
MD5 8e6702ac15d060913411ec71a1424bc1
BLAKE2b-256 b281a9b25e5da40977704b686969b47dd9629bdb1e8074705c40307943e5f792

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page