title: Atomic operations in Redis
body: <p>How to perform these operations atomically?</p>
  
  <pre><code>def setNickName(nick):
      oldNick = r.get("user:id:1:nick") # r - instance of redis.Redis()
      updated = r.set("user:id:1:nick", nick) if r.hsetnx("user:ref:nick", nick, '1') else False
  
      if updated and oldNick:
          r.hdel("user:ref:nick", oldNick)
          return True
  
      return False
  </code></pre>