Skip to main content

PEP 3156 implementation of the redis protocol.

Project description

Features

  • Works for the asyncio (PEP3156) event loop

  • No dependencies

  • Connection pooling

  • Automatic conversion from unicode (Python) to bytes (inside Redis.)

  • Completely tested

  • Blocking calls and transactions supported

  • Streaming of some multi bulk replies

Documentation

View documentation at read-the-docs

Example using the Protocol class

import asyncio
from asyncio_redis import RedisProtocol

@asyncio.coroutine
def example():
    loop = asyncio.get_event_loop()

    # Create Redis connection
    transport, protocol = yield from loop.create_connection(
                RedisProtocol, 'localhost', 6379)

    # Set a key
    yield from protocol.set('my_key', 'my_value')

    # Get a key
    result = yield from protocol.get('my_key')
    print(result)

The connection class

asyncio_redis.Connection takes care of connection pooling. Requests will automatically be distributed among all connections. If a connection is blocking because of –for instance– a blocking rpop, the other connections will be used for new commands.

import asyncio
from asyncio_redis import Connection

@asyncio.coroutine
def example():
    # Create Redis connection
    connection = yield from Connection.create(port=6379, poolsize=10)

    # Set a key
    yield from connection.set('my_key', 'my_value')

    # Get a key
    result = yield from connection.get('my_key')
    print(result)

Transactions

Example:

import asyncio
from asyncio_redis import Connection

@asyncio.coroutine
def example():
    # Create Redis connection
    connection = yield from Connection.create(port=6379, poolsize=10)

    # Create transaction
    transaction = yield from connection.multi()

    # Run commands in transaction (they return future objects)
    f1 = yield from transaction.set('key', 'value')
    f1 = yield from transaction.set('another_key', 'another_value')

    # Commit transaction
    yield from transaction.exec()

    # Retrieve results
    result1 = yield from f1
    result2 = yield from f2

It’s recommended to use a large enough poolsize. A connection will be occupied as long as there’s a transaction running in there.

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

asyncio_redis-0.1.tar.gz (10.5 kB view details)

Uploaded Source

File details

Details for the file asyncio_redis-0.1.tar.gz.

File metadata

  • Download URL: asyncio_redis-0.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for asyncio_redis-0.1.tar.gz
Algorithm Hash digest
SHA256 c8d6bb6759d382520823448915ea3d68b6a812f058a00087024c2c3ebaa1506c
MD5 e7becd5b6043c3bb8eb76dd2738da1c9
BLAKE2b-256 6d217557b8d70c55d533a8227f9dddfa87b4170d9cbdfa6fcfd8aa68893888c1

See more details on using hashes here.

Supported by

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