Skip to main content

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

Project description

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 fafhrd91@gmail.com
Maintainer Rex Zhang rex.zhang@gmail.com
Contributions Andrew Svetlov andrew.svetlov@gmail.com

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

Coverage Report

python -m pytest --cov=. --cov-report html

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

AioMemcached-0.8.3.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

AioMemcached-0.8.3-py2.py3-none-any.whl (13.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file AioMemcached-0.8.3.tar.gz.

File metadata

  • Download URL: AioMemcached-0.8.3.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for AioMemcached-0.8.3.tar.gz
Algorithm Hash digest
SHA256 e79cfaf454a0dbd7f4d73f350506d71e0dbc57bcf2cb2becd14c4c4277bbab93
MD5 85a8bf998a045bd3d817480be58d7d53
BLAKE2b-256 617d574f2bbdca034517fde3966dec9cc93aa0727e26bb0951e63ab06c5ff931

See more details on using hashes here.

File details

Details for the file AioMemcached-0.8.3-py2.py3-none-any.whl.

File metadata

  • Download URL: AioMemcached-0.8.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for AioMemcached-0.8.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 effd4e1a5b774a50004c266bae5f97aa4abede9ada3271d3be429a9762246aa8
MD5 ffcf67a2caac302ad7eebbbd77963f49
BLAKE2b-256 895ce3df531c7adbf0d13831b80d5209ff70f79fbf4faae981de2a044ecd784a

See more details on using hashes here.

Supported by

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