
Security News
Opengrep Adds Apex Support and New Rule Controls in Latest Updates
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
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
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.