tessl install tessl/pypi-pylibmc@1.6.0Quick and small memcached client for Python
Agent Success
Agent success rate when using this tile
86%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.04x
Baseline
Agent success rate without this tile
83%
Design a small service that uses a memcached client to keep integer counters with atomic updates. All mutations must rely on the client's atomic counter operations rather than manual read/modify/write sequences.
get_count returns the current value or a provided default when missing. @test@generates
class CounterService:
def __init__(self, client, default_ttl: int = 0):
"""client is a configured pylibmc client; default_ttl applies when a counter is first created."""
def increment(self, key: str, delta: int = 1) -> int:
"""Atomically increases a counter by delta, initializing missing counters at zero before the operation. Returns the new count."""
def decrement(self, key: str, delta: int = 1) -> int:
"""Atomically decreases a counter by delta without going below zero. Returns the new count."""
def bulk_bump(self, deltas: dict[str, int]) -> dict[str, int]:
"""Atomically adjusts multiple counters by given deltas (positive to increment, negative to decrement). Returns updated counts keyed by counter name."""
def get_count(self, key: str, default: int = 0) -> int:
"""Fetches the current counter value, returning the provided default when the counter does not exist."""Memcached client used to persist counters with atomic increment/decrement support.