From 2fee47a0de6a4f5cc2077c132c6c57b66ed2505b Mon Sep 17 00:00:00 2001 From: Brian Wilke Date: Wed, 11 Mar 2015 22:40:16 -0600 Subject: [PATCH] minified files for 0.0.8 --- redis-mock-min.js | 4 ++-- redis-mock-min.map | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/redis-mock-min.js b/redis-mock-min.js index 90345f1..0bad828 100644 --- a/redis-mock-min.js +++ b/redis-mock-min.js @@ -1,3 +1,3 @@ -(function(){"use strict";var root=this;var redismock={};function exists(v){return typeof v!=="undefined"&&v!==null}if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=redismock}exports.redismock=redismock}else{root.redismock=redismock}if(!exists(setImmediate)||typeof setImmediate!=="function"){var setImmediate=function(f){setTimeout(f,0)}}if(!exists(process)){var process={}}var cache={};var timeouts={};var mySubscriptions={};var watchers={};var sets="sets-"+Math.random();var zsets="zsets-"+Math.random();var hashes="hashes-"+Math.random();cache[sets]={};cache[zsets]={};cache[hashes]={};String.prototype.escape=function(){var escapable=/[.\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;var meta;meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",".":"\\.",'"':'\\"',"\\":"\\\\"};function escapechar(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}return this.replace(escapable,escapechar)};function translate(pat){var i=0,j,n=pat.length||0,res,c,stuff;res="^";while(i=n){res=res+"\\["}else{stuff=pat.slice(i,j).replace("\\","\\\\");i=j+1;if(stuff[0]==="!"){stuff="^"+stuff.slice(1)}else if(stuff[0]==="^"){stuff="\\"+stuff}res=res+"["+stuff+"]"}}else{res=res+c.escape()}}return res+"$"}var cb=function(callback,context){return function(){var args=arguments;if(callback&&typeof callback==="function"){setImmediate(function(){callback.apply(context,args)})}if(args[0]instanceof Error){return args[0]}return args[1]}};var gather=function(f,e){var end=f.length;if(e){end=e}return function(){var idx,len=arguments.length;var callback;var list=[arguments[end-2]];if(len>=end){for(idx=end-1;idx=cache[key].length){end=cache[key].length-1}if(start<0){start=cache[key].length+start}if(end<0){end=cache[key].length+end}if(start>end){return 0}count=0;for(idx=start;idx<=end;idx+=1){n=cache[key].charCodeAt(idx);while(n){count+=n&1;n>>=1}}return count}).thennx(function(){return 0}).end()};redismock.bitop=function(operation,destkey,key,callback){var that=this;var g=gather(this.bitop).apply(this,arguments);var longest,strings,string,r;operation=typeof operation==="string"?operation.toLowerCase():"";if(operation!=="and"&&operation!=="or"&&operation!=="xor"&&operation!=="not"){return cb(callback)(new Error("ERR syntax error"))}callback=g.callback;strings=g.list.map(function(k){if(that.exists(k)&&that.type(k)!=="string"){return null}return that.exists(k)?cache[k]:""});if(strings.some(function(str){return str===null})){return wrongType(callback)}longest=strings.reduce(function(length,str){return str.length>length?str.length:length},0);strings=strings.map(function(str){while(str.length0){n=cur.charCodeAt(idx)^str.charCodeAt(idx)}else{n=cur.charCodeAt(idx)}}else if(operation==="not"){n=~cur.charCodeAt(idx)}s+=String.fromCharCode(n)}return s},strings[0]);r=this.set(destkey,string);if(r instanceof Error){return cb(callback)(r)}return cb(callback)(null,string.length)};redismock.bitpos=function(key,bit,callback){var g=gather(this.bitpos,3).apply(this,arguments);var start,end;callback=g.callback;if(g.list.length>1){start=g.list[1];end=g.list[2]}if(typeof start==="undefined"){start=0}if(bit!==0&&bit!==1){return cb(callback)(new Error("ERR The bit argument must be 1 or 0."))}return this.ifType(key,"string",callback).thennx(function(){if(bit===0){return 0}return-1}).thenex(function(){var idx,ch,cnt,noend=false;if(start<0){start=cache[key].length+start}if(typeof end==="undefined"){noend=true;end=cache[key].length-1}if(end<0){end=cache[key].length+end}if(start>end){return-1}for(idx=start;idx<=end;idx+=1){ch=cache[key].charCodeAt(idx);cnt=0;while(cnt<8){if(bit===0&&(ch&128)!==128){return idx*8+cnt}if(bit===1&&(ch&128)===128){return idx*8+cnt}ch<<=1;cnt+=1}}if(bit===1){return-1}if(bit===0&&noend){return idx*8}return-1}).end()};redismock.decr=function(key,callback){return this.decrby(key,1,callback)};redismock.decrby=function(key,decrement,callback){return this.ifType(key,"string",callback).thennx(function(){this.set(key,"0")}).then(function(){var asInt=parseInt(this.get(key),10);if(isNaN(asInt)){return new Error("ERR value is not an integer or out of range")}this.set(key,asInt-decrement);return asInt-decrement}).end()};redismock.get=function(key,callback){if(this.type(key)==="string"){return cb(callback)(null,cache[key])}return cb(callback)(null,null)};redismock.getbit=function(key,offset,callback){return this.ifType(key,"string",callback).thenex(function(){var n,pos;if(offset>=cache[key].length*8){return 0}n=cache[key].charCodeAt(Math.floor(offset/8));pos=offset%8;return n>>pos&1}).thennx(function(){return 0}).end()};redismock.getrange=function(key,start,end,callback){return this.ifType(key,"string",callback).thenex(function(){var len=0;if(end<0){end=cache[key].length+end}if(start<0){len=end-(cache[key].length+start)+1}else{len=end-start+1}return cache[key].substr(start,len)}).thennx(function(){return""}).end()};redismock.getset=function(key,value,callback){var prev=this.get(key);this.set(key,value);return cb(callback)(null,prev)};redismock.incr=function(key,callback){return this.incrby(key,1,callback)};redismock.incrby=function(key,increment,callback){return this.ifType(key,"string",callback).thennx(function(){this.set(key,"0")}).then(function(){var asInt=parseInt(this.get(key),10);if(isNaN(asInt)){return new Error("ERR value is not an integer or out of range")}this.set(key,asInt+increment);return asInt+increment}).end()};redismock.incrbyfloat=function(key,increment,callback){return this.ifType(key,"string",callback).thennx(function(){this.set(key,"0")}).then(function(){var asInt=parseFloat(this.get(key));if(isNaN(asInt)){return new Error("ERR value is not an integer or out of range")}this.set(key,asInt+increment);return this.get(key)}).end()};redismock.mget=function(key,callback){var g=gather(this.mget).apply(this,arguments);callback=g.callback;return cb(callback)(null,g.list.map(function(k){return cache[k]||null}))};redismock.mset=function(key,value,callback){var kvs=[];var that=this;var g=gather(this.mset,2).apply(this,arguments);callback=g.callback;g.list.forEach(function(opt,index){if(index%2===0){kvs.push([opt,g.list[index+1]])}});kvs.forEach(function(kv){that.set(kv[0],kv[1])});return cb(callback)(null,"OK")};redismock.msetnx=function(key,value,callback){var kvs=[];var that=this;var g=gather(this.msetnx,2).apply(this,arguments);callback=g.callback;g.list.forEach(function(opt,index){if(index%2===0){kvs.push([opt,g.list[index+1]])}});if(kvs.some(function(kv){return that.exists(kv[0])})){return cb(callback)(null,0)}kvs.forEach(function(kv){that.set(kv[0],kv[1])});return cb(callback)(null,1)};redismock.psetex=function(key,milliseconds,value,callback){this.set(key,value);this.pexpire(key,milliseconds);return cb(callback)(null,"OK")};redismock.set=function(key,value,callback){var nx=false,xx=false,ex=-1,px=-1;var g=gather(this.set).apply(this,arguments);callback=g.callback;g.list.forEach(function(opt,index){if(opt==="nx"){nx=true}else if(opt==="xx"){xx=true}else if(opt==="ex"){ex=g.list[index+1]}else if(opt==="px"){px=g.list[index+1]}});if(nx){if(this.exists(key)){return cb(callback)(null,null)}}if(xx){if(!this.exists(key)){return cb(callback)(null,null)}}cache[key]=exists(value)?value.toString():"";if(px!==-1){redismock.pexpire(key,px)}if(ex!==-1){redismock.expire(key,ex)}return cb(callback)(null,"OK")};redismock.setbit=function(key,offset,value,callback){return this.ifType(key,"string",callback).thennx(function(){cache[key]=""}).then(function(){var byteIdx=Math.floor(offset/8);var bitIdx=offset%8;var idx,bit,mask;var code;if(value!==0&&value!==1){return new Error("ERR bit is not an integer or out of range")}while(cache[key].length>=1;idx+=1}bit=(code&mask)===0?0:1;if(value===0){code=code&~mask}else{code=code|mask}cache[key]=cache[key].substr(0,byteIdx)+String.fromCharCode(code)+cache[key].substr(byteIdx+1);return bit}).end()};redismock.setex=function(key,seconds,value,callback){this.set(key,value);this.expire(key,seconds);return cb(callback)(null,"OK")};redismock.setnx=function(key,value,callback){if(!this.exists(key)){this.set(key,value);return cb(callback)(null,1)}return cb(callback)(null,0)};redismock.setrange=function(key,offset,value,callback){return this.ifType(key,"string",callback).thennx(function(){cache[key]=""}).then(function(){var idx,newValue;if(cache[key].length=0&&i=0){elem=cache[key][cache[key].length+i]}}).then(function(){return elem}).end()};redismock.linsert=function(key,beforeafter,pivot,value,callback){return this.ifType(key,"list",callback).thenex(function(){var idx=cache[key].indexOf(pivot);if(idx!==-1){if(beforeafter==="before"){cache[key].splice(idx,0,value)}else if(beforeafter==="after"){cache[key].splice(idx+1,0,value)}return cache[key].length}return-1}).thennx(function(){return 0}).end()};redismock.llen=function(key,callback){return this.ifType(key,"list",callback).thenex(function(){return cache[key].length}).thennx(function(){return 0}).end()};redismock.lpop=function(key,callback){return this.ifType(key,"list",callback).thenex(function(){return cache[key].shift()}).thennx(function(){return null}).end()};redismock.lpush=function(key,element,callback){var g=gather(this.lpush).apply(this,arguments);callback=g.callback;return this.ifType(key,"list",callback).thennx(function(){cache[key]=[]}).then(function(){cache[key]=g.list.concat(cache[key]);return cache[key].length}).end()};redismock.lpushx=function(key,element,callback){return this.ifType(key,"list",callback).thenex(function(){cache[key].unshift(element);return cache[key].length}).thennx(function(){return 0}).end()};redismock.lrange=function(key,start,end,callback){var l=[];return this.ifType(key,"list",callback).thenex(function(){if(start>cache[key].length-1){l=[]}else{if(start<0){start=cache[key].length+start}if(end<0){end=cache[key].length+end}if(start>end){l=[]}else{l=cache[key].slice(start,end+1)}}}).then(function(){return l}).end()};redismock.lrem=function(key,count,element,callback){var cnt=0;return this.ifType(key,"list",callback).thenex(function(){var idx;while(true){idx=cache[key].indexOf(element);if(idx===-1){break}cache[key].splice(idx,1);cnt+=1;if(count>0&&cnt===count){break}}if(!cache[key].length){this.del(key)}}).then(function(){return cnt}).end()};redismock.lset=function(key,index,element,callback){return this.ifType(key,"list",callback).thenex(function(){if(index>=cache[key].length){return new Error("ERR index out of range")}cache[key][index]=element;return"OK"}).thennx(function(){return new Error("ERR no such key")}).end()};redismock.ltrim=function(key,start,end,callback){return this.ifType(key,"list",callback).thenex(function(){var tmpS,tmpE;if(start>cache[key].length-1||start>end){cache[key]=[]}else{if(start<0&&end<0){tmpE=cache[key].length+end;tmpS=cache[key].length+start;if(tmpS<0){tmpS=0}start=tmpS;end=tmpE}if(end>cache[key].length-1){end=cache[key].length-1}cache[key]=cache[key].slice(start,end+1)}}).then(function(){if(this.exists(key)&&!cache[key].length){this.del(key)}return"OK"}).end()};redismock.rpop=function(key,callback){return this.ifType(key,"list",callback).thenex(function(){return cache[key].pop()}).thennx(function(){return null}).end()};redismock.rpoplpush=function(source,dest,callback){var element,reply;element=this.rpop(source);if(element instanceof Error){return cb(callback)(element)}if(element){reply=this.lpush(dest,element);if(reply instanceof Error){return cb(callback)(reply)}}return cb(callback)(null,element)};redismock.rpush=function(key,element,callback){var g=gather(this.rpush).apply(this,arguments);callback=g.callback;return this.ifType(key,"list",callback).thennx(function(){cache[key]=[]}).then(function(){cache[key]=cache[key].concat(g.list);return cache[key].length}).end()};redismock.rpushx=function(key,element,callback){return this.ifType(key,"list",callback).thenex(function(){cache[key].push(element);return cache[key].length}).thennx(function(){return 0}).end()};redismock.sadd=function(key,member,callback){var g=gather(this.sadd).apply(this,arguments);var count=0;callback=g.callback;return this.ifType(key,"set",callback).thennx(function(){cache[sets][key]={}}).then(function(){g.list.forEach(function(m){m=m?m.toString():"";if(m.length===0){return}if(!(m in cache[sets][key])){cache[sets][key][m]=m;count+=1}});return count}).end()};redismock.scard=function(key,callback){return this.ifType(key,"set",callback).thenex(function(){return Object.keys(cache[sets][key]).length}).thennx(function(){return 0}).end()};redismock.sdiff=function(key,callback){return cb(callback)(new Error("UNIMPLEMENTED"))};redismock.sdiffstore=function(destination,key,callback){return cb(callback)(new Error("UNIMPLEMENTED"))};redismock.sinter=function(key,callback){return cb(callback)(new Error("UNIMPLEMENTED"))};redismock.sinterstore=function(destination,key,callback){return cb(callback)(new Error("UNIMPLEMENTED"))};redismock.sismember=function(key,member,callback){return this.ifType(key,"set",callback).thenex(function(){return member in cache[sets][key]?1:0}).thennx(function(){return 0}).end()};redismock.smembers=function(key,callback){return this.ifType(key,"set",callback).thenex(function(){return Object.keys(cache[sets][key])}).thennx(function(){return[]}).end()};redismock.smove=function(source,dest,member,callback){var r,e;r=redismock.srem(source,member);if(r instanceof Error){return cb(callback)(r)}e=redismock.sadd(dest,member);if(e instanceof Error){return cb(callback)(e)}return cb(callback)(null,r)};redismock.spop=function(key,callback){var r;var rando=this.srandmember(key);if(rando instanceof Error){return cb(callback)(rando)}r=this.srem(key,rando);if(r instanceof Error){return cb(callback)(r)}return cb(callback)(null,rando)};redismock.srandmember=function(key,callback){var count;if(arguments.length===2&&typeof callback!=="function"){count=callback;callback=null}if(arguments.length===3){count=callback;callback=arguments[2]}return this.ifType(key,"set",callback).thenex(function(){var k=Object.keys(cache[sets][key]);var idx,randos;if(count===0){return null}if(count){randos=[];for(idx=0;idxstart){return true}idx+=cache[zsets][key].set[score].length;startScoreIdx+=1;return false});cache[zsets][key].scores.slice(startScoreIdx).some(function(score){var arr=[];var len=cache[zsets][key].set[score].length;var from=0,to=0;if(idx>stop){return true}while(idx=limitOffset){if(limitCount!==-1){if(arr.length=2){for(idx=1;idx=2){for(idx=1;idx=n){res=res+"\\["}else{stuff=pat.slice(i,j).replace("\\","\\\\");i=j+1;if(stuff[0]==="!"){stuff="^"+stuff.slice(1)}else if(stuff[0]==="^"){stuff="\\"+stuff}res=res+"["+stuff+"]"}}else{res=res+c.escape()}}return res+"$"}var cb=function(callback,context){return function(){var args=arguments;if(callback&&typeof callback==="function"){setImmediate(function(){callback.apply(context,args)})}if(args[0]instanceof Error){return args[0]}return args[1]}};var gather=function(f,e){var end=f.length;if(e){end=e}return function(){var idx,len=arguments.length;var callback;var list=[arguments[end-2]];if(len>=end){for(idx=end-1;idx=cache[key].length){end=cache[key].length-1}if(start<0){start=cache[key].length+start}if(end<0){end=cache[key].length+end}if(start>end){return 0}count=0;for(idx=start;idx<=end;idx+=1){n=cache[key].charCodeAt(idx);while(n){count+=n&1;n>>=1}}return count}).thennx(function(){return 0}).end()};redismock.bitop=function(operation,destkey,key,callback){var that=this;var g=gather(this.bitop).apply(this,arguments);var longest,strings,string,r;operation=typeof operation==="string"?operation.toLowerCase():"";if(operation!=="and"&&operation!=="or"&&operation!=="xor"&&operation!=="not"){return cb(callback)(new Error("ERR syntax error"))}callback=g.callback;strings=g.list.map(function(k){if(that.exists(k)&&that.type(k)!=="string"){return null}return that.exists(k)?cache[k]:""});if(strings.some(function(str){return str===null})){return wrongType(callback)}longest=strings.reduce(function(length,str){return str.length>length?str.length:length},0);strings=strings.map(function(str){while(str.length0){n=cur.charCodeAt(idx)^str.charCodeAt(idx)}else{n=cur.charCodeAt(idx)}}else if(operation==="not"){n=~cur.charCodeAt(idx)}s+=String.fromCharCode(n)}return s},strings[0]);r=this.set(destkey,string);if(r instanceof Error){return cb(callback)(r)}return cb(callback)(null,string.length)};redismock.bitpos=function(key,bit,callback){var g=gather(this.bitpos,3).apply(this,arguments);var start,end;callback=g.callback;if(g.list.length>1){start=g.list[1];end=g.list[2]}if(typeof start==="undefined"){start=0}if(bit!==0&&bit!==1){return cb(callback)(new Error("ERR The bit argument must be 1 or 0."))}return this.ifType(key,"string",callback).thennx(function(){if(bit===0){return 0}return-1}).thenex(function(){var idx,ch,cnt,noend=false;if(start<0){start=cache[key].length+start}if(typeof end==="undefined"){noend=true;end=cache[key].length-1}if(end<0){end=cache[key].length+end}if(start>end){return-1}for(idx=start;idx<=end;idx+=1){ch=cache[key].charCodeAt(idx);cnt=0;while(cnt<8){if(bit===0&&(ch&128)!==128){return idx*8+cnt}if(bit===1&&(ch&128)===128){return idx*8+cnt}ch<<=1;cnt+=1}}if(bit===1){return-1}if(bit===0&&noend){return idx*8}return-1}).end()};redismock.decr=function(key,callback){return this.decrby(key,1,callback)};redismock.decrby=function(key,decrement,callback){return this.ifType(key,"string",callback).thennx(function(){this.set(key,"0")}).then(function(){var asInt=parseInt(this.get(key),10);if(isNaN(asInt)){return new Error("ERR value is not an integer or out of range")}this.set(key,asInt-decrement);return asInt-decrement}).end()};redismock.get=function(key,callback){if(this.type(key)==="string"){return cb(callback)(null,cache[key])}return cb(callback)(null,null)};redismock.getbit=function(key,offset,callback){return this.ifType(key,"string",callback).thenex(function(){var n,pos;if(offset>=cache[key].length*8){return 0}n=cache[key].charCodeAt(Math.floor(offset/8));pos=offset%8;return n>>pos&1}).thennx(function(){return 0}).end()};redismock.getrange=function(key,start,end,callback){return this.ifType(key,"string",callback).thenex(function(){var len=0;if(end<0){end=cache[key].length+end}if(start<0){len=end-(cache[key].length+start)+1}else{len=end-start+1}return cache[key].substr(start,len)}).thennx(function(){return""}).end()};redismock.getset=function(key,value,callback){var prev=this.get(key);this.set(key,value);return cb(callback)(null,prev)};redismock.incr=function(key,callback){return this.incrby(key,1,callback)};redismock.incrby=function(key,increment,callback){return this.ifType(key,"string",callback).thennx(function(){this.set(key,"0")}).then(function(){var asInt=parseInt(this.get(key),10);if(isNaN(asInt)){return new Error("ERR value is not an integer or out of range")}this.set(key,asInt+increment);return asInt+increment}).end()};redismock.incrbyfloat=function(key,increment,callback){return this.ifType(key,"string",callback).thennx(function(){this.set(key,"0")}).then(function(){var asInt=parseFloat(this.get(key));if(isNaN(asInt)){return new Error("ERR value is not an integer or out of range")}this.set(key,asInt+increment);return this.get(key)}).end()};redismock.mget=function(key,callback){var g=gather(this.mget).apply(this,arguments);callback=g.callback;return cb(callback)(null,g.list.map(function(k){return cache[k]||null}))};redismock.mset=function(key,value,callback){var kvs=[];var that=this;var g=gather(this.mset,2).apply(this,arguments);callback=g.callback;g.list.forEach(function(opt,index){if(index%2===0){kvs.push([opt,g.list[index+1]])}});kvs.forEach(function(kv){that.set(kv[0],kv[1])});return cb(callback)(null,"OK")};redismock.msetnx=function(key,value,callback){var kvs=[];var that=this;var g=gather(this.msetnx,2).apply(this,arguments);callback=g.callback;g.list.forEach(function(opt,index){if(index%2===0){kvs.push([opt,g.list[index+1]])}});if(kvs.some(function(kv){return that.exists(kv[0])})){return cb(callback)(null,0)}kvs.forEach(function(kv){that.set(kv[0],kv[1])});return cb(callback)(null,1)};redismock.psetex=function(key,milliseconds,value,callback){this.set(key,value);this.pexpire(key,milliseconds);return cb(callback)(null,"OK")};redismock.set=function(key,value,callback){var nx=false,xx=false,ex=-1,px=-1;var g=gather(this.set).apply(this,arguments);callback=g.callback;g.list.forEach(function(opt,index){if(opt==="nx"){nx=true}else if(opt==="xx"){xx=true}else if(opt==="ex"){ex=g.list[index+1]}else if(opt==="px"){px=g.list[index+1]}});if(nx){if(this.exists(key)){return cb(callback)(null,null)}}if(xx){if(!this.exists(key)){return cb(callback)(null,null)}}cache[key]=exists(value)?value.toString():"";if(px!==-1){redismock.pexpire(key,px)}if(ex!==-1){redismock.expire(key,ex)}return cb(callback)(null,"OK")};redismock.setbit=function(key,offset,value,callback){return this.ifType(key,"string",callback).thennx(function(){cache[key]=""}).then(function(){var byteIdx=Math.floor(offset/8);var bitIdx=offset%8;var idx,bit,mask;var code;if(value!==0&&value!==1){return new Error("ERR bit is not an integer or out of range")}while(cache[key].length>=1;idx+=1}bit=(code&mask)===0?0:1;if(value===0){code=code&~mask}else{code=code|mask}cache[key]=cache[key].substr(0,byteIdx)+String.fromCharCode(code)+cache[key].substr(byteIdx+1);return bit}).end()};redismock.setex=function(key,seconds,value,callback){this.set(key,value);this.expire(key,seconds);return cb(callback)(null,"OK")};redismock.setnx=function(key,value,callback){if(!this.exists(key)){this.set(key,value);return cb(callback)(null,1)}return cb(callback)(null,0)};redismock.setrange=function(key,offset,value,callback){return this.ifType(key,"string",callback).thennx(function(){cache[key]=""}).then(function(){var idx,newValue;if(cache[key].length=0&&i=0){elem=cache[key][cache[key].length+i]}}).then(function(){return elem}).end()};redismock.linsert=function(key,beforeafter,pivot,value,callback){return this.ifType(key,"list",callback).thenex(function(){var idx=cache[key].indexOf(pivot);if(idx!==-1){if(beforeafter==="before"){cache[key].splice(idx,0,value)}else if(beforeafter==="after"){cache[key].splice(idx+1,0,value)}return cache[key].length}return-1}).thennx(function(){return 0}).end()};redismock.llen=function(key,callback){return this.ifType(key,"list",callback).thenex(function(){return cache[key].length}).thennx(function(){return 0}).end()};redismock.lpop=function(key,callback){return this.ifType(key,"list",callback).thenex(function(){return cache[key].shift()}).thennx(function(){return null}).end()};redismock.lpush=function(key,element,callback){var g=gather(this.lpush).apply(this,arguments);callback=g.callback;return this.ifType(key,"list",callback).thennx(function(){cache[key]=[]}).then(function(){cache[key]=g.list.concat(cache[key]);return cache[key].length}).end()};redismock.lpushx=function(key,element,callback){return this.ifType(key,"list",callback).thenex(function(){cache[key].unshift(element);return cache[key].length}).thennx(function(){return 0}).end()};redismock.lrange=function(key,start,end,callback){var l=[];return this.ifType(key,"list",callback).thenex(function(){if(start>cache[key].length-1){l=[]}else{if(start<0){start=cache[key].length+start}if(end<0){end=cache[key].length+end}if(start>end){l=[]}else{l=cache[key].slice(start,end+1)}}}).then(function(){return l}).end()};redismock.lrem=function(key,count,element,callback){var cnt=0;return this.ifType(key,"list",callback).thenex(function(){var idx;while(true){idx=cache[key].indexOf(element);if(idx===-1){break}cache[key].splice(idx,1);cnt+=1;if(count>0&&cnt===count){break}}if(!cache[key].length){this.del(key)}}).then(function(){return cnt}).end()};redismock.lset=function(key,index,element,callback){return this.ifType(key,"list",callback).thenex(function(){if(index>=cache[key].length){return new Error("ERR index out of range")}cache[key][index]=element;return"OK"}).thennx(function(){return new Error("ERR no such key")}).end()};redismock.ltrim=function(key,start,end,callback){return this.ifType(key,"list",callback).thenex(function(){var tmpS,tmpE;if(start>cache[key].length-1||start>end){cache[key]=[]}else{if(start<0&&end<0){tmpE=cache[key].length+end;tmpS=cache[key].length+start;if(tmpS<0){tmpS=0}start=tmpS;end=tmpE}if(end>cache[key].length-1){end=cache[key].length-1}cache[key]=cache[key].slice(start,end+1)}}).then(function(){if(this.exists(key)&&!cache[key].length){this.del(key)}return"OK"}).end()};redismock.rpop=function(key,callback){return this.ifType(key,"list",callback).thenex(function(){return cache[key].pop()}).thennx(function(){return null}).end()};redismock.rpoplpush=function(source,dest,callback){var element,reply;element=this.rpop(source);if(element instanceof Error){return cb(callback)(element)}if(element){reply=this.lpush(dest,element);if(reply instanceof Error){return cb(callback)(reply)}}return cb(callback)(null,element)};redismock.rpush=function(key,element,callback){var g=gather(this.rpush).apply(this,arguments);callback=g.callback;return this.ifType(key,"list",callback).thennx(function(){cache[key]=[]}).then(function(){cache[key]=cache[key].concat(g.list);return cache[key].length}).end()};redismock.rpushx=function(key,element,callback){return this.ifType(key,"list",callback).thenex(function(){cache[key].push(element);return cache[key].length}).thennx(function(){return 0}).end()};redismock.sadd=function(key,member,callback){var g=gather(this.sadd).apply(this,arguments);var count=0;callback=g.callback;return this.ifType(key,"set",callback).thennx(function(){cache[sets][key]={}}).then(function(){g.list.forEach(function(m){m=m?m.toString():"";if(m.length===0){return}if(!(m in cache[sets][key])){cache[sets][key][m]=m;count+=1}});return count}).end()};redismock.scard=function(key,callback){return this.ifType(key,"set",callback).thenex(function(){return Object.keys(cache[sets][key]).length}).thennx(function(){return 0}).end()};redismock.sdiff=function(key,callback){var that=this;var g=gather(this.sdiff).apply(this,arguments);callback=g.callback;if(!g.list.every(function(k){return that.type(k)==="set"||that.type(k)==="none"})){return wrongType(callback)}return this.ifType(key,"set",callback).thennx(function(){return[]}).thenex(function(){return g.list.slice(1).reduce(function(set,k){return that.smembers(k).reduce(function(diff,member){var idx=diff.indexOf(member);if(idx!==-1){diff.splice(idx,1)}return diff},set)},this.smembers(g.list[0]))}).end()};redismock.sdiffstore=function(destination,key,callback){var g=gather(this.sdiffstore).apply(this,arguments);var diff=this.sdiff.apply(this,g.list);callback=g.callback;if(diff instanceof Error){return cb(callback)(diff)}if(this.exists(destination)){this.del(destination)}this.sadd.apply(this,[destination].concat(diff));return cb(callback)(null,diff.length)};redismock.sinter=function(key,callback){var that=this;var g=gather(this.sdiff).apply(this,arguments);callback=g.callback;if(!g.list.every(function(k){return that.type(k)==="set"||that.type(k)==="none"})){return wrongType(callback)}return this.ifType(key,"set",callback).thennx(function(){return[]}).thenex(function(){return g.list.slice(1).reduce(function(set,k){return that.smembers(k).filter(function(member){return set.indexOf(member)!==-1})},this.smembers(g.list[0]))}).end()};redismock.sinterstore=function(destination,key,callback){var g=gather(this.sinterstore).apply(this,arguments);var inter=this.sinter.apply(this,g.list);callback=g.callback;if(inter instanceof Error){return cb(callback)(inter)}if(this.exists(destination)){this.del(destination)}this.sadd.apply(this,[destination].concat(inter));return cb(callback)(null,inter.length)};redismock.sismember=function(key,member,callback){return this.ifType(key,"set",callback).thenex(function(){return member in cache[sets][key]?1:0}).thennx(function(){return 0}).end()};redismock.smembers=function(key,callback){return this.ifType(key,"set",callback).thenex(function(){return Object.keys(cache[sets][key])}).thennx(function(){return[]}).end()};redismock.smove=function(source,dest,member,callback){var r,e;r=redismock.srem(source,member);if(r instanceof Error){return cb(callback)(r)}e=redismock.sadd(dest,member);if(e instanceof Error){return cb(callback)(e)}return cb(callback)(null,r)};redismock.spop=function(key,callback){var r;var rando=this.srandmember(key);if(rando instanceof Error){return cb(callback)(rando)}r=this.srem(key,rando);if(r instanceof Error){return cb(callback)(r)}return cb(callback)(null,rando)};redismock.srandmember=function(key,callback){var count;if(arguments.length===2&&typeof callback!=="function"){count=callback;callback=null}if(arguments.length===3){count=callback;callback=arguments[2]}return this.ifType(key,"set",callback).thenex(function(){var k=Object.keys(cache[sets][key]);var idx,randos;if(count===0){return null}if(count){randos=[];for(idx=0;idx=count});return[cursor,arr]}).end()};redismock.zadd=function(key,score,member,callback){var g=gather(this.zadd,3).apply(this,arguments);callback=g.callback;return this.ifType(key,"zset",callback).thennx(function(){cache[zsets][key]={scores:[],set:{}}}).then(function(){var count=0;g.list.map(function(elem,index){if(index%2===0){return[parseFloat(g.list[index]),g.list[index+1]]}return null}).filter(function(elem){return elem!==null}).forEach(function(sm){var score=sm[0];var m=sm[1];var noop=false;if(!cache[zsets][key].set[score]){cache[zsets][key].scores.push(score);cache[zsets][key].set[score]=[]}cache[zsets][key].scores.map(function(score){return[score,cache[zsets][key].set[score].indexOf(m)]}).filter(function(si){return si[1]!==-1}).forEach(function(si){if(si[0]!==score){cache[zsets][key].set[si[0]].splice(si[1],1)}else{noop=true}});if(!noop){cache[zsets][key].set[score].push(m);count+=1}});cache[zsets][key].scores.sort();return count}).end()};redismock.zcard=function(key,callback){return this.ifType(key,"zset",callback).thenex(function(){return cache[zsets][key].scores.reduce(function(cnt,score){return cnt+cache[zsets][key].set[score].length},0)}).thennx(function(){return 0}).end()};redismock.zcount=function(key,min,max,callback){return this.ifType(key,"zset",callback).thenex(function(){var count=cache[zsets][key].scores.filter(function(score){return min<=score&&score<=max}).reduce(function(cnt,score){return cnt+cache[zsets][key].set[score].length},0);return count}).thennx(function(){return 0}).end()};redismock.zincrby=function(key,increment,member,callback){return cb(callback)(new Error("UNIMPLEMENTED"))};redismock.zinterstore=function(destination,numkeys,key,callback){return cb(callback)(new Error("UNIMPLEMENTED"))};redismock.zlexcount=function(key,min,max,callback){return cb(callback)(new Error("UNIMPLEMENTED"))};redismock.zrange=function(key,start,stop,callback){var withscores=false;if(typeof callback!=="function"&&callback==="withscores"){withscores=true;callback=arguments[4]}if(start<0){start=this.zcard(key)+start}if(stop<0){stop=this.zcard(key)+stop}return this.ifType(key,"zset",callback).thenex(function(){var startScoreIdx=0,idx=0;var range=[];cache[zsets][key].scores.some(function(score){if(idx<=start&&idx+cache[zsets][key].set[score].length>start){return true}idx+=cache[zsets][key].set[score].length;startScoreIdx+=1;return false});cache[zsets][key].scores.slice(startScoreIdx).some(function(score){var arr=[];var len=cache[zsets][key].set[score].length;var from=0,to=0;if(idx>stop){return true}while(idx=limitOffset){if(limitCount!==-1){if(arr.length=2){for(idx=1;idx=2){for(idx=1;idx