Skip to main content

Object-oriented wrapper for aioredis.

Project description

Redisobjects

Simple wrapper for aioredis to provide asynchronous functionality with a clean object-oriented interface for Redis in Python 3.6+.

Installation

pip install redisobjects

Examples

Example showing how to use atoms (defined as single key-value pairs):

import redisobjects
import asyncio

async def main(loop):
    redis = await redisobjects.connect('redis://localhost', loop=loop)
    atom = redis.atom('example.atom')
    print(await atom.get())
    await atom.set('bla')
    print(await atom.get())
    await atom.remove()
    print(await atom.get())
    redis.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()

Example that shows how to use a list:

import redisobjects
import asyncio

async def main(loop):
    redis = await redisobjects.connect('redis://localhost', loop=loop)
    example_list = redis.list('example.list')
    print(await example_list.list())
    await example_list.push_right('b')
    await example_list.push_right('c')
    print(await example_list.list())
    await example_list.push_left('a')
    print(await example_list.list())
    await example_list.pop_left()
    await example_list.pop_left()
    print(await example_list.list())
    await example_list.pop_left()
    print(await example_list.list())
    redis.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()

Example that shows how to use a dict/map:

import redisobjects
import asyncio

async def main(loop):
    redis = await redisobjects.connect('redis://localhost', loop=loop)
    d = redis.dict('example.dict')
    print(dict(await d.items()))
    await d.set('a', '1')
    print(dict(await d.items()))
    await d.set('b', '2')
    print(dict(await d.items()))
    await d.set('c', '3')
    print(dict(await d.items()))
    await d.remove('a', 'b')
    print(dict(await d.items()))
    await d.remove('c')
    print(dict(await d.items()))
    redis.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()

Example that shows how to use transactions:

import redisobjects
import asyncio

async def main(loop):
    redis = await redisobjects.connect('redis://localhost', loop=loop)
    list = redis.list('example.list')
    atom = redis.atom('example.atom')
    tx = redis.create_transaction()
    await list.push_right('a', 'b', tx=tx)
    await atom.set('a', tx=tx)
    print(await list.list())
    print(await atom.get())
    await tx.commit()
    print(await list.list())
    print(await atom.get())
    # Clean up
    await list.remove('a')
    await list.remove('b')
    await atom.remove()
    redis.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()

Project details


Download files

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

Files for redisobjects, version 0.7.8
Filename, size File type Python version Upload date Hashes
Filename, size redisobjects-0.7.8-py3.6.egg (36.7 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size redisobjects-0.7.8-py3-none-any.whl (16.1 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page