aioredisorm


Nameaioredisorm JSON
Version 0.1.3 PyPI version JSON
download
home_page
SummaryA Python class for interacting with Redis using asyncio and aioredis.
upload_time2023-06-29 06:41:44
maintainer
docs_urlNone
authorfadedreams7
requires_python>=3.8,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## AIORedisORM

A Python class for interacting with Redis using asyncio and aioredis.

### Installation

You can install AIORedisORM using pip:

```
pip install aioredisorm
```

### Example Usage

Here is an example that demonstrates the usage of the AIORedisORM class:

```python
import asyncio
from aioredisorm import AIORedisORM

async def main():
    # Add prefix to beging of each key
    redis_client = AIORedisORM(key_prefix='my_prefix')
    await redis_client.connect()

    # Set a value
    await redis_client.set_value('my_key', 'my_value', ex=12)

    # Get a value
    result = await redis_client.get_value('my_key')
    print(result)  # Output: b'my_value'

    # Set a hash
    await redis_client.set_hash('my_hash', {'key1': 'value1', 'key2': 'value2', 'key3': 13})

    # Set a hash with expiration
    await redis_client.set_hash('my_hash', {'key1': 'value1', 'key2': 'value2', 'key3': 13}, ex=5)

    # Get a hash
    hash_result = await redis_client.get_hash('my_hash')
    print(hash_result)  # Output: {b'key1': b'value1', b'key2': b'value2', b'key3': b'123'}

    await asyncio.sleep(5)  # Wait for the expiration to pass

    hash_result = await redis_client.get_hash('my_hash')
    print(hash_result)  # Output: {}

    # Decode the bytes to a string if needed
    result = result.decode('utf-8')
    print(result)  # Output: 'my_value'

    # Set a set
    await redis_client.set_set('my_set', 'value1', 'value2', 'value3')

    # Get a set
    set_result = await redis_client.get_set('my_set')
    print("set_result", set_result)  # Output: {b'value1', b'value2', b'value3'}

    # Transaction example
    commands = [
        ('set', 'key1', 'value1'),
        ('set', 'key2', 'value2')
    ]
    results = await redis_client.execute_transaction(commands)
    print(results)  # Output: [(True, True)]

    # Set a list
    await redis_client.set_list('my_list', 'value1', 'value2', 'value3')

    # Get a list
    list_result = await redis_client.get_list('my_list')
    print(list_result)  # Output: [b'value1', b'value2', b'value3']

    # Get the expiration time of a key
    ttl, pttl = await redis_client.get_key_expiration('key1')
    print(f"TTL of 'my_key': {ttl} seconds")
    print(f"PTTL of 'my_key': {pttl} milliseconds")

    # Close the connection
    await redis_client.close()

# Run the async example
asyncio.run(main())
```

Make sure to import the AIORedisORM class and replace 'my_prefix' with your desired key prefix.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "aioredisorm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "fadedreams7",
    "author_email": "fadedreams7@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/95/fa/2bfcba5ff45b0ab2c81f875025532910331755fbd3af80d990d3f049bc55/aioredisorm-0.1.3.tar.gz",
    "platform": null,
    "description": "## AIORedisORM\n\nA Python class for interacting with Redis using asyncio and aioredis.\n\n### Installation\n\nYou can install AIORedisORM using pip:\n\n```\npip install aioredisorm\n```\n\n### Example Usage\n\nHere is an example that demonstrates the usage of the AIORedisORM class:\n\n```python\nimport asyncio\nfrom aioredisorm import AIORedisORM\n\nasync def main():\n    # Add prefix to beging of each key\n    redis_client = AIORedisORM(key_prefix='my_prefix')\n    await redis_client.connect()\n\n    # Set a value\n    await redis_client.set_value('my_key', 'my_value', ex=12)\n\n    # Get a value\n    result = await redis_client.get_value('my_key')\n    print(result)  # Output: b'my_value'\n\n    # Set a hash\n    await redis_client.set_hash('my_hash', {'key1': 'value1', 'key2': 'value2', 'key3': 13})\n\n    # Set a hash with expiration\n    await redis_client.set_hash('my_hash', {'key1': 'value1', 'key2': 'value2', 'key3': 13}, ex=5)\n\n    # Get a hash\n    hash_result = await redis_client.get_hash('my_hash')\n    print(hash_result)  # Output: {b'key1': b'value1', b'key2': b'value2', b'key3': b'123'}\n\n    await asyncio.sleep(5)  # Wait for the expiration to pass\n\n    hash_result = await redis_client.get_hash('my_hash')\n    print(hash_result)  # Output: {}\n\n    # Decode the bytes to a string if needed\n    result = result.decode('utf-8')\n    print(result)  # Output: 'my_value'\n\n    # Set a set\n    await redis_client.set_set('my_set', 'value1', 'value2', 'value3')\n\n    # Get a set\n    set_result = await redis_client.get_set('my_set')\n    print(\"set_result\", set_result)  # Output: {b'value1', b'value2', b'value3'}\n\n    # Transaction example\n    commands = [\n        ('set', 'key1', 'value1'),\n        ('set', 'key2', 'value2')\n    ]\n    results = await redis_client.execute_transaction(commands)\n    print(results)  # Output: [(True, True)]\n\n    # Set a list\n    await redis_client.set_list('my_list', 'value1', 'value2', 'value3')\n\n    # Get a list\n    list_result = await redis_client.get_list('my_list')\n    print(list_result)  # Output: [b'value1', b'value2', b'value3']\n\n    # Get the expiration time of a key\n    ttl, pttl = await redis_client.get_key_expiration('key1')\n    print(f\"TTL of 'my_key': {ttl} seconds\")\n    print(f\"PTTL of 'my_key': {pttl} milliseconds\")\n\n    # Close the connection\n    await redis_client.close()\n\n# Run the async example\nasyncio.run(main())\n```\n\nMake sure to import the AIORedisORM class and replace 'my_prefix' with your desired key prefix.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Python class for interacting with Redis using asyncio and aioredis.",
    "version": "0.1.3",
    "project_urls": {
        "repository": "https://github.com/fadedreams/aioredisorm"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8efba0c157a93b8c4bf42e79cf03ce80de4bbc0076494a1ae945a928ee6d5887",
                "md5": "5683a5030bd79a597d2dcea1258ee1ae",
                "sha256": "5903e8ea68fbda813f0ab0ec9abd6028c22481989901f039375b3548e9a49837"
            },
            "downloads": -1,
            "filename": "aioredisorm-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5683a5030bd79a597d2dcea1258ee1ae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 4140,
            "upload_time": "2023-06-29T06:41:43",
            "upload_time_iso_8601": "2023-06-29T06:41:43.690931Z",
            "url": "https://files.pythonhosted.org/packages/8e/fb/a0c157a93b8c4bf42e79cf03ce80de4bbc0076494a1ae945a928ee6d5887/aioredisorm-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "95fa2bfcba5ff45b0ab2c81f875025532910331755fbd3af80d990d3f049bc55",
                "md5": "a6c9cac8fb84a157e08f5c9848fc589e",
                "sha256": "720dde55158995e737f58689f0f90cc8dbabe2bf7bc6c00555279623824e4005"
            },
            "downloads": -1,
            "filename": "aioredisorm-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "a6c9cac8fb84a157e08f5c9848fc589e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 3793,
            "upload_time": "2023-06-29T06:41:44",
            "upload_time_iso_8601": "2023-06-29T06:41:44.978707Z",
            "url": "https://files.pythonhosted.org/packages/95/fa/2bfcba5ff45b0ab2c81f875025532910331755fbd3af80d990d3f049bc55/aioredisorm-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-29 06:41:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fadedreams",
    "github_project": "aioredisorm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "aioredisorm"
}
        
Elapsed time: 1.61070s