{ "info": { "author": "Anish Gupta", "author_email": "nkanish2002@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "pyredis-cache\n=============\n\nPython Cache client for redis.\n\nSupports Python 3.5 and above.\n\nFeatures\n========\n\n- Automatically Sync data between the sync\\_func and cache\n- Use of Async/Await for Asynchronous execution of sync\\_func\n\nDependencies\n============\n\n- `redis-py `__\n- `hiredis-py `__\n\nInstallation\n============\n\n1. Through pip: ``pip install pyredis-cache``\n\n2. Manually: ``python setup.py install``. Install dependencies first\n\nGetting Started\n===============\n\n- Simple Redis Cache\n\n.. code:: py\n\n # Import redis Connection pool and CacheClient.\n from redis import ConnectionPool\n from redis_cache import CacheClient\n\n import json\n\n # Initialize the Connection pool.\n redis_pool = ConnectionPool()\n\n # Create a data synchronisation function\n # The first argument should define the uniqueness of the data\n def sync_func(student_id, lots_of_args):\n # fetch the data however you want to\n return data # Lets assume that the data returned is of type `dict` \n \n # Initialize the cache client\n cache = CacheClient(redis_pool, \"Student\", sync_func, set_func=json.dumps, get_func=json.loads, expire_time=10)\n # for persistent cache, assign 0 to expire_time (default)\n\n # This will set cache for ID: 12\n cache.set(12)\n\n # This will set cache for ID: 13, with custom data\n cache.set(13, data={\"name\":\"John Doe\", \"age\":16})\n\n # This will get cache for ID: 12 (no need to do a set, it will automatically set the data)\n cache.get(12)\n\n # The get function will pass extra arguments to the sync_func, same works with set.\n cache.get(14, age=15)\n\n # This will delete the cache for ID: 12\n cache.delete(12)\n\n- Caching into a single hash. I am still working on this to make a much\n more flexible caching mechanism\n\n.. code:: py\n\n # Import redis Connection pool and HashCacheClient.\n from redis import ConnectionPool\n from redis_cache import CacheClient\n\n import json\n\n # Initialize the Connection pool.\n redis_pool = ConnectionPool()\n\n # Create a data synchronisation function\n # The first argument should define the uniqueness of the data\n def sync_func(student_id, lots_of_args):\n # fetch the data however you want to\n return data # Lets assume that the data returned is of type `dict` \n \n # Initialize the cache client.\n hcache = HashCacheClient(redis_pool, \"Class\", \"Student\", sync_func, set_func=dumps, get_func=loads)\n # expire_time not supported.\n\n # This will set cache for ID: 12 for hash_id: 3\n hcache.set(3, 12)\n\n # This will get cache for ID: 12 for hash_id: 3 (no need to do a set, it will automatically set the data)\n hcache.get(3, 12)\n\n # This will delete the cache for ID: 12 for hash_id: 3\n hcache.delete(3, 12)\n\n # This will delete the hash with hash_id: 3\n hcache.delete_hash(3)\n\nTerminology\n===========\n\n- key: is the identifier for the cache object. eg. ``student`` (type\n string)\n- identity: is the index for a particular key. eg. Roll no. of a\n student ``12`` (type int)\n- sync\\_func: function which will give data tto be stores in cache.\n- set\\_func: data parsing function for setting data into cache. eg. if\n you want to set a dict value, you will have to set this as\n ``json.dumps``\n- get\\_func: data parsing function for getting data into cache. eg. if\n you want to set a dict value, you will have to set this as\n ``json.loads``\n- hash\\_key and hash\\_id: Unique identifiers for the hash. eg.\n hash\\_key can be ``grade12`` and hash\\_id can be ``2``\n\nKey and Identity are combined in a unique fashion to make the name\nagainst which the cache object will be stored. Similarly for hash\\_key\nand hash\\_id.\n\nAsync\n=====\n\nIf your function is Async i.e. makes use of ``async`` and ``await``\ncoroutines (`PEP 492 `__).\nYou will have to use event loop to run use this functionality like\nasyncio and tornado. You could do the following:-\n\n.. code:: py\n\n cache = CacheClient(redis_pool, \"Student\", sync_func, set_func=json.dumps, get_func=json.loads, expire_time=10, asynchronous=True)\n\n async def some_func():\n data = await cache.get(23)\n\nNote: the cache client is synchronous because redis servers are quite\nfast. You can expect near 0 latency with the correct setup. Also the\ncreator of tornado-redis suggests this kind if architecture to reduce\nthe cost overhead caused by setting up callbacks. (see post:\nhttp://stackoverflow.com/a/15596969/2248966)\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nkanish2002/pyredis-cache", "keywords": "redis cache client asyncio tornado", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pyredis-cache", "package_url": "https://pypi.org/project/pyredis-cache/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pyredis-cache/", "project_urls": { "Homepage": "https://github.com/nkanish2002/pyredis-cache" }, "release_url": "https://pypi.org/project/pyredis-cache/0.1.3/", "requires_dist": null, "requires_python": "", "summary": "Cache client for redis", "version": "0.1.3" }, "last_serial": 2159070, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "b77e31662f5df4acdad6551b6b90b575", "sha256": "2e77b75da52facbdd61ca03c1af0cbab6270cc5d730321fcec722f6299aa539a" }, "downloads": -1, "filename": "pyredis-cache-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b77e31662f5df4acdad6551b6b90b575", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2953, "upload_time": "2016-06-09T13:13:49", "url": "https://files.pythonhosted.org/packages/1a/f4/67f0b83497c7aee788d3da7c4a32068cbc9ab9acdc5d130410651e3dfdb6/pyredis-cache-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "63d413f38ddae50751901aaffa1a6787", "sha256": "165ccf487b0c2b2b1b9b966157e7d2bfc5b6eda79f020f932e1383498e585b48" }, "downloads": -1, "filename": "pyredis-cache-0.1.3.tar.gz", "has_sig": false, "md5_digest": "63d413f38ddae50751901aaffa1a6787", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4530, "upload_time": "2016-06-09T17:40:56", "url": "https://files.pythonhosted.org/packages/84/d3/f0ff0a8ec30643776b1ddb5553ff30755c6fd12c71c53f691be5100485b7/pyredis-cache-0.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "63d413f38ddae50751901aaffa1a6787", "sha256": "165ccf487b0c2b2b1b9b966157e7d2bfc5b6eda79f020f932e1383498e585b48" }, "downloads": -1, "filename": "pyredis-cache-0.1.3.tar.gz", "has_sig": false, "md5_digest": "63d413f38ddae50751901aaffa1a6787", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4530, "upload_time": "2016-06-09T17:40:56", "url": "https://files.pythonhosted.org/packages/84/d3/f0ff0a8ec30643776b1ddb5553ff30755c6fd12c71c53f691be5100485b7/pyredis-cache-0.1.3.tar.gz" } ] }