{"id":13418519,"url":"https://github.com/douban/libmc","last_synced_at":"2025-05-14T19:09:48.142Z","repository":{"id":29747960,"uuid":"33291534","full_name":"douban/libmc","owner":"douban","description":"Fast and light-weight memcached client for C++ / #python / #golang #libmc","archived":false,"fork":false,"pushed_at":"2024-10-18T11:20:32.000Z","size":664,"stargazers_count":439,"open_issues_count":4,"forks_count":74,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-04-13T16:53:17.359Z","etag":null,"topics":["c-plus-plus","cache","caching","client-lib","golang","memcached","python"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/libmc/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/douban.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-02T05:45:00.000Z","updated_at":"2025-03-14T06:11:58.000Z","dependencies_parsed_at":"2023-11-29T07:29:28.423Z","dependency_job_id":"8e7da719-2c31-4d46-81b7-f0fef5895b5f","html_url":"https://github.com/douban/libmc","commit_stats":{"total_commits":264,"total_committers":21,"mean_commits":"12.571428571428571","dds":0.6893939393939394,"last_synced_commit":"d32820f07f01c04d6f8c1272248fa47cd131b14c"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Flibmc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Flibmc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Flibmc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douban%2Flibmc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/douban","download_url":"https://codeload.github.com/douban/libmc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"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":["c-plus-plus","cache","caching","client-lib","golang","memcached","python"],"created_at":"2024-07-30T22:01:03.244Z","updated_at":"2025-05-14T19:09:47.288Z","avatar_url":"https://github.com/douban.png","language":"C++","readme":"libmc\n=====\n\n|build_go| |build_py|\n|status| |pypiv| |pyversions| |wheel| |license|\n\nlibmc is a memcached client library for Python without any other\ndependencies at runtime. It's mainly written in C++ and Cython and\ncan be considered a drop in replacement for libmemcached and\n`python-libmemcached \u003chttps://github.com/douban/python-libmemcached\u003e`__.\n\nlibmc is developed and maintained by Douban Inc. Currently, it is\nworking in a production environment, powering all web traffic on\n`douban.com \u003chttps://douban.com/\u003e`__\n(`english wiki \u003chttps://en.wikipedia.org/wiki/Douban\u003e`__).\n\nBuild and Installation\n----------------------\n\nFor users:\n\n::\n\n    pip install libmc\n\nUsage:\n\n.. code:: python\n\n    import libmc\n\n    mc = libmc.Client(['localhost:11211', 'localhost:11212'])\n    mc.set('foo', 'bar')\n    assert mc.get('foo') == 'bar'\n\nUnder the hood\n--------------\n\nUnder the hood, libmc consists of 2 parts: an internal, fully-functional\nmemcached client implementation in C++ and a Cython wrapper around that\nimplementation. Dynamic memory allocation and memory-copy are slow, so\nwe've tried our best to avoid them. libmc also supports the ``set_multi``\ncommand, which is not natively supported by the `memcached\nprotocol \u003chttps://github.com/memcached/memcached/blob/master/doc/protocol.txt\u003e`__.\nSome techniques have been applied to make ``set_multi`` command extremely fast\nin libmc (compared to similiar libraries).\n\nConfiguration\n-------------\n\n.. code:: python\n\n    import libmc\n    from libmc import (\n        MC_HASH_MD5, MC_POLL_TIMEOUT, MC_CONNECT_TIMEOUT, MC_RETRY_TIMEOUT\n    )\n\n    mc = libmc.Client(\n        [\n        'localhost:11211',\n        'localhost:11212',\n        'remote_host',\n        'remote_host mc.mike',\n        'remote_host:11213 mc.oscar'\n        ],\n        do_split=True,\n        comp_threshold=0,\n        noreply=False,\n        prefix=None,\n        hash_fn=MC_HASH_MD5,\n        failover=False\n    )\n\n    mc.config(MC_POLL_TIMEOUT, 100)  # 100 ms\n    mc.config(MC_CONNECT_TIMEOUT, 300)  # 300 ms\n    mc.config(MC_RETRY_TIMEOUT, 5)  # 5 s\n\n\n-  ``servers``: a list of memcached server addresses. Each address\n   should be formated as ``hostname[:port] [alias]``, where ``port`` and\n   ``alias`` are optional. If ``port`` is not given, the default port ``11211``\n   will be used. If given, ``alias`` will be used to compute the server hash,\n   which would otherwise be computed based on ``host`` and ``port``\n   (i.e. whichever portion is given).\n-  ``do_split``: splits large values (up to 10MB) into chunks (\u003c1MB). The\n   memcached server implementation will not store items larger than 1MB,\n   however in some environments it is beneficial to shard up to 10MB of data.\n   Attempts to store more than that are ignored. Default: ``True``.\n-  ``comp_threshold``: compresses large values using zlib. If\n   ``buffer length \u003e comp_threshold \u003e 0`` (in bytes), the buffer will be\n   compressed. If ``comp_threshold == 0``, the string buffer will never be\n   compressed. Default: ``0``\n-  ``noreply``: controls memcached's\n   ``noreply`` `feature \u003chttps://github.com/memcached/memcached/wiki/CommonFeatures#noreplyquiet\u003e`__.\n   Default: ``False``\n-  ``prefix``: The key prefix. default: ``''``\n-  ``hash_fn``: hashing function for keys. possible values:\n\n   -  ``MC_HASH_MD5``\n   -  ``MC_HASH_FNV1_32``\n   -  ``MC_HASH_FNV1A_32``\n   -  ``MC_HASH_CRC_32``\n\n   default: ``MC_HASH_MD5``\n\n   **NOTE:** fnv1\\_32, fnv1a\\_32, crc\\_32 implementations in libmc are\n   per each spec, but they're not compatible with corresponding\n   implementions in libmemcached.\n\n-  ``failover``: Whether to failover to next server when current server\n   is not available. Default: ``False``\n\n-  ``MC_POLL_TIMEOUT`` Timeout parameter used during set/get procedure.\n   Default: ``300`` ms\n-  ``MC_CONNECT_TIMEOUT`` Timeout parameter used when connecting to\n   memcached server in the initial phase. Default: ``100`` ms\n-  ``MC_RETRY_TIMEOUT`` When a server is not available due to server-end\n   error, libmc will try to establish the broken connection in every\n   ``MC_RETRY_TIMEOUT`` s until the connection is back to live. Default:\n   ``5`` s\n\n**NOTE:** The hashing algorithm for host mapping on continuum is always\nmd5.\n\nContributing to libmc\n---------------------\n\nFeel free to send a **Pull Request**. For feature requests or any\nquestions, please open an **Issue**.\n\nFor **SECURITY DISCLOSURE**, please disclose the information responsibly\nby sending an email to security@douban.com directly instead of creating\na GitHub issue.\n\nFAQ\n---\n\nDoes libmc support PHP?\n^^^^^^^^^^^^^^^^^^^^^^^\n\nNo, but, if you like, you can write a wrapper for PHP based on the C++\nimplementation.\n\nIs Memcached binary protocol supported ?\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nNo. Only Memcached ASCII protocol is supported currently.\n\nWhy reinventing the wheel?\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBefore libmc, we were using\n`python-libmemcached \u003chttps://github.com/douban/python-libmemcached\u003e`__,\nwhich is a python extention for\n`libmemcached \u003chttp://libmemcached.org/libMemcached.html\u003e`__.\nlibmemcached is quite weird and buggy. After nearly one decade, there're\nstill some unsolved bugs.\n\nIs libmc thread-safe ?\n^^^^^^^^^^^^^^^^^^^^^^\n\nYes. ``libmc.ThreadedClient`` is a thread-safe client implementation. To hold\naccess for more than one request, ``libmc.ClientPool`` can be used with Python\n``with`` statements. ``libmc.Client``, however, is a single-threaded memcached\nclient. If you initialize a standard client in one thread but reuse that in\nanother thread, a Python ``ThreadUnsafe`` Exception will be raised.\n\nIs libmc compatible with gevent?\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYes, with the help of `greenify \u003chttps://github.com/douban/greenify\u003e`__,\nlibmc is friendly to gevent. Read ``tests/shabby/gevent_issue.py`` for\ndetails. ``libmc.ThreadedClient`` and ``libmc.ClientPool`` are not compatible.\n[#]_\n\n**Notice:**\n\n``gevent.monkey.patch_all()`` will override\n``threading.current_thread().ident`` to Greenlet's ID,\nthis will cause libmc to throw a ThreadUnSafe error\nor run into dead lock, you should only patch the things\nthat you need, e.g.\n\n.. code:: python\n\n    from gevent import monkey\n    monkey.patch_socket()\n\nAcknowledgments\n---------------\n\n-  Thanks to `@fahrenheit2539 \u003chttps://github.com/fahrenheit2539\u003e`__ and\n   the llvm project for the standalone.\n   `SmallVector \u003chttp://fahrenheit2539.blogspot.com/2012/06/introduction-in-depths-look-at.html\u003e`__\n   implementation.\n-  Thanks to `@miloyip \u003chttps://github.com/miloyip\u003e`__ for the high\n   performance `i64toa \u003chttps://github.com/miloyip/itoa-benchmark\u003e`__\n   implementation.\n-  Thanks to `Ivan Novikov \u003chttps://twitter.com/d0znpp\u003e`__ for the\n   research in `THE NEW PAGE OF INJECTIONS BOOK: MEMCACHED\n   INJECTIONS \u003chttps://www.blackhat.com/us-14/briefings.html#the-new-page-of-injections-book-memcached-injections\u003e`__.\n-  Thanks to the PolarSSL project for the md5 implementation.\n-  Thanks to `@lericson \u003chttps://github.com/lericson\u003e`__ for the `benchmark\n   script in\n   pylibmc \u003chttps://github.com/lericson/pylibmc/blob/master/bin/runbench.py\u003e`__.\n-  Thanks to the libmemcached project and some other projects possibly\n   not mentioned here.\n\nContributors\n------------\n\n-  `@mckelvin \u003chttps://github.com/mckelvin\u003e`__\n-  `@zzl0 \u003chttps://github.com/zzl0\u003e`__\n-  `@windreamer \u003chttps://github.com/windreamer\u003e`__\n-  `@lembacon \u003chttps://github.com/lembacon\u003e`__\n-  `@seansay \u003chttps://github.com/seansay\u003e`__\n-  `@mosasiru \u003chttps://github.com/mosasiru\u003e`__\n-  `@jumpeiMano \u003chttps://github.com/jumpeiMano\u003e`__\n\n\nWho is using\n------------\n\n- `豆瓣 \u003chttps://douban.com\u003e`__\n- `下厨房 \u003chttps://www.xiachufang.com\u003e`__\n- `Some other projects on GitHub \u003chttps://github.com/douban/libmc/network/dependents\u003e`__\n- Want to add your company/organization name here?\n  Please feel free to send a PR!\n\nDocumentation\n-------------\n\nhttps://github.com/douban/libmc/wiki\n\nFootnotes\n---------\n\n.. [#] In order to use a single executable for multiple greenlet contexts,\n   gevent has to `copy thread memory\n   \u003chttps://github.com/python-greenlet/greenlet/blob/937f150e07823ee03344aeeb5111c0bb371a831d/src/greenlet/greenlet.cpp#L105\u003e`__\n   to and from the same stack space. This doesn't affect Python references,\n   which are handed off through gevent, but makes it impossible for shared\n   libraries to pass memory addresses across greenlets, which is required for\n   the worker pool.\n\n\nLICENSE\n-------\n\nCopyright (c) 2014-2020, Douban Inc. All rights reserved.\n\nLicensed under a BSD license:\nhttps://github.com/douban/libmc/blob/master/LICENSE.txt\n\n.. |build_go| image:: https://github.com/douban/libmc/actions/workflows/golang.yml/badge.svg\n   :target: https://github.com/douban/libmc/actions/workflows/golang.yml\n\n.. |build_py| image:: https://github.com/douban/libmc/actions/workflows/python.yml/badge.svg\n   :target: https://github.com/douban/libmc/actions/workflows/python.yml\n\n.. |pypiv| image:: https://img.shields.io/pypi/v/libmc\n   :target: https://pypi.org/project/libmc/\n\n.. |status| image:: https://img.shields.io/pypi/status/libmc\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/libmc\n.. |wheel| image:: https://img.shields.io/pypi/wheel/libmc\n.. |license| image:: https://img.shields.io/pypi/l/libmc?color=blue\n","funding_links":[],"categories":["TODO scan for Android support in followings","C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouban%2Flibmc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdouban%2Flibmc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouban%2Flibmc/lists"}