naja-atra-redis-session


Namenaja-atra-redis-session JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryThis is the redis session implementation for the project [naja atra](https://github.com/naja-atra/naja-atra)
upload_time2024-04-11 12:28:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT License Copyright (c) 2018 Keijack Wu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords http-server websocket http web web-server
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Redis Sesion Implementation for Naja Atra

This is the redis session implementation for the project [naja atra](https://github.com/naja-atra/naja-atra)

## Usage

```python
import naja_atra
import naja_atra.server as server
import os
from naja_atra_redis_session.redis_session import RedisSessionFactory

def main(*args):
    # host, port, db, username, password are all optional.
    naja_atra.set_session_factory(RedisSessionFactory(host="10.0.2.16", port=6379, db=0, username="", password=""))
    server.scan("tests/ctrls", r'.*controllers.*')
    
    root = os.path.dirname(os.path.abspath(__file__))
    server.start(
        port=9090,
        resources={"/public/*": f"{root}/tests/static"})

```

or you can re-use your redis client which might be used in other codes.

```python
import naja_atra
import naja_atra.server as server
import os
import redis
from naja_atra_redis_session.redis_session import RedisSessionFactory

def main(*args):
    # This redis client can be used in other business codes.
    redis_client = redis.Redis(host="10.0.2.16", port=6379, db=0, username="", password="")
    naja_atra.set_session_factory(RedisSessionFactory(redis_client=redis_client))
    
    root = os.path.dirname(os.path.abspath(__file__))
    server.start(
        port=9090,
        resources={"/public/*": f"{root}/tests/static"})

```

## Write Your Own ObjectSerializer

Module `pickle` is used to do the serialization and deserialization, if the defalut serialization logic could not satisfy you, you can write your own

```python
naja_atra_redis_session.redis_session import ObjectSerializer

class MyObjectSerializer(ObjectSerializer):

    def object_to_bytes(self, obj: Any) -> bytes:
        bys = ...
        return bys

    def bytes_to_objects(self, value: bytes) -> Any:
        obj = ...
        return obj

# Set it when initializing a SessionFactory.

naja_atra.set_session_factory(RedisSessionFactory(host="10.0.2.16", port=6379, db=0, username="", password="", object_serializer=MyObjectSerializer()))
```



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "naja-atra-redis-session",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "http-server, websocket, http, web, web-server",
    "author": null,
    "author_email": "keijack <keijack.wu@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/17/12/a9203eda421bb11963a65fb22b1e973b77baf22c816fbadbe830469e25fc/naja-atra-redis-session-1.0.1.tar.gz",
    "platform": null,
    "description": "# Redis Sesion Implementation for Naja Atra\n\nThis is the redis session implementation for the project [naja atra](https://github.com/naja-atra/naja-atra)\n\n## Usage\n\n```python\nimport naja_atra\nimport naja_atra.server as server\nimport os\nfrom naja_atra_redis_session.redis_session import RedisSessionFactory\n\ndef main(*args):\n    # host, port, db, username, password are all optional.\n    naja_atra.set_session_factory(RedisSessionFactory(host=\"10.0.2.16\", port=6379, db=0, username=\"\", password=\"\"))\n    server.scan(\"tests/ctrls\", r'.*controllers.*')\n    \n    root = os.path.dirname(os.path.abspath(__file__))\n    server.start(\n        port=9090,\n        resources={\"/public/*\": f\"{root}/tests/static\"})\n\n```\n\nor you can re-use your redis client which might be used in other codes.\n\n```python\nimport naja_atra\nimport naja_atra.server as server\nimport os\nimport redis\nfrom naja_atra_redis_session.redis_session import RedisSessionFactory\n\ndef main(*args):\n    # This redis client can be used in other business codes.\n    redis_client = redis.Redis(host=\"10.0.2.16\", port=6379, db=0, username=\"\", password=\"\")\n    naja_atra.set_session_factory(RedisSessionFactory(redis_client=redis_client))\n    \n    root = os.path.dirname(os.path.abspath(__file__))\n    server.start(\n        port=9090,\n        resources={\"/public/*\": f\"{root}/tests/static\"})\n\n```\n\n## Write Your Own ObjectSerializer\n\nModule `pickle` is used to do the serialization and deserialization, if the defalut serialization logic could not satisfy you, you can write your own\n\n```python\nnaja_atra_redis_session.redis_session import ObjectSerializer\n\nclass MyObjectSerializer(ObjectSerializer):\n\n    def object_to_bytes(self, obj: Any) -> bytes:\n        bys = ...\n        return bys\n\n    def bytes_to_objects(self, value: bytes) -> Any:\n        obj = ...\n        return obj\n\n# Set it when initializing a SessionFactory.\n\nnaja_atra.set_session_factory(RedisSessionFactory(host=\"10.0.2.16\", port=6379, db=0, username=\"\", password=\"\", object_serializer=MyObjectSerializer()))\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2018 Keijack Wu  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "This is the redis session implementation for the project [naja atra](https://github.com/naja-atra/naja-atra)",
    "version": "1.0.1",
    "project_urls": {
        "homepage": "https://github.com/naja-atra/naja-atra-redis-session",
        "repository": "https://github.com/naja-atra/naja-atra-redis-session"
    },
    "split_keywords": [
        "http-server",
        " websocket",
        " http",
        " web",
        " web-server"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e4a78f55251200f539eb43ed6450b6dfae866b84075b7fc09c56f9dec5155ae",
                "md5": "702a538bd517b4af588c151b44739d7d",
                "sha256": "311de0ea4d1af952a47e9b85ad3bcd413f3245c787bee6ad939b728bb276268a"
            },
            "downloads": -1,
            "filename": "naja_atra_redis_session-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "702a538bd517b4af588c151b44739d7d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6468,
            "upload_time": "2024-04-11T12:28:48",
            "upload_time_iso_8601": "2024-04-11T12:28:48.532098Z",
            "url": "https://files.pythonhosted.org/packages/3e/4a/78f55251200f539eb43ed6450b6dfae866b84075b7fc09c56f9dec5155ae/naja_atra_redis_session-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1712a9203eda421bb11963a65fb22b1e973b77baf22c816fbadbe830469e25fc",
                "md5": "5a36016b6ab159a7d7bfca995a124660",
                "sha256": "a523b6bee3af57ed9a87ac16c2b83090d132929d1de5314dff314feb32b25514"
            },
            "downloads": -1,
            "filename": "naja-atra-redis-session-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5a36016b6ab159a7d7bfca995a124660",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4247,
            "upload_time": "2024-04-11T12:28:50",
            "upload_time_iso_8601": "2024-04-11T12:28:50.217155Z",
            "url": "https://files.pythonhosted.org/packages/17/12/a9203eda421bb11963a65fb22b1e973b77baf22c816fbadbe830469e25fc/naja-atra-redis-session-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-11 12:28:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "naja-atra",
    "github_project": "naja-atra-redis-session",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "naja-atra-redis-session"
}
        
Elapsed time: 0.24667s