{"id":13837188,"url":"https://github.com/stephenmcd/hot-redis","last_synced_at":"2025-04-04T14:04:25.336Z","repository":{"id":11341690,"uuid":"13769660","full_name":"stephenmcd/hot-redis","owner":"stephenmcd","description":"Rich Python data types for Redis","archived":false,"fork":false,"pushed_at":"2024-04-03T17:50:55.000Z","size":185,"stargazers_count":290,"open_issues_count":9,"forks_count":33,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-28T13:08:19.599Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stephenmcd.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-22T10:15:34.000Z","updated_at":"2025-01-19T12:20:36.000Z","dependencies_parsed_at":"2024-06-19T11:16:24.466Z","dependency_job_id":"e3f95a67-9c99-4076-8855-d289b032a780","html_url":"https://github.com/stephenmcd/hot-redis","commit_stats":{"total_commits":155,"total_committers":6,"mean_commits":"25.833333333333332","dds":0.038709677419354827,"last_synced_commit":"6b0cf260c775fd98c44b6703030d33004dabf67d"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmcd%2Fhot-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmcd%2Fhot-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmcd%2Fhot-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmcd%2Fhot-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephenmcd","download_url":"https://codeload.github.com/stephenmcd/hot-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190246,"owners_count":20898702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T15:01:02.956Z","updated_at":"2025-04-04T14:04:25.308Z","avatar_url":"https://github.com/stephenmcd.png","language":"Python","funding_links":[],"categories":["ORM","资源列表","Python","ORM [🔝](#readme)","Awesome Python","Web Frameworks \u0026 RESTful API"],"sub_categories":["ORM"],"readme":".. image:: https://secure.travis-ci.org/stephenmcd/hot-redis.png?branch=master\n   :target: http://travis-ci.org/stephenmcd/hot-redis\n\nCreated by `Stephen McDonald \u003chttp://twitter.com/stephen_mcd\u003e`_\n\nIntroduction\n============\n\nHOT Redis is a wrapper library for the `redis-py`_ client. Rather than\ncalling the `Redis`_ commands directly from a client library, HOT Redis\nprovides a wide range of data types that mimic many of the built-in\ndata types provided by Python, such as lists, dicts, sets, and more, as\nwell as many of the classes found throughout the standard library, such\nas those found in the Queue, threading, and collections modules.\n\nThese types are then backed by Redis, allowing objects to be\nmanipulated atomically over the network - the atomic nature of the\nmethods implemented on objects in HOT Redis is one of its core\nfeatures, and many of these are backed by `Lua`_ code executed within\nRedis, which ensures atomic operations where applicable.\n\nThe name HOT Redis originally stood for \"Higher Order Types for Redis\",\nbut since the implementation doesn't strictly fit the definition, the\nrecursive acronym \"HOT Object Toolkit for Redis\" should appease the\nmost luscious of bearded necks.\n\nHOT Redis was drawn from the infrastructure behind the\n`Kouio RSS reader`_, a popular alternative to Google Reader.\n\n\nInstallation\n============\n\nThe easiest way to install ``hot-redis`` is directly\nfrom PyPi using `pip`_ by running the following command::\n\n    $ pip install -U hot-redis\n\nOtherwise you can download and install it directly from source::\n\n    $ python setup.py install\n\n\nUsage\n=====\n\nEach of the types provided by HOT Redis strive to implement the same\nmethod signatures and return values as their Python built-in and\nstandard library counterparts. The main difference is each type's\n``__init__`` method. Every HOT Redis type's ``__init__`` method will\noptionally accept ``initial`` and ``key`` keyword arguments, which are\nused for defining an initial value to be stored in Redis for the\nobject, and the key that should be used, respectively. If no key is\nprovided, a key will be generated, which can then be accessed via the\n``key`` attribute::\n\n    \u003e\u003e\u003e from hot_redis import List\n    \u003e\u003e\u003e my_list = List()\n    \u003e\u003e\u003e my_list.key\n    '93366bdb-90b2-4226-a52a-556f678af40e'\n    \u003e\u003e\u003e my_list_with_key = List(key=\"foo\")\n    \u003e\u003e\u003e my_list_with_key.key\n    'foo'\n\nOnce you've determined a strategy for naming keys, you can then create\nHOT Redis objects and interact with them over the network, for example\nhere is a ``List`` created on a computer we'll refer to as computer A::\n\n    \u003e\u003e\u003e list_on_computer_a = List(key=\"foo\", initial=[\"a\", \"b\", \"c\"])\n\nthen on another computer we'll creatively refer to as computer B::\n\n    \u003e\u003e\u003e list_on_computer_b = List(key=\"foo\")\n    \u003e\u003e\u003e list_on_computer_b[:]  # Performs: LRANGE foo 0 -1\n    ['a', 'b', 'c']\n    \u003e\u003e\u003e list_on_computer_b += ['d', 'e', 'f']  # Performs: RPUSH foo d e f\n\nand back to computer A::\n\n    \u003e\u003e\u003e list_on_computer_a[:]  # Performs: LRANGE foo 0 -1\n    ['a', 'b', 'c', 'd', 'e', 'f']\n    \u003e\u003e\u003e 'c' in list_on_computer_a  # Works like Python lists where expected\n    True\n    \u003e\u003e\u003e list_on_computer_a.reverse()\n    \u003e\u003e\u003e list_on_computer_a[:]\n    ['f', 'e', 'd', 'c', 'b', 'a']\n\nThe last interaction here is an interesting one. Python's\n``list.reverse()`` is an in-place reversal of the list, that is, it\nmodifies the existing list, rather than returning a reversed copy. If\nwe were to implement this naively, we would first read the list from\nRedis, reverse it locally, then store the reversed list back in Redis\nagain. But what if another client were to modify the list at\napproximately the same time? One computer's modification to the list\nwould certainly overwrite the other's. In this scenario, and *many*\nothers, HOT Redis provides its own Lua routine specifically for\nreversing the list in-place, within Redis atomically. I wrote in more\ndetail about this in a blog post, `Bitwise Lua Operations in Redis`_.\n\n\nConfiguration\n=============\n\nBy default, HOT Redis attempts to connect to a Redis instance running\nlocally on the default port 6379. You can configure the default client\nby calling the ``hot_redis.configure`` function, prior to instantiating\nany HOT Redis objects. The arguments given to ``configure`` are passed\nonto the underlying `redis-py`_ client::\n\n    \u003e\u003e\u003e from hot_redis import configure\n    configure(host='myremotehost', port=6380)\n\nAlternatively, if you wish to use a different client per object, you\ncan explicitly create a ``HotClient`` instance, and pass it to each\nobject::\n\n    \u003e\u003e\u003e from hot_redis import HotClient, Queue\n    \u003e\u003e\u003e client = HotClient(host=\"myremotehost\", port=6380)\n    \u003e\u003e\u003e my_queue = Queue(client=client)\n\n\nTransactions\n============\n\nBasic support for thread-safe transactions are provided using the\nRedis ``MULTI`` and ``EXEC`` commands::\n\n    \u003e\u003e\u003e from hot_redis import List, Queue, transaction\n    \u003e\u003e\u003e my_list = List(key=\"foo\")\n    \u003e\u003e\u003e my_queue = Queue(key=\"bar\")\n    \u003e\u003e\u003e with transaction():\n    ...     for i in range(20):\n    ...         my_list.append(i)\n    ...         my_queue.put(i)\n\nIn the above example, all of the ``append`` and ``put`` calls are\nbatched together into a single transaction, that is executed once the\n``transaction()`` context is exited.\n\n\nData Types\n==========\n\nThe following table is the complete list of types provided by HOT\nRedis, mapped to their Python counterparts and underlying Redis types,\nalong with any special considerations worth noting.\n\n==================  ============================  ==========  ===============\nHOT Redis           Python                        Redis       Notes\n==================  ============================  ==========  ===============\nList                list                          list\nSet                 set                           set\nDict                dict                          hash\nString              string                        string      Mutable - string methods that normally create a new string object in Python will mutate the string stored in Redis\nImmutableString     string                        string      Immutable - behaves like a regular Python string\nInt                 int                           int\nFloat               float                         float\nQueue               Queue.Queue                   list\nLifoQueue           Queue.LifoQueue               list\nSetQueue            N/A                           list + set  Extension of ``Queue`` with unique members\nLifoSetQueue        N/A                           list + set  Extension of ``LifoQueue`` with unique members\nBoundedSemaphore    threading.BoundedSemaphore    list        Extension of ``Queue`` leveraging Redis' blocking list pop operations with timeouts, while using Queue's ``maxsize`` arg to provide BoundedSemaphore's ``value`` arg\nSemaphore           threading.Semaphore           list        Extension of ``BoundedSemaphore`` without a queue size\nLock                threading.Lock                list        Extension of ``BoundedSemaphore`` with a queue size of 1\nRLock               threading.RLock               list        Extension of ``Lock`` allowing multiple ``acquire`` calls\nDefaultDict         collections.DefaultDict       hash\nMultiSet            collections.Counter           hash\n==================  ============================  ==========  ===============\n\n.. _`redis-py`: https://github.com/andymccurdy/redis-py\n.. _`Redis`: http://redis.io\n.. _`Lua`: http://www.lua.org/\n.. _`Kouio RSS reader`: https://kouio.com\n.. _`pip`: http://www.pip-installer.org/\n.. _`Bitwise Lua Operations in Redis`: http://blog.jupo.org/2013/06/12/bitwise-lua-operations-in-redis/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenmcd%2Fhot-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephenmcd%2Fhot-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenmcd%2Fhot-redis/lists"}