Skip to main content

aiossdb is a library for accessing a ssdb database from the asyncio

Project description

# aiossdb
aiossdb is a library for accessing an ssdb database from AsyncIO

[![Coverage Status](https://coveralls.io/repos/github/Microndgt/aiossdb/badge.svg?branch=master)](https://coveralls.io/github/Microndgt/aiossdb?branch=master)
![https://travis-ci.org/Microndgt/aiossdb.svg?branch=master](https://travis-ci.org/Microndgt/aiossdb.svg?branch=master)

Requirements
------------

- Python 3.6+

DONE and TODO
-------------

- [x] base async ssdb connection
- [x] async ssdb parser
- [x] async ssdb connection pool
- [x] easy using ssdb async client
- [x] tests
- [ ] detailed docs
- [ ] suppress ReplyError as a choice
- [ ] releasing...
- [ ] and more...

Quick Start
-----------

- Client

Client will create a connection pool, each time you execute the command will be from the available connection pool to get the connection, and then execute the command, and then release
Client会创建一个连接池,在每次执行命令的时候都会去从可用连接池中拿到连接,然后执行命令,然后释放

```
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)


async def just_look():
c = Client(loop=loop)
await c.set('a', 1)
res = await c.get('a')
print(res)
await c.close()
return res

loop.run_until_complete(just_look())
loop.close()
```

- ConnectionPool

```
import asyncio
from aiossdb import create_pool

loop = asyncio.get_event_loop()


async def connect_tcp():
pool = await create_pool(('localhost', 8888), loop=loop, minsize=5, maxsize=10)

# Use the direct implementation of the command pool
# 使用pool直接执行命令
await pool.execute('set', 'a', 2)
val = await pool.execute('hget', 'hash_name', 'hash_key')
print(val)

# Use the pool to get the connection
# 使用pool获取连接
conn, addr = await pool.get_connection()
await conn.execute('set', 'a', 2)
val = await conn.execute('hget', 'hash_name', 'hash_key')
print(val)

# Get the final connection to be released
# 获取的连接最后一定要release
await pool.release(conn)

pool.close()
await pool.wait_closed()

loop.run_until_complete(connect_tcp())
loop.close()
```

If you request a non-existent key, a `ReplyError` will be raised and the type of error may be: `not_found`, `error`, `fail`, `client_error`
如果获取不存在的键等情况会引发`ReplyError`, 错误类型可能有: `not_found`, `error`, `fail`, `client_error`

```
try:
val = await conn.execute('hget', 'hash_name', 'hash_key')
except ReplyError as e:
print("Error type: {}".format(e.etype))
print("Executed command: {}".format(e.command))
```

- Connection

```
import asyncio
from aiossdb import create_connection, ReplyError


loop = asyncio.get_event_loop()


async def connect_tcp():
conn = await create_connection(('localhost', 8888), loop=loop)
await conn.execute('set', 'a', 2)
val = await conn.execute('hget', 'hash_name', 'hash_key')
print(val)

conn.close()
await conn.wait_closed()

loop.run_until_complete(connect_tcp())
loop.close()
```

Exceptions
----------

- SSDBError
- ConnectionClosedError
- ReplyError
- ProtocolError
- PoolClosedError

NOTES
-----

- The preliminary test shows that `aiossdb` is 25 times fast than [pyssdb](https://github.com/ifduyue/pyssdb)

Contributor
===========

Kevin Du
--------

- Email: `dgt_x@foxmail.com`
- Site: `http://skyrover.me`

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

aiossdb-0.0.5.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

aiossdb-0.0.5-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file aiossdb-0.0.5.tar.gz.

File metadata

  • Download URL: aiossdb-0.0.5.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiossdb-0.0.5.tar.gz
Algorithm Hash digest
SHA256 c01ca10729e8f7e5fa9fe783f7262e7bf8fa7a32451a47bc545949c4e4124bdb
MD5 44581545cbcb9099789d9cab1bc607f1
BLAKE2b-256 cb5b3ea09f0232397559c86cba54848c1b763b74d878afdeed324197d3ef946f

See more details on using hashes here.

File details

Details for the file aiossdb-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for aiossdb-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3bf00a6059ee318f2ac2c8b5d3d2a6cc5e67d99fff74fe7143dd54e2de74f7ee
MD5 4436fce318a5fc20543a69039898e379
BLAKE2b-256 03ee850be94f4bde02ed7fe637a337c35c691ecf34bc1e6eff7fc87b29d9fbc3

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