
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
redis-lock-py
Advanced tools
Redis distributed lock implementation for Python based on Pub/Sub messaging.
$> pip install redis-lock-py
import redis
from redis_lock import RedisLock
client = redis.Redis(host="127.0.0.1", port=6379)
name = "foo"
lock = RedisLock(client, name)
if not lock.acquire():
raise Exception("Fail to acquire lock")
print("Acquired lock successfully!")
lock.release()
The redis-py library is required for Redis connection objects.
After successfully acquiring the lock using RedisLock.acquire, ensure to release it by calling RedisLock.release to prevent lock retention.
import redis
from redis_lock import RedisLock
client = redis.Redis(host="127.0.0.1", port=6379)
with RedisLock(client, name="foo", blocking_timeout=10):
print("Acquired lock successfully!")
To avoid issues where the lock remains unreleased (potentially blocking other clients from acquiring it),
you can use RedisLock with a context manager, which ensures that the lock is automatically released at the end of the with block.
Both examples in sections 3.1 and 3.2 function in a same manner.
from redis.asyncio import Redis
from redis_lock.asyncio import RedisLock
client = Redis(host="127.0.0.1", port=6379)
async with RedisLock(client, name="foo", blocking_timeout=10):
print("Acquired lock successfully!")
redis-lock supports the asyncio platform.
import redis
from redis_lock import RedisSpinLock
client = redis.Redis(host="127.0.0.1", port=6379)
lock = RedisSpinLock(client, name="foo")
if not lock.acquire(blocking=True, sleep_time=0.1):
raise Exception("Fail to acquire lock")
print("Acquired lock successfully!")
lock.release()
While a spin lock is available, it is not recommended unless there is a compelling reason to use it, as it is less efficient compared to the Pub/Sub messaging system.

FAQs
Redis distributed lock implementation for Python based on Pub/Sub messaging
We found that redis-lock-py demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.