Skip to content

A pure-Python(3.7+) zero-depend asyncio memcached client, fork from aiomcache.

License

Notifications You must be signed in to change notification settings

rexzhang/aiomemcached

 
 

Repository files navigation

AioMemcached

GitHub Pytest Workflow Status codecov Code style: black

A pure-Python(3.7+) zero-depend asyncio memcached client, fork from aiomcache.

people
Author Nikolay Kim [email protected]
Maintainer Rex Zhang [email protected]
Contributions Nikolay Novik [email protected]
Andrew Svetlov [email protected]
Rex Zhang [email protected]
Manuel Miranda [email protected]
Jeong YunWon https://github.com/youknowone
Thanos Lefteris https://github.com/alefteris
Maarten Draijer [email protected]
Michael Gorven [email protected]

Install

pip install -U AioMemcached

Usage

Base command examples

Code

import asyncio

import aiomemcached


async def base_command():
    client = aiomemcached.Client()

    print('client.version() =>', await client.version())

    print('\ninit key and value:')
    k1, k2, v1, v2 = b'k1', b'k2', b'1', b'v2'
    print("k1, k2, v1, v2 = b'k1', b'k2', b'1', b'2'")
    keys = [k1, k2]
    print("keys = [k1, k2]")

    print('\nget and set key:')
    print('client.set(k1, v1) =>', await client.set(k1, v1))
    print('client.get(k1) =>', await client.get(k1))
    print('client.set(k2, v2) =>', await client.set(k2, v2))
    print('client.get(k2) =>', await client.get(k2))

    print('\nincr and decr value:')
    print('client.incr(k1) =>', await client.incr(k1))
    print('client.decr(k1) =>', await client.decr(k1))

    print('\nget multi key:')
    print('client.get_many(keys) =>', await client.get_many(keys))
    print('client.gets_many(keys) =>', await client.gets_many(keys))
    print('client.set(k2, v2) =>', await client.set(k2, v2))
    print('client.gets_many(keys) =>', await client.gets_many(keys))

    print('\ndelete key:')
    print('client.delete(k1) =>', await client.delete(k1))
    print('client.gets_many(keys) =>', await client.gets_many(keys))

    print('\nappend value to key:')
    print("client.append(k2, b'append') =>",
          await client.append(k2, b'append'))
    print('client.get(k2) =>', await client.get(k2))

    print('flush memcached:')
    print('client.flush_all() =>', await client.flush_all())
    print('client.get_many(keys) =>', await client.get_many(keys))

    return


if __name__ == '__main__':
    asyncio.run(base_command())

Output

client.version() => b'1.6.9'

init key and value:
k1, k2, v1, v2 = b'k1', b'k2', b'1', b'2'
keys = [k1, k2]

get and set key:
client.set(k1, v1) => True
client.get(k1) => (b'1', {'flags': 0, 'cas': None})
client.set(k2, v2) => True
client.get(k2) => (b'v2', {'flags': 0, 'cas': None})

incr and decr value:
client.incr(k1) => 2
client.decr(k1) => 1

get multi key:
client.get_many(keys) => ({b'k1': b'1', b'k2': b'v2'}, {b'k1': {'flags': 0, 'cas': None}, b'k2': {'flags': 0, 'cas': None}})
client.gets_many(keys) => ({b'k1': b'1', b'k2': b'v2'}, {b'k1': {'flags': 0, 'cas': 168}, b'k2': {'flags': 0, 'cas': 166}})
client.set(k2, v2) => True
client.gets_many(keys) => ({b'k1': b'1', b'k2': b'v2'}, {b'k1': {'flags': 0, 'cas': 168}, b'k2': {'flags': 0, 'cas': 169}})

delete key:
client.delete(k1) => True
client.gets_many(keys) => ({b'k2': b'v2'}, {b'k2': {'flags': 0, 'cas': 169}})

append value to key:
client.append(k2, b'append') => True
client.get(k2) => (b'v2append', {'flags': 0, 'cas': None})
flush memcached:
client.flush_all() => True
client.get_many(keys) => ({}, {})

Development

Unit test and coverage report

python -m pytest

About

A pure-Python(3.7+) zero-depend asyncio memcached client, fork from aiomcache.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.9%
  • Shell 0.1%