{"id":21076049,"url":"https://github.com/loggi/python-multimapwithttl","last_synced_at":"2025-07-24T15:14:30.959Z","repository":{"id":57457280,"uuid":"427163482","full_name":"loggi/python-multimapwithttl","owner":"loggi","description":"An implementation of multimap with per-item expiration backed up by Redis.","archived":false,"fork":false,"pushed_at":"2021-11-12T04:03:10.000Z","size":377,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-02-22T03:33:28.194Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loggi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-11T22:40:51.000Z","updated_at":"2022-01-17T14:56:57.000Z","dependencies_parsed_at":"2022-09-05T17:52:10.228Z","dependency_job_id":null,"html_url":"https://github.com/loggi/python-multimapwithttl","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loggi%2Fpython-multimapwithttl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loggi%2Fpython-multimapwithttl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loggi%2Fpython-multimapwithttl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loggi%2Fpython-multimapwithttl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loggi","download_url":"https://codeload.github.com/loggi/python-multimapwithttl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243521215,"owners_count":20304183,"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-11-19T19:26:15.229Z","updated_at":"2025-03-14T03:43:01.838Z","avatar_url":"https://github.com/loggi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MultiMapWithTTL\n\n\n[![pypi](https://img.shields.io/pypi/v/python-multimapwithttl.svg)](https://pypi.org/project/python-multimapwithttl/)\n[![python](https://img.shields.io/pypi/pyversions/python-multimapwithttl.svg)](https://pypi.org/project/python-multimapwithttl/)\n[![Build Status](https://github.com/loggi/python-multimapwithttl/actions/workflows/dev.yml/badge.svg)](https://github.com/loggi/python-multimapwithttl/actions/workflows/dev.yml)\n[![codecov](https://codecov.io/gh/loggi/python-multimapwithttl/branch/main/graphs/badge.svg)](https://codecov.io/github/loggi/python-multimapwithttl)\n\n\n\nAn implementation of multimap with per-item expiration backed up by Redis.\n\n\n* Documentation: \u003chttps://loggi.github.io/python-multimapwithttl\u003e\n* GitHub: \u003chttps://github.com/loggi/python-multimapwithttl\u003e\n* PyPI: \u003chttps://pypi.org/project/python-multimapwithttl/\u003e\n* Free software: MIT\n\n\n## Description\n\nThis lib is based on: https://quickleft.com/blog/how-to-create-and-expire-list-items-in-redis/\nwithout the need for an extra job to delete old items.\n\nValues are internally stored on Redis using Sorted Sets :\n\n    key1: { (score1, value1), (score2, value2), ... }\n    key2: { (score3, value3), (score4, value4), ... }\n    ...\n\nWhere the `score` is the timestamp when the value was added.\nWe use the timestamp to filter expired values and when an insertion happens,\nwe opportunistically garbage collect expired values.\n\nThe key itself is set to expire through redis ttl mechanism together with the newest value.\nThese operations result in a simulated multimap with item expiration.\n\nYou can use to keep track of values associated to keys,\nwhen the value has a notion of expiration.\n\n```\n\u003e\u003e\u003e s = MultiMapWithTTL(redis_client, 'multimap')\n\u003e\u003e\u003e s.add('a', 1, 2, 3)\n\u003e\u003e\u003e sorted(s.get('a'))\n[1, 2, 3]\n\u003e\u003e\u003e s.add_many([('b', (4, 5, 6)), ('c', (7, 8, 9)), ])\n\u003e\u003e\u003e sorted(sorted(values) for values in s.get_many('a', 'b', 'c')))\n[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floggi%2Fpython-multimapwithttl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floggi%2Fpython-multimapwithttl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floggi%2Fpython-multimapwithttl/lists"}