• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 14 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

simple python datastructure wrappings for redis

If you'd like to be a contributor, send me a note! I'd be more than glad to pass this over to a more active maintainer.

This package exposes Redis backed datastructures which bring together standard Python syntax with persistent in-memory storage. Redis operations are all atomic as well, meaning that a thoughtful approach can use them concurrently on multiple machines.

Utimately, a trivial wrapper around Redis-Py.

Simple Installation

The simplest approach to installation is:

pip install redis
pip install -e git+https://github.com/lethain/Redis-Python-Datastructures.git#egg=redis_ds

Installation for development

For development, you should checkout the repository, and install it into a virtualenv:

# get the code
git clone https://github.com/lethain/Redis-Python-Datastructures.git
cd Redis-Python-Datastructures.git

# create and activate a virtualenv if you don't have one already
virtualenv env
. ./activate

# install it
pip install -r requirements.txt
python setup.py develop

Running tests

With some embarassment, the tests currently run against local Redis using keys prefixed with "test_rds.", and taking great pains not to delete any other keys, so if you have a toy Redis node, the tests will not cause any harm, but you really shouldn't run the tests against a Redis node you care deeply about.

Run them via:

python src/redis_ds/tests.py

The tests really ought to be run against a mocked out version of Redis, but that work hasn't been done yet.

Usage

This section covers how to use this library to interface with Redis.

Dictionary via Redis Strings

Using the entire Redis cluster as a dictionary:

>>> from redis_ds.redis_dict import RedisDict
>>> x = RedisDict()
>>> x
{}
>>> x['a'] = 100
>>> x
{'a': '100'}
>>> x['a']
'100'
>>> x['b']
>>> len(x)
1

Dictionaries via Redis Hashes

Using Redis hashes we can store multiple dictionaries in one Redis server.

>>> from redis_ds.redis_hash_dict import RedisHashDict
>>> x = RedisHashDict("some_hash_key")
>>> x
{}
>>> x['a'] = 100
>>> x
{'a': '100'}
>>> x['a']
'100'
>>> x['b']
>>> len(x)
1

Lists via Redis Lists

We also have a kind-of-sort-off implementation of a list which certainly doesn't have the full flexibility of a Python list, but is persistent, synchronized and sharable.

>>> from redis_ds.redis_list import RedisList
>>> x = RedisList("my-list")
>>> x
RedisList([])
>>> x.append("a")
1
>>> x.append("b")
2
>>> x
RedisList(['a', 'b'])
>>> x[0]
'a'
>>> x.pop()
'b'
>>> x
RedisList(['a'])

It also provides access to blocking versions of pop, which with a little creativity you can use to create a message queue with workers.

>>> x.pop(blocking=True)
'a'

Woohoo.

Sets

Sets are also available thanks to work by @hhuuggoo:

>>> from redis_ds.redis_set import RedisSet
>>> x = RedisSet()
>>> x.add("a")
>>> x.add("a")
>>> x.add("b")
>>> x.add("b")
>>> len(x)
2
>>> 'a' in x
True
>>> 'c' in x
False
>>> x.pop()
'a'
>>> len(x)
1

Serializing Values Stored in Redis

Thanks to work by @hhuuggoo, this library also supports serializing values before storing them in Redis. Each class has a serialized equivalent, for example the above hashmap example becomes:

>>> from redis_ds.redis_hash_dict import PickleRedisHashDict
>>> y = PickleRedisHashDict('some_other_key')
>>> y
{}
>>> y['a'] = {'obj': 'ect'}
>>> y
{'a': {'obj': 'ect'}}
>>> y['a']['obj']
'ect'

The same can be done using JSON instead of Pickle by changing it to:

>>> from redis_ds.redis_hash_dict import JSONRedisHashDict

and so on. The same is true for RedisList which has PickleRedisList and JSONRedisList, and so on.

More Repositories

1

systems

systems is a set of tools for describing, running and visualizing systems diagrams.
HTML
265
star
2

staff-eng

Collection of stories of how folks have reached Staff-plus roles in technology.
CSS
207
star
3

extraction

A Python library for extracting titles, images, descriptions and canonical urls from HTML.
Python
146
star
4

django-monetize

A pluggable Django application for delivering highly targeted advertisement.
Python
86
star
5

apache-log-parser

A Python command-line tool for parsing information from Apache log files.
Python
66
star
6

aym-cms

A Django templating based static CMS.
Python
59
star
7

django-userskins

A pluggable Django app for allowing users to pick among a variety of skins for webapps.
Python
43
star
8

lifeflow

A full featured and opinionated blogging solution using Django
Python
43
star
9

django-springsteen

A Django app for querying Yahoo! BOSS and aggregating service results.
Python
41
star
10

nagios_erlang

Nagios plugins for monitoring Erlang process groups/applications/nodes/etc
Shell
40
star
11

sparklines.js

A javascript library for creating bar and line Sparklines.
JavaScript
40
star
12

log-collector

node.js server for collecting logs and client for monitoring files and sending them to remote collection server
JavaScript
31
star
13

python-markdown-graphviz

support for embedding graphviz graphs inside markdown documents
Python
27
star
14

codernote

a django project for organizing, sharing and rendering code snippets and notes
JavaScript
17
star
15

metawindow

Repository for a PyObjC project built in one of my tutorial series.
Python
14
star
16

BeepBeep-Examples

A collection of BeepBeep examples
Erlang
13
star
17

go-learning-projects

A collection of projects for learning the Go programming language while also learning about the implementation details of open-source technologies you likely already use.
Go
13
star
18

llm-explorer

Experimentation with Streamlit for personal LLM tool
Python
12
star
19

django-syntax-colorize

A template filter for Django to apply Pygments syntax coloring to strings.
Python
11
star
20

dfsmr

Distributed runner for finite state machines.
Go
11
star
21

rethinkdb-extraction

A very simple example of using RethinkDB along with the Extraction library for a simpler crawler.
Python
11
star
22

distributed-key-value-store-example

an example of a distributed key-value store...
Erlang
11
star
23

couchdb_analytics

Erlang application using CouchDB to store visitor analytics for web applications.
Erlang
10
star
24

comfy-django-example

A tutorial that shows how to use CouchDB with Django.
Python
10
star
25

erlang_markdown

Markdown parser written in Erlang.
Erlang
9
star
26

systems-explorations

Examples of using systems library to model dynamic systems.
Jupyter Notebook
9
star
27

notes-djapp-tutorial

The Git repository for the Django, jQuery & Ajax tutorial series.
8
star
28

openai-experiments

Just me playing around with OpenAI
Python
8
star
29

sisyphus

A Redis-backed blog written in Django
Python
8
star
30

techwriters-dev

https://techwriters.dev - a community for authors writing technical content
8
star
31

digg-streaming

Examples for using the Digg Streaming API
Python
8
star
32

Redis-Memory-Usage-Tests

Collection of tests to measure redis memory usage.
Python
8
star
33

misc-clojure-snippets

collection of unorganized clojure snippets of questionable quality
Clojure
8
star
34

papersandsystems

Hold the source code for Papers and Systems!
HTML
7
star
35

resume-interactivity-provider

App for creating static resume-like pages with dynamic interactivity.
JavaScript
7
star
36

reflect-slack-app

A simple example of a Slack application
Python
7
star
37

pandoc-book-example

Python
6
star
38

extraction_tutorial

Working example of GraphQL, Flask and Python3.
Python
6
star
39

vtt_compactor

Compact VTT transcripts into a denser format
Python
6
star
40

mahou

A Cappuccino, Yahoo! BOSS, and Google App Engine based web search
6
star
41

infraeng-changes

git-scraping example monitoring changes to infraeng.dev
Python
5
star
42

python-twitter-remote

Barebones library for using twitter to run remote commands.
Python
5
star
43

python-utilities-misc

Collection of miscellaneous Python utilities.
Python
4
star
44

kappa

A PyObjC based Twitter client
4
star
45

haproxy-parser

Simple parser for HAProxy in Go, plus transforming to JSON.
Go
3
star
46

organize

Python library for parsing in messy real-world data files (CSV, TSV, Excel).
Python
3
star
47

workframe.js

A micro-web-framework for Node.js centered on imperative workflows
JavaScript
3
star
48

bossarray

A Python list like wrapper around the Yahoo BOSS search results.
Python
3
star
49

icarus

Icarus is a minimalistic blog platform for people who want to write Markdown or HTML documents in Git
Go
3
star
50

social-context

Python
2
star
51

k8s-fault-injection

Quick proof of concept for running fault injection against Kubernetes deployments.
Python
2
star
52

gareports_reader

Python library for parsing Google Analytics reports.
2
star
53

xlwt-examples-aws-pricing

An example of using the xlwt library to generate an AWS pricing calculator
Python
2
star
54

python_brightkite

A Python wrapper for the Brightkite API
Python
2
star
55

literal

Utility for maintaining state and rendering templates in text formats.
Rust
2
star
56

gke_ci

A very basic approach for last mile of continuous deployment on Google Container Engine, which updates deployment after successful Container Builds for associated deployments.
Python
2
star
57

lethain

1
star
58

ruby-learning-projects

Learning projects for Ruby.
Ruby
1
star
59

phabulous

A hopefully simpler wrapper around python-phabricator for playing with Phabricator data.
Python
1
star
60

Pitance

A command-line interface for the Pitance project.
1
star
61

comment-rater

Example of a 2-player Game With A Purpose implemented in Node.js
JavaScript
1
star
62

exuberant-sketches

sketches.lethain.com
HTML
1
star