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
Release history Release notifications | RSS feed
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 Distributions
redisobjects-0.7.8-py3.6.egg
(36.7 kB
view details)
File details
Details for the file redisobjects-0.7.8-py3.6.egg
.
File metadata
- Download URL: redisobjects-0.7.8-py3.6.egg
- Upload date:
- Size: 36.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f70a77be1d9f462f08a96eec2aa557865decee31b5f92bac8795b9c8d56e00a |
|
MD5 | 2f56af54c34f38926cc1007fe0a44b74 |
|
BLAKE2b-256 | 2a8259b6c2a55faddb95d78e276e3ccf7780566ad15c64171acb9898bd061ced |
File details
Details for the file redisobjects-0.7.8-py3-none-any.whl
.
File metadata
- Download URL: redisobjects-0.7.8-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc0160a51e90efdb0d1d93ccb295fd9d0eaabf9beede328e3113b0d58324a99e |
|
MD5 | 8d2524a6d0992b01665e91c0aa9df571 |
|
BLAKE2b-256 | efa1f7e09248dbcd0ccc220d7be2cbebe97b337c786a832ae1e7f94ea39ad1cc |