Tagged articles
setnx
23 articles · Page 1 of 1
This article explains four approaches to implementing distributed locks with Redis: basic SETNX with expiration, atomic Lua scripts for lock acquire/release, the Redisson Java client with watchdog renewal, and the Redlock algorithm for high-availability multi-master deployments.
Distributed LockJavaLua Script
0 likes · 10 min read

This article examines the evolution of Redis distributed lock implementations—from the basic SETNX command to atomic SET with Lua scripts and the feature‑rich Redisson framework—detailing core requirements, common pitfalls, Go code samples, and production‑grade recommendations.
Distributed LockGoLua
0 likes · 21 min read

This article walks through the evolution of Redis distributed locks—from basic SETNX mutual exclusion to atomic SET with expiration, Lua‑based safe unlocking, Redisson's WatchDog auto‑renewal, and the RedLock algorithm—highlighting pitfalls, best‑practice implementations, and interview‑style Q&A for robust production use.
Distributed LockJavaRedisson
0 likes · 15 min read

This article explains why duplicate order requests occur, analyzes the idempotency challenges, and presents practical front‑end and Redis‑based solutions—including button disabling, SETNX locking, and token validation—to ensure only one successful order per user action.
Idempotencyduplicate orderfrontend
0 likes · 6 min read

This article explains how to achieve API idempotency by having clients send a short‑lived unique serial number, storing it as a Redis key with SETNX and an expiration, and handling the Redis response to process or reject duplicate requests.
API idempotencyredissetnx
0 likes · 3 min read


ITPUBJan 7, 2024 · Backend Development
A Redis lock timeout caused users to be blocked for two hours, revealing problems with lock leakage and mis‑release; the article explains the root causes, proper use of SETNX with EXPIRE, and Lua scripts for atomic operations and safe lock deletion.
Distributed LockExpireLua
0 likes · 7 min read

This article explains the concept of distributed locks, outlines various implementation strategies, and dives deep into Redis-based solutions—including SETNX, GET, GETSET, EXPIRE, and Lua scripting—to achieve mutual exclusion, safety, reentrancy, and automatic lock release in high‑performance systems.
Distributed LockReentrancysetnx
0 likes · 10 min read

This article examines the shortcomings of local locking in microservices, introduces distributed locking concepts, and walks through five progressive Redis-based lock implementations—from a simple SETNX bronze approach to a Lua‑scripted diamond solution—detailing their mechanisms, code examples, and trade‑offs.
Distributed LockJavaLua Script
0 likes · 16 min read

This article explains three Redis‑based rate‑limiting methods—using SETNX for simple counters, leveraging ZSET for a sliding‑window algorithm, and implementing a token‑bucket scheme with LISTs—complete with Java code examples and discussion of their advantages and drawbacks.
BackendZSetrate limiting
0 likes · 7 min read

This article explains three Redis-powered rate‑limiting methods—using SETNX for simple counters, leveraging ZSET for a sliding‑window algorithm, and implementing a token‑bucket scheme with LISTs—providing Java code examples, advantages, and practical considerations for high‑concurrency back‑end services.
Javaredissetnx
0 likes · 7 min read

This article explains how Redis setnx, the Redisson client, and the RedLock algorithm work together to implement distributed locks, discusses common pitfalls such as non‑atomic unlocks, and provides Lua scripts and Java pseudocode for safe lock acquisition and release.
LuaRedissonRedlock
0 likes · 10 min read

This article explains the fundamentals of Redis locking mechanisms, covering SETNX usage, the pitfalls of naive implementations, Lua‑based atomic unlock scripts, the Redisson client library, and the RedLock algorithm, while providing practical code examples and diagrams to illustrate each concept.
Distributed LockLuaRedisson
0 likes · 10 min read

This article explains how Redis implements distributed locks using the SET command with NX and PX options, compares plain setnx, Lua‑based atomic unlock scripts, and Redisson’s high‑level APIs including the RedLock algorithm, and provides practical code examples and pitfalls to avoid.
BackendDistributed LockLua
0 likes · 11 min read

This article explains how Redis locking works, covering the setnx command, the importance of using unique values, atomic unlock via Lua scripts, the Redisson client features, and the RedLock distributed algorithm, while highlighting common pitfalls and practical recommendations.
Distributed LockLua ScriptRedisson
0 likes · 10 min read

This article explores the most common Redis locking mechanisms—SetNX, RedLock, and Redisson—detailing their principles, pitfalls, and implementation nuances, including code examples, Lua scripts for atomic unlocks, and best‑practice recommendations for building reliable distributed locks in backend systems.
Distributed LockRedissonRedlock
0 likes · 11 min read

This article explains how Redis locking works by detailing the setnx command, its modern usage with the SET command and PX expiration, common pitfalls, safe unlocking with unique values and Lua scripts, and introduces Redisson's lock implementations and the RedLock algorithm for distributed environments.
RedissonRedlockbackend development
0 likes · 10 min read

This article examines why local locks fail in distributed systems, introduces Redis‑based distributed locking, and walks through five progressive solutions—from a simple SETNX implementation to atomic Lua scripts—highlighting each approach's drawbacks and how to mitigate them.
Backendredissetnx
0 likes · 16 min read

This article explains why simple SETNX/EXPIRE commands can cause deadlocks, shows how to achieve atomic lock operations with Lua scripts or the Redis SET command, and demonstrates how to use the Redisson library for re‑entrant, auto‑renewing distributed locks in Java.
Distributed LockLua ScriptRedisson
0 likes · 8 min read

This article explains the fundamentals and pitfalls of using Redis for distributed locking, covering the setnx command, the SET command with NX and PX options, Lua‑based lock scripts, Redisson’s lock implementations, and the RedLock algorithm, along with practical code examples.
Distributed LockLuaRedisson
0 likes · 12 min read

This article explains the fundamentals of Redis locking mechanisms, including the setnx command, the RedLock algorithm, and how the Redisson Java client implements distributed locks with Lua scripts, highlighting pitfalls, best practices, and code examples for safe lock acquisition and release.
JavaLuaRedisson
0 likes · 10 min read

This article explains how Redis can be used for distributed locking, covering the setnx command, the SET command with NX and PX options, common pitfalls, Lua‑based atomic unlock scripts, the Redisson client, and the RedLock algorithm for achieving reliable locks across multiple nodes.
Distributed LockLua scriptingRedisson
0 likes · 10 min read

This article explores Redis locking mechanisms, explaining the SETNX command, its limitations, the use of PX for timeouts, Lua scripts for atomic unlocks, and introduces Redisson’s advanced lock implementations including RedLock, while highlighting practical pitfalls and best‑practice recommendations for reliable distributed synchronization.
LuaRedissonRedlock
0 likes · 11 min read


21CTONov 8, 2017 · Backend Development
This article explains how to build reliable distributed locks with Redis, covering essential commands, common pitfalls, improvements using GETSET, Lua scripting for atomicity, and complete Java code examples that address deadlock and unlock vulnerabilities.
Distributed LockJavaLua Script
0 likes · 15 min read
