nameko-pymemcache


Namenameko-pymemcache JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/andreasmyleus/nameko-pymemcache/
SummaryMemcached dependency for nameko services with consistent hashing
upload_time2025-09-16 14:38:12
maintainerNone
docs_urlNone
authorandreasmyleus
requires_python>=3.8
licenseApache License, Version 2.0
keywords nameko memcached cache distributed consistent-hashing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # nameko-pymemcache
[![PyPI version](https://badge.fury.io/py/nameko-pymemcache.svg)](https://badge.fury.io/py/nameko-pymemcache)
[![Tests](https://github.com/andreasmyleus/nameko-pymemcache/actions/workflows/test.yml/badge.svg)](https://github.com/andreasmyleus/nameko-pymemcache/actions/workflows/test.yml)
[![Python](https://img.shields.io/pypi/pyversions/nameko-pymemcache.svg)](https://pypi.org/project/nameko-pymemcache/)

Memcached dependency for nameko services with consistent hashing support for multi-node setups. Uses the high-performance pymemcache library with automatic failover and connection pooling.

**Key Features:**
- **Consistent hashing** for reliable multi-node memcached clusters  
- **Optimized for Nameko** - proper connection management and worker cleanup
- **Automatic failover** when nodes become unavailable
- **Drop-in replacement** for bmemcached with better multi-node behavior
- **High performance** - uses pymemcache's efficient C implementation

Inspiration and structure **proudly** stolen from nameko-redis :) Thanks guys!

## Installation
```
pip install nameko-pymemcache
```

## Usage
```python
from nameko.rpc import rpc
from nameko_pymemcache import Memcached


class MyService(object):
    name = "my_service"

    memcached = Memcached()

    @rpc
    def hello(self, name):
        self.memcached.set("foo", name)
        return "Hello, {}!".format(name)

    @rpc
    def bye(self):
        name = self.memcached.get("foo")
        return "Bye, {}!".format(name)
```

To specify memcached uri(s) and optional username/password you will need a config
```yaml
AMQP_URI: 'amqp://guest:guest@localhost'
MEMCACHED_URIS: ['127.0.0.1:11211', ]
MEMCACHED_USER: 'playerone'
MEMCACHED_PASSWORD: 'ready'
```

## Multi-Node Configuration

For multi-node memcached clusters, specify multiple servers using either format:

**YAML list format:**
```yaml
AMQP_URI: 'amqp://guest:guest@localhost'
MEMCACHED_URIS: 
  - '192.168.1.10:11211'
  - '192.168.1.11:11211'
  - '192.168.1.12:11211'
```

**Bracketed list format:**
```yaml
AMQP_URI: 'amqp://guest:guest@localhost'
MEMCACHED_URIS: ['192.168.1.10:11211', '192.168.1.11:11211', '192.168.1.12:11211']
```

The client automatically uses **consistent hashing** to distribute keys across nodes. When a node fails, only the keys on that node are affected (not all keys like with simple round-robin).

## Advanced Configuration

You can pass extra options to customize client behavior:
```python
class MyService(object):
    name = "my_service"

    memcached = Memcached(
        connect_timeout=0.1,    # connection timeout in seconds
        timeout=0.2,            # operation timeout in seconds
        retry_attempts=2,       # number of retries on failure
        dead_timeout=10,        # how long to avoid a failed node
    )

    ...
```

## Available Operations

All standard memcached operations are supported:

```python
# Basic operations
self.memcached.set(key, value, expire=300)
result = self.memcached.get(key)
self.memcached.delete(key)

# Batch operations
self.memcached.set_many({'key1': 'val1', 'key2': 'val2'})
results = self.memcached.get_many(['key1', 'key2'])

# Increment/decrement operations
self.memcached.incr(key, delta=1)
self.memcached.decr(key, delta=1)
```

## Performance Tips

- **Identical server order**: Keep the same server order across all clients for consistent key distribution
- **Connection pooling**: Available via pymemcache options if needed
- **Custom timeouts**: Override defaults by passing pymemcache options to the constructor
- **Failure handling**: Failed nodes are automatically removed from the hash ring and retried later

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/andreasmyleus/nameko-pymemcache/",
    "name": "nameko-pymemcache",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "nameko memcached cache distributed consistent-hashing",
    "author": "andreasmyleus",
    "author_email": "andreas@pdc.ax",
    "download_url": "https://files.pythonhosted.org/packages/52/9b/09225f6766dfe792367411cac05841569212e8233fee305799b62ead96a4/nameko_pymemcache-0.1.2.tar.gz",
    "platform": null,
    "description": "# nameko-pymemcache\n[![PyPI version](https://badge.fury.io/py/nameko-pymemcache.svg)](https://badge.fury.io/py/nameko-pymemcache)\n[![Tests](https://github.com/andreasmyleus/nameko-pymemcache/actions/workflows/test.yml/badge.svg)](https://github.com/andreasmyleus/nameko-pymemcache/actions/workflows/test.yml)\n[![Python](https://img.shields.io/pypi/pyversions/nameko-pymemcache.svg)](https://pypi.org/project/nameko-pymemcache/)\n\nMemcached dependency for nameko services with consistent hashing support for multi-node setups. Uses the high-performance pymemcache library with automatic failover and connection pooling.\n\n**Key Features:**\n- **Consistent hashing** for reliable multi-node memcached clusters  \n- **Optimized for Nameko** - proper connection management and worker cleanup\n- **Automatic failover** when nodes become unavailable\n- **Drop-in replacement** for bmemcached with better multi-node behavior\n- **High performance** - uses pymemcache's efficient C implementation\n\nInspiration and structure **proudly** stolen from nameko-redis :) Thanks guys!\n\n## Installation\n```\npip install nameko-pymemcache\n```\n\n## Usage\n```python\nfrom nameko.rpc import rpc\nfrom nameko_pymemcache import Memcached\n\n\nclass MyService(object):\n    name = \"my_service\"\n\n    memcached = Memcached()\n\n    @rpc\n    def hello(self, name):\n        self.memcached.set(\"foo\", name)\n        return \"Hello, {}!\".format(name)\n\n    @rpc\n    def bye(self):\n        name = self.memcached.get(\"foo\")\n        return \"Bye, {}!\".format(name)\n```\n\nTo specify memcached uri(s) and optional username/password you will need a config\n```yaml\nAMQP_URI: 'amqp://guest:guest@localhost'\nMEMCACHED_URIS: ['127.0.0.1:11211', ]\nMEMCACHED_USER: 'playerone'\nMEMCACHED_PASSWORD: 'ready'\n```\n\n## Multi-Node Configuration\n\nFor multi-node memcached clusters, specify multiple servers using either format:\n\n**YAML list format:**\n```yaml\nAMQP_URI: 'amqp://guest:guest@localhost'\nMEMCACHED_URIS: \n  - '192.168.1.10:11211'\n  - '192.168.1.11:11211'\n  - '192.168.1.12:11211'\n```\n\n**Bracketed list format:**\n```yaml\nAMQP_URI: 'amqp://guest:guest@localhost'\nMEMCACHED_URIS: ['192.168.1.10:11211', '192.168.1.11:11211', '192.168.1.12:11211']\n```\n\nThe client automatically uses **consistent hashing** to distribute keys across nodes. When a node fails, only the keys on that node are affected (not all keys like with simple round-robin).\n\n## Advanced Configuration\n\nYou can pass extra options to customize client behavior:\n```python\nclass MyService(object):\n    name = \"my_service\"\n\n    memcached = Memcached(\n        connect_timeout=0.1,    # connection timeout in seconds\n        timeout=0.2,            # operation timeout in seconds\n        retry_attempts=2,       # number of retries on failure\n        dead_timeout=10,        # how long to avoid a failed node\n    )\n\n    ...\n```\n\n## Available Operations\n\nAll standard memcached operations are supported:\n\n```python\n# Basic operations\nself.memcached.set(key, value, expire=300)\nresult = self.memcached.get(key)\nself.memcached.delete(key)\n\n# Batch operations\nself.memcached.set_many({'key1': 'val1', 'key2': 'val2'})\nresults = self.memcached.get_many(['key1', 'key2'])\n\n# Increment/decrement operations\nself.memcached.incr(key, delta=1)\nself.memcached.decr(key, delta=1)\n```\n\n## Performance Tips\n\n- **Identical server order**: Keep the same server order across all clients for consistent key distribution\n- **Connection pooling**: Available via pymemcache options if needed\n- **Custom timeouts**: Override defaults by passing pymemcache options to the constructor\n- **Failure handling**: Failed nodes are automatically removed from the hash ring and retried later\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Memcached dependency for nameko services with consistent hashing",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/andreasmyleus/nameko-pymemcache/"
    },
    "split_keywords": [
        "nameko",
        "memcached",
        "cache",
        "distributed",
        "consistent-hashing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5d23e5a788edddb0119db9a6cc1a37d36de98d89a075025086939780b5630c9f",
                "md5": "b7808a79c342f39cafa5c46a4c9c9387",
                "sha256": "c1d4e8d659f0ab087ac7b1e8cf1fd88c046bca5574b2dadf2b86a702e6f3ef50"
            },
            "downloads": -1,
            "filename": "nameko_pymemcache-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b7808a79c342f39cafa5c46a4c9c9387",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8627,
            "upload_time": "2025-09-16T14:38:11",
            "upload_time_iso_8601": "2025-09-16T14:38:11.885365Z",
            "url": "https://files.pythonhosted.org/packages/5d/23/e5a788edddb0119db9a6cc1a37d36de98d89a075025086939780b5630c9f/nameko_pymemcache-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "529b09225f6766dfe792367411cac05841569212e8233fee305799b62ead96a4",
                "md5": "6c02826b2ab103c7843bc13771883388",
                "sha256": "2918e7efb499ea936333b73790d8db6c8d8189ee702cf58c050c4828004aa76f"
            },
            "downloads": -1,
            "filename": "nameko_pymemcache-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "6c02826b2ab103c7843bc13771883388",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10093,
            "upload_time": "2025-09-16T14:38:12",
            "upload_time_iso_8601": "2025-09-16T14:38:12.620172Z",
            "url": "https://files.pythonhosted.org/packages/52/9b/09225f6766dfe792367411cac05841569212e8233fee305799b62ead96a4/nameko_pymemcache-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-16 14:38:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "andreasmyleus",
    "github_project": "nameko-pymemcache",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "nameko-pymemcache"
}
        
Elapsed time: 7.58256s