How to use the redis.saveClient.setnx function in redis

To help you get started, we’ve selected a few redis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pilif / tempalias / lib / tempalias_http.js View on Github external
var rate_limit_check = function(){
          // too bad SETNX counts as a write operation even when it doesn't write.
          // that's why I can't just use redis' EXPIRE command
          var lock_key = 'lock:'+remote_addr;
          var t = (new Date()).getTime();
          redis.setnx(lock_key, t+config.http.rate_limit, function(lr){
            if (!lr){
              redis.get(lock_key, function(exp){
                if (parseInt(exp, 10) < (t)){
                  redis.set(lock_key, t+config.http.rate_limit, function(){
                    rbl_check();
                  });
                }else{
                  err(403, {error: 'rate-limited', description: 'please wait a moment before generating the next alias'});
                }
              });
            }else{
              rbl_check();
            }
          });
        };
github pilif / tempalias / lib / tempalias.js View on Github external
var uuidg = function uuidg() {
          len++;
          var id = UUID.uuid(len);
          redis.setnx('reservations:' + id, 'reserved', function(data) {
            if (parseInt(""+data, 10) == 0) {
              redis.set('admin:keylength', len, function(data){
                uuidg();
              });
            }
            callback(id);
          });
        }();
      });