How do i prevent an overwrite on a key value in redis?



  • Also see: https://www.lightnetics.com/post/10426

    This article assumes you have installed and connected to the redis server.

    There's a redis command called setnx, that only sets the value if the key does not exist.

    127.0.0.1:6379> set song1 "the tide is high"
    OK
    127.0.0.1:6379> setnx song1 "that's entertainment"
    (integer) 0
    127.0.0.1:6379> get song1
    "the tide is high"
    127.0.0.1:6379>
    
    This is the same as using the NX option for set.

Log in to reply
 

© Lightnetics 2024