Giter Site home page Giter Site logo

willman0982 / aredis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nonegg/aredis

0.0 0.0 0.0 723 KB

redis client for Python asyncio (has support for redis server, sentinel and cluster)

Home Page: http://aredis.readthedocs.io/en/latest/

License: MIT License

Python 99.29% C 0.71%

aredis's Introduction

aredis

Latest Version in PyPI CircleCI build status Supported Python versions

An efficient and user-friendly async redis client ported from redis-py (which is a Python interface to the Redis key-value)

To get more information please read full document

Installation

aredis requires a running Redis server.

To install aredis, simply:

$ pip3 install aredis[hiredis]

or from source:

$ python setup.py install

Getting started

More examples

Tip: since python 3.8 you can use asyncio REPL:

$ python -m asyncio

single node client

import asyncio
from aredis import StrictRedis

async def example():
    client = StrictRedis(host='127.0.0.1', port=6379, db=0)
    await client.flushdb()
    await client.set('foo', 1)
    assert await client.exists('foo') is True
    await client.incr('foo', 100)

    assert int(await client.get('foo')) == 101
    await client.expire('foo', 1)
    await asyncio.sleep(0.1)
    await client.ttl('foo')
    await asyncio.sleep(1)
    assert not await client.exists('foo')

loop = asyncio.get_event_loop()
loop.run_until_complete(example())

cluster client

 import asyncio
 from aredis import StrictRedisCluster

 async def example():
     client = StrictRedisCluster(host='172.17.0.2', port=7001)
     await client.flushdb()
     await client.set('foo', 1)
     await client.lpush('a', 1)
     print(await client.cluster_slots())

     await client.rpoplpush('a', 'b')
     assert await client.rpop('b') == b'1'

loop = asyncio.get_event_loop()
loop.run_until_complete(example())
# {(10923, 16383): [{'host': b'172.17.0.2', 'node_id': b'332f41962b33fa44bbc5e88f205e71276a9d64f4', 'server_type': 'master', 'port': 7002},
# {'host': b'172.17.0.2', 'node_id': b'c02deb8726cdd412d956f0b9464a88812ef34f03', 'server_type': 'slave', 'port': 7005}],
# (5461, 10922): [{'host': b'172.17.0.2', 'node_id': b'3d1b020fc46bf7cb2ffc36e10e7d7befca7c5533', 'server_type': 'master', 'port': 7001},
# {'host': b'172.17.0.2', 'node_id': b'aac4799b65ff35d8dd2ad152a5515d15c0dc8ab7', 'server_type': 'slave', 'port': 7004}],
# (0, 5460): [{'host': b'172.17.0.2', 'node_id': b'0932215036dc0d908cf662fdfca4d3614f221b01', 'server_type': 'master', 'port': 7000},
# {'host': b'172.17.0.2', 'node_id': b'f6603ab4cb77e672de23a6361ec165f3a1a2bb42', 'server_type': 'slave', 'port': 7003}]}

Benchmark

Please run test script in benchmarks dir to confirm the benchmark.

For benchmark in my environment please see: benchmark

Contributing

Enhancement, bug reports and Pull requests are welcomed, please make an issue to let me know. Fork me please~

aredis's People

Contributors

nonegg avatar inytar avatar fogapod avatar bsergean avatar thekevjames avatar eoghanmurray avatar mjwestcott avatar thiefmaster avatar amatai avatar coykto avatar barbieri avatar jayh5 avatar mumbleskates avatar pliu avatar rubyw avatar xchange avatar bjowi avatar kingnand avatar mek-yt avatar stj avatar whiteplanet avatar marsoft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.