Skip to main content

ORM for Redis

Project description

PyPI Version Build Status

redis-astra

Redis-astra is Python light ORM for Redis

Example:

import redis
from astra import models

db = redis.StrictRedis(host='127.0.0.1', decode_responses=True)

class SiteObject(models.Model):
    database = db
    name = models.CharHash()

class UserObject(models.Model):
    database = db
    name = models.CharHash()
    login = models.CharHash()
    site_id = models.ForeignKey(to='SiteObject')
    sites_list = models.List(to='SiteObject')
    viewers = models.IntegerField()

So you can use it like this:

>>> user = UserObject(pk=1, name="Mike", viewers=5)
>>> user.login = 'mike@null.com'
>>> user.login
'mike@null.com'
>>> user.viewers_incr(2)
7
>>> site = SiteObject(pk=1, name="redis.io")
>>> user.site_id = site
>>> user.sites_list.lpush(site, site, site)
3
>>> len(user.sites_list)
3
>>> user.sites_list[2].name
'redis.io'

Redis-astra supported signals, based on PyDispatcher:

from astra import signals

def save_handler(**kwargs):
    print(kwargs)

signals.post_init.connect(save_handler)
signals.post_assign.connect(save_handler)

>>> user = UserObject(pk=1, name="Mike", viewers=5)
{'signal': 'post_init', 'instance': <Model UserObject(pk=1)>, 'sender': <class '__main__.UserObject'>}

>>> user.login = 'mike@null.com'
{'signal': 'post_assign', 'value': 'mike@null.com', 'instance': <Model UserObject(pk=1)>, 'attr': 'login', 'sender': <class '__main__.UserObject'>}

Install

Python versions 2.6, 2.7, 3.3, 3.4, 3.5 are supported Redis-py versions >= 2.9.1

pip install redis-astra

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-astra-1.0.3.zip (12.5 kB view details)

Uploaded Source

File details

Details for the file redis-astra-1.0.3.zip.

File metadata

  • Download URL: redis-astra-1.0.3.zip
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for redis-astra-1.0.3.zip
Algorithm Hash digest
SHA256 21914fa660631fb7a9544e9e4b8b44376f388d4bc8a1c092463a336802d50f4c
MD5 2d341d9b3188c8a2534b2c527b7fd69f
BLAKE2b-256 2b6ac459b898f36fd11ae0b5de7bb36c58ffd96a48138b25aa3dc32f46693838

See more details on using hashes here.

Supported by

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