Skip to main content

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

Project description

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

Install

% pip install redis-helper

or

% pip install git+git://github.com/kenjyco/redis_helper

Modify the ~/.config/redis-helper/settings.ini file.

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, ...)

Note: this is only a small usage sample. Several ``RedThing``
methods have many parameters.

Test running

% git clone https://github.com/kenjyco/redis_helper
% cd redis_helper
% python3 setup.py test

Note: requires setuptools (i.e.
``sudo apt-get install python3-setuptools``)

Dev setup

% git clone https://github.com/kenjyco/redis_helper
% cd redis_helper
% ./dev-setup.bash

Create a virtual environment with extra dependencies (ipython,
pdbpp, pytest).

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).

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). The redis-py library provides the StrictRedis class, which contain methods that correspond to all of the Redis server commands.

Project details


Download files

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

Source Distribution

redis-helper-0.2.1.tar.gz (12.0 kB view details)

Uploaded Source

File details

Details for the file redis-helper-0.2.1.tar.gz.

File metadata

  • Download URL: redis-helper-0.2.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for redis-helper-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bfeeadbaad592f79815b970d9fe038ca609ce0c515ced23af959d0fea8251ddf
MD5 42ec026dafe8a9397527486e5b4065e5
BLAKE2b-256 da4e089a9197576eced3b589a298c5251b8d36e60fb468967344b9848a9934c2

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