Skip to content

Commit

Permalink
Add SETNX
Browse files Browse the repository at this point in the history
  • Loading branch information
elcuervo committed Aug 5, 2011
1 parent bb1d418 commit 22f47a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -112,7 +112,7 @@
* SELECT index ✓
* SETBIT key offset value
* SETEX key seconds value ✓
* SETNX key value
* SETNX key value ✓
* SETRANGE key offset value
* SHUTDOWN
* SINTER key [key ...]
Expand Down
7 changes: 7 additions & 0 deletions index.html
Expand Up @@ -464,6 +464,13 @@ <h3>Scenarios</h3>
assert_equal(l.get("foo"), "Hello")
},

"SETNX should set a key only if the key does not exists": function(){
l.setnx("foo", "Hello");
l.setnx("foo", "World");

assert_equal(l.get("foo"), "Hello");
},

});

</script>
Expand Down
2 changes: 2 additions & 0 deletions lodis.coffee
Expand Up @@ -343,3 +343,5 @@ class @Lodis
this.set(key, value)
this.expire(key, expire)

setnx: (key, value) -> this.set(key, value) if !this.exists(key)

5 changes: 5 additions & 0 deletions lodis.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 22f47a5

Please sign in to comment.