Atomic SET if not exists

Difficulty: Intermediate

Question

What does 'SET key value NX' do?

Answer

It only sets the key if it doesn't already exist. It's the building block for distributed locks.

Concepts covered

Atomicity, Redlock