@upstash/redis 0.0.0-ci.a0519b405e783d33aa4660281b294551474ad898 → 0.0.0-ci.a37d29ff68c6d235b92a2288360dc563c2f31f89-20241021061213

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/nodejs.js CHANGED
@@ -1 +1,3939 @@
1
- "use strict";var be=Object.create;var oe=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var ke=(s,n)=>{for(var t in n)oe(s,t,{get:n[t],enumerable:!0})},ue=(s,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let m of Te(n))!De.call(s,m)&&m!==t&&oe(s,m,{get:()=>n[m],enumerable:!(o=Oe(n,m))||o.enumerable});return s};var he=(s,n,t)=>(t=s!=null?be(we(s)):{},ue(n||!s||!s.__esModule?oe(t,"default",{value:s,enumerable:!0}):t,s)),Ae=s=>ue(oe({},"__esModule",{value:!0}),s);var Pe={};ke(Pe,{Redis:()=>de});module.exports=Ae(Pe);var c=class extends Error{constructor(n){super(n),this.name="UpstashError"}};var se=class{baseUrl;headers;options;retry;constructor(n){this.options={backend:n.options?.backend,agent:n.agent,responseEncoding:n.responseEncoding??"base64",cache:n.cache},this.baseUrl=n.baseUrl.replace(/\/$/,""),this.headers={"Content-Type":"application/json",...n.headers},this.options.responseEncoding==="base64"&&(this.headers["Upstash-Encoding"]="base64"),typeof n?.retry=="boolean"&&n?.retry===!1?this.retry={attempts:1,backoff:()=>0}:this.retry={attempts:n?.retry?.retries??5,backoff:n?.retry?.backoff??(t=>Math.exp(t)*50)}}mergeTelemetry(n){function t(o,m,r){return r&&(o[m]?o[m]=[o[m],r].join(","):o[m]=r),o}this.headers=t(this.headers,"Upstash-Telemetry-Runtime",n.runtime),this.headers=t(this.headers,"Upstash-Telemetry-Platform",n.platform),this.headers=t(this.headers,"Upstash-Telemetry-Sdk",n.sdk)}async request(n){let t={cache:this.options.cache,method:"POST",headers:this.headers,body:JSON.stringify(n.body),keepalive:!0,agent:this.options?.agent,backend:this.options?.backend},o=null,m=null;for(let a=0;a<=this.retry.attempts;a++)try{o=await fetch([this.baseUrl,...n.path??[]].join("/"),t);break}catch(i){m=i,await new Promise(p=>setTimeout(p,this.retry.backoff(a)))}if(!o)throw m??new Error("Exhausted all retries");let r=await o.json();if(!o.ok)throw new c(`${r.error}, command was: ${JSON.stringify(n.body)}`);return this.options?.responseEncoding==="base64"?Array.isArray(r)?r.map(({result:i,error:p})=>({result:pe(i),error:p})):{result:pe(r.result),error:r.error}:r}};function le(s){let n="";try{let t=atob(s),o=t.length,m=new Uint8Array(o);for(let r=0;r<o;r++)m[r]=t.charCodeAt(r);n=new TextDecoder().decode(m)}catch{n=s}return n}function pe(s){let n;switch(typeof s){case"undefined":return s;case"number":{n=s;break}case"object":{Array.isArray(s)?n=s.map(t=>typeof t=="string"?le(t):Array.isArray(t)?t.map(pe):t):n=null;break}case"string":{n=s==="OK"?"OK":le(s);break}default:break}return n}function Ce(s){let n=Array.isArray(s)?s.map(t=>{try{return Ce(t)}catch{return t}}):JSON.parse(s);return typeof n=="number"&&n.toString()!==s?s:n}function ge(s){try{return Ce(s)}catch{return s}}var Se=s=>{switch(typeof s){case"string":case"number":case"boolean":return s;default:return JSON.stringify(s)}},e=class{command;serialize;deserialize;constructor(n,t){this.serialize=Se,this.deserialize=typeof t?.automaticDeserialization>"u"||t.automaticDeserialization?t?.deserialize??ge:o=>o,this.command=n.map(o=>this.serialize(o))}async exec(n){let{result:t,error:o}=await n.request({body:this.command});if(o)throw new c(o);if(typeof t>"u")throw new Error("Request did not return a result");return this.deserialize(t)}};var l=class extends e{constructor(n,t){super(["append",...n],t)}};var C=class extends e{constructor([n,t,o],m){let r=["bitcount",n];typeof t=="number"&&r.push(t),typeof o=="number"&&r.push(o),super(r,m)}};var g=class extends e{constructor(n,t){super(["bitop",...n],t)}};var x=class extends e{constructor(n,t){super(["bitpos",...n],t)}};var f=class extends e{constructor([n,t,o],m){super(["COPY",n,t,...o?.replace?["REPLACE"]:[]],{...m,deserialize(r){return r>0?"COPIED":"NOT_COPIED"}})}};var y=class extends e{constructor(n){super(["dbsize"],n)}};var b=class extends e{constructor(n,t){super(["decr",...n],t)}};var O=class extends e{constructor(n,t){super(["decrby",...n],t)}};var T=class extends e{constructor(n,t){super(["del",...n],t)}};var w=class extends e{constructor(n,t){super(["echo",...n],t)}};var D=class extends e{constructor([n,t,o],m){super(["eval",n,t.length,...t,...o??[]],m)}};var k=class extends e{constructor([n,t,o],m){super(["evalsha",n,t.length,...t,...o??[]],m)}};var A=class extends e{constructor(n,t){super(["exists",...n],t)}};var S=class extends e{constructor(n,t){super(["expire",...n],t)}};var R=class extends e{constructor(n,t){super(["expireat",...n],t)}};var v=class extends e{constructor(n,t){let o=["flushall"];n&&n.length>0&&n[0].async&&o.push("async"),super(o,t)}};var M=class extends e{constructor([n],t){let o=["flushdb"];n?.async&&o.push("async"),super(o,t)}};var E=class extends e{constructor([n,t,...o],m){let r=["geoadd",n];"nx"in t&&t.nx?r.push("nx"):"xx"in t&&t.xx&&r.push("xx"),"ch"in t&&t.ch&&r.push("ch"),"latitude"in t&&t.latitude&&r.push(t.longitude,t.latitude,t.member),r.push(...o.flatMap(({latitude:a,longitude:i,member:p})=>[i,a,p])),super(r,m)}};var z=class extends e{constructor([n,t,o,m="M"],r){super(["GEODIST",n,t,o,m],r)}};var I=class extends e{constructor(n,t){let[o]=n,m=Array.isArray(n[1])?n[1]:n.slice(1);super(["GEOPOS",o,...m],{deserialize:r=>Re(r),...t})}};function Re(s){let n=[];for(let t of s)!t?.[0]||!t?.[1]||n.push({lng:parseFloat(t[0]),lat:parseFloat(t[1])});return n}var P=class extends e{constructor(n,t){let[o]=n,m=Array.isArray(n[1])?n[1]:n.slice(1);super(["GEOHASH",o,...m],t)}};var J=class extends e{constructor([n,t,o,m,r],a){let i=["GEOSEARCH",n];(t.type==="FROMMEMBER"||t.type==="frommember")&&i.push(t.type,t.member),(t.type==="FROMLONLAT"||t.type==="fromlonlat")&&i.push(t.type,t.coordinate.lon,t.coordinate.lat),(o.type==="BYRADIUS"||o.type==="byradius")&&i.push(o.type,o.radius,o.radiusType),(o.type==="BYBOX"||o.type==="bybox")&&i.push(o.type,o.rect.width,o.rect.height,o.rectType),i.push(m),r?.count&&i.push(r.count.limit,...r.count.any?["ANY"]:[]);let p=ce=>!r?.withCoord&&!r?.withDist&&!r?.withHash?ce.map(d=>{try{return{member:JSON.parse(d)}}catch{return{member:d}}}):ce.map(d=>{let ee=1,h={};try{h.member=JSON.parse(d[0])}catch{h.member=d[0]}return r.withDist&&(h.dist=parseFloat(d[ee++])),r.withHash&&(h.hash=d[ee++].toString()),r.withCoord&&(h.coord={long:parseFloat(d[ee][0]),lat:parseFloat(d[ee][1])}),h});super([...i,...r?.withCoord?["WITHCOORD"]:[],...r?.withDist?["WITHDIST"]:[],...r?.withHash?["WITHHASH"]:[]],{...a,deserialize:p})}};var L=class extends e{constructor([n,t,o,m,r,a],i){let p=["GEOSEARCHSTORE",n,t];(o.type==="FROMMEMBER"||o.type==="frommember")&&p.push(o.type,o.member),(o.type==="FROMLONLAT"||o.type==="fromlonlat")&&p.push(o.type,o.coordinate.lon,o.coordinate.lat),(m.type==="BYRADIUS"||m.type==="byradius")&&p.push(m.type,m.radius,m.radiusType),(m.type==="BYBOX"||m.type==="bybox")&&p.push(m.type,m.rect.width,m.rect.height,m.rectType),p.push(r),a?.count&&p.push(a.count.limit,...a.count.any?["ANY"]:[]),super([...p,...a?.storeDist?["STOREDIST"]:[]],i)}};var N=class extends e{constructor(n,t){super(["get",...n],t)}};var K=class extends e{constructor(n,t){super(["getbit",...n],t)}};var Z=class extends e{constructor(n,t){super(["getdel",...n],t)}};var G=class extends e{constructor(n,t){super(["getrange",...n],t)}};var U=class extends e{constructor(n,t){super(["getset",...n],t)}};var B=class extends e{constructor(n,t){super(["hdel",...n],t)}};var H=class extends e{constructor(n,t){super(["hexists",...n],t)}};var F=class extends e{constructor(n,t){super(["hget",...n],t)}};function ve(s){if(s.length===0)return null;let n={};for(;s.length>=2;){let t=s.shift(),o=s.shift();try{!Number.isNaN(Number(o))&&!Number.isSafeInteger(o)?n[t]=o:n[t]=JSON.parse(o)}catch{n[t]=o}}return n}var $=class extends e{constructor(n,t){super(["hgetall",...n],{deserialize:o=>ve(o),...t})}};var q=class extends e{constructor(n,t){super(["hincrby",...n],t)}};var j=class extends e{constructor(n,t){super(["hincrbyfloat",...n],t)}};var X=class extends e{constructor([n],t){super(["hkeys",n],t)}};var W=class extends e{constructor(n,t){super(["hlen",...n],t)}};function Me(s,n){if(n.length===0||n.every(o=>o===null))return null;let t={};for(let o=0;o<s.length;o++)try{t[s[o]]=JSON.parse(n[o])}catch{t[s[o]]=n[o]}return t}var _=class extends e{constructor([n,...t],o){super(["hmget",n,...t],{deserialize:m=>Me(t,m),...o})}};var Y=class extends e{constructor([n,t],o){super(["hmset",n,...Object.entries(t).flatMap(([m,r])=>[m,r])],o)}};function Ee(s){if(s.length===0)return null;let n={};for(;s.length>=2;){let t=s.shift(),o=s.shift();try{n[t]=JSON.parse(o)}catch{n[t]=o}}return n}var V=class extends e{constructor(n,t){let o=["hrandfield",n[0]];typeof n[1]=="number"&&o.push(n[1]),n[2]&&o.push("WITHVALUES"),super(o,{deserialize:n[2]?m=>Ee(m):t?.deserialize,...t})}};var Q=class extends e{constructor([n,t,o],m){let r=["hscan",n,t];o?.match&&r.push("match",o.match),typeof o?.count=="number"&&r.push("count",o.count),super(r,m)}};var nn=class extends e{constructor([n,t],o){super(["hset",n,...Object.entries(t).flatMap(([m,r])=>[m,r])],o)}};var tn=class extends e{constructor(n,t){super(["hsetnx",...n],t)}};var en=class extends e{constructor(n,t){super(["hstrlen",...n],t)}};var on=class extends e{constructor(n,t){super(["hvals",...n],t)}};var sn=class extends e{constructor(n,t){super(["incr",...n],t)}};var mn=class extends e{constructor(n,t){super(["incrby",...n],t)}};var rn=class extends e{constructor(n,t){super(["incrbyfloat",...n],t)}};var an=class extends e{constructor(n,t){super(["JSON.ARRAPPEND",...n],t)}};var pn=class extends e{constructor(n,t){super(["JSON.ARRINDEX",...n],t)}};var dn=class extends e{constructor(n,t){super(["JSON.ARRINSERT",...n],t)}};var cn=class extends e{constructor(n,t){super(["JSON.ARRLEN",n[0],n[1]??"$"],t)}};var un=class extends e{constructor(n,t){super(["JSON.ARRPOP",...n],t)}};var hn=class extends e{constructor(n,t){let o=n[1]??"$",m=n[2]??0,r=n[3]??0;super(["JSON.ARRTRIM",n[0],o,m,r],t)}};var ln=class extends e{constructor(n,t){super(["JSON.CLEAR",...n],t)}};var Cn=class extends e{constructor(n,t){super(["JSON.DEL",...n],t)}};var gn=class extends e{constructor(n,t){super(["JSON.FORGET",...n],t)}};var xn=class extends e{constructor(n,t){let o=["JSON.GET"];typeof n[1]=="string"?o.push(...n):(o.push(n[0]),n[1]&&(n[1].indent&&o.push("INDENT",n[1].indent),n[1].newline&&o.push("NEWLINE",n[1].newline),n[1].space&&o.push("SPACE",n[1].space)),o.push(...n.slice(2))),super(o,t)}};var fn=class extends e{constructor(n,t){super(["JSON.MGET",...n[0],n[1]],t)}};var yn=class extends e{constructor(n,t){super(["JSON.NUMINCRBY",...n],t)}};var bn=class extends e{constructor(n,t){super(["JSON.NUMMULTBY",...n],t)}};var On=class extends e{constructor(n,t){super(["JSON.OBJKEYS",...n],t)}};var Tn=class extends e{constructor(n,t){super(["JSON.OBJLEN",...n],t)}};var wn=class extends e{constructor(n,t){super(["JSON.RESP",...n],t)}};var Dn=class extends e{constructor(n,t){let o=["JSON.SET",n[0],n[1],n[2]];n[3]&&(n[3].nx?o.push("NX"):n[3].xx&&o.push("XX")),super(o,t)}};var kn=class extends e{constructor(n,t){super(["JSON.STRAPPEND",...n],t)}};var An=class extends e{constructor(n,t){super(["JSON.STRLEN",...n],t)}};var Sn=class extends e{constructor(n,t){super(["JSON.TOGGLE",...n],t)}};var Rn=class extends e{constructor(n,t){super(["JSON.TYPE",...n],t)}};var vn=class extends e{constructor(n,t){super(["keys",...n],t)}};var Mn=class extends e{constructor(n,t){super(["lindex",...n],t)}};var En=class extends e{constructor(n,t){super(["linsert",...n],t)}};var zn=class extends e{constructor(n,t){super(["llen",...n],t)}};var In=class extends e{constructor(n,t){super(["lmove",...n],t)}};var Pn=class extends e{constructor(n,t){super(["lpop",...n],t)}};var Jn=class extends e{constructor(n,t){let o=["lpos",n[0],n[1]];typeof n[2]?.rank=="number"&&o.push("rank",n[2].rank),typeof n[2]?.count=="number"&&o.push("count",n[2].count),typeof n[2]?.maxLen=="number"&&o.push("maxLen",n[2].maxLen),super(o,t)}};var Ln=class extends e{constructor(n,t){super(["lpush",...n],t)}};var Nn=class extends e{constructor(n,t){super(["lpushx",...n],t)}};var Kn=class extends e{constructor(n,t){super(["lrange",...n],t)}};var Zn=class extends e{constructor(n,t){super(["lrem",...n],t)}};var Gn=class extends e{constructor(n,t){super(["lset",...n],t)}};var Un=class extends e{constructor(n,t){super(["ltrim",...n],t)}};var Bn=class extends e{constructor(n,t){let o=Array.isArray(n[0])?n[0]:n;super(["mget",...o],t)}};var Hn=class extends e{constructor([n],t){super(["mset",...Object.entries(n).flatMap(([o,m])=>[o,m])],t)}};var Fn=class extends e{constructor([n],t){super(["msetnx",...Object.entries(n).flatMap(o=>o)],t)}};var $n=class extends e{constructor(n,t){super(["persist",...n],t)}};var qn=class extends e{constructor(n,t){super(["pexpire",...n],t)}};var jn=class extends e{constructor(n,t){super(["pexpireat",...n],t)}};var Xn=class extends e{constructor(n,t){let o=["ping"];typeof n<"u"&&typeof n[0]<"u"&&o.push(n[0]),super(o,t)}};var Wn=class extends e{constructor(n,t){super(["psetex",...n],t)}};var _n=class extends e{constructor(n,t){super(["pttl",...n],t)}};var Yn=class extends e{constructor(n,t){super(["publish",...n],t)}};var Vn=class extends e{constructor(n){super(["randomkey"],n)}};var Qn=class extends e{constructor(n,t){super(["rename",...n],t)}};var nt=class extends e{constructor(n,t){super(["renamenx",...n],t)}};var tt=class extends e{constructor(n,t){super(["rpop",...n],t)}};var et=class extends e{constructor(n,t){super(["rpush",...n],t)}};var ot=class extends e{constructor(n,t){super(["rpushx",...n],t)}};var st=class extends e{constructor(n,t){super(["sadd",...n],t)}};var mt=class extends e{constructor([n,t],o){let m=["scan",n];t?.match&&m.push("match",t.match),typeof t?.count=="number"&&m.push("count",t.count),t?.type&&t.type.length>0&&m.push("type",t.type),super(m,o)}};var rt=class extends e{constructor(n,t){super(["scard",...n],t)}};var at=class extends e{constructor(n,t){super(["script","exists",...n],{deserialize:o=>o,...t})}};var it=class extends e{constructor([n],t){let o=["script","flush"];n?.sync?o.push("sync"):n?.async&&o.push("async"),super(o,t)}};var pt=class extends e{constructor(n,t){super(["script","load",...n],t)}};var dt=class extends e{constructor(n,t){super(["sdiff",...n],t)}};var ct=class extends e{constructor(n,t){super(["sdiffstore",...n],t)}};var ut=class extends e{constructor([n,t,o],m){let r=["set",n,t];o&&("nx"in o&&o.nx?r.push("nx"):"xx"in o&&o.xx&&r.push("xx"),"get"in o&&o.get&&r.push("get"),"ex"in o&&typeof o.ex=="number"?r.push("ex",o.ex):"px"in o&&typeof o.px=="number"?r.push("px",o.px):"exat"in o&&typeof o.exat=="number"?r.push("exat",o.exat):"pxat"in o&&typeof o.pxat=="number"?r.push("pxat",o.pxat):"keepTtl"in o&&o.keepTtl&&r.push("keepTtl")),super(r,m)}};var ht=class extends e{constructor(n,t){super(["setbit",...n],t)}};var lt=class extends e{constructor(n,t){super(["setex",...n],t)}};var Ct=class extends e{constructor(n,t){super(["setnx",...n],t)}};var gt=class extends e{constructor(n,t){super(["setrange",...n],t)}};var xt=class extends e{constructor(n,t){super(["sinter",...n],t)}};var ft=class extends e{constructor(n,t){super(["sinterstore",...n],t)}};var yt=class extends e{constructor(n,t){super(["sismember",...n],t)}};var bt=class extends e{constructor(n,t){super(["smembers",...n],t)}};var Ot=class extends e{constructor(n,t){super(["smismember",n[0],...n[1]],t)}};var Tt=class extends e{constructor(n,t){super(["smove",...n],t)}};var wt=class extends e{constructor([n,t],o){let m=["spop",n];typeof t=="number"&&m.push(t),super(m,o)}};var Dt=class extends e{constructor([n,t],o){let m=["srandmember",n];typeof t=="number"&&m.push(t),super(m,o)}};var kt=class extends e{constructor(n,t){super(["srem",...n],t)}};var At=class extends e{constructor([n,t,o],m){let r=["sscan",n,t];o?.match&&r.push("match",o.match),typeof o?.count=="number"&&r.push("count",o.count),super(r,m)}};var St=class extends e{constructor(n,t){super(["strlen",...n],t)}};var Rt=class extends e{constructor(n,t){super(["sunion",...n],t)}};var vt=class extends e{constructor(n,t){super(["sunionstore",...n],t)}};var Mt=class extends e{constructor(n){super(["time"],n)}};var Et=class extends e{constructor(n,t){super(["touch",...n],t)}};var zt=class extends e{constructor(n,t){super(["ttl",...n],t)}};var It=class extends e{constructor(n,t){super(["type",...n],t)}};var Pt=class extends e{constructor(n,t){super(["unlink",...n],t)}};var me=class extends e{constructor([n,t,o,m],r){let a=["XADD",n];m&&(m.nomkStream&&a.push("NOMKSTREAM"),m.trim&&(a.push(m.trim.type,m.trim.comparison,m.trim.threshold),typeof m.trim.limit<"u"&&a.push("LIMIT",m.trim.limit))),a.push(t);for(let[i,p]of Object.entries(o))a.push(i,p);super(a,r)}};function ze(s){let n={};for(let t of s)for(;t.length>=2;){let o=t.shift(),m=t.shift();for((o in n)||(n[o]={});m.length>=2;){let r=m.shift(),a=m.shift();try{n[o][r]=JSON.parse(a)}catch{n[o][r]=a}}}return n}var re=class extends e{constructor([n,t,o,m],r){let a=["XRANGE",n,t,o];typeof m=="number"&&a.push("COUNT",m),super(a,{deserialize:i=>ze(i),...r})}};var u=class extends e{constructor([n,t,...o],m){let r=["zadd",n];"nx"in t&&t.nx?r.push("nx"):"xx"in t&&t.xx&&r.push("xx"),"ch"in t&&t.ch&&r.push("ch"),"incr"in t&&t.incr&&r.push("incr"),"score"in t&&"member"in t&&r.push(t.score,t.member),r.push(...o.flatMap(({score:a,member:i})=>[a,i])),super(r,m)}};var Jt=class extends e{constructor(n,t){super(["zcard",...n],t)}};var Lt=class extends e{constructor(n,t){super(["zcount",...n],t)}};var Nt=class extends e{constructor(n,t){super(["zincrby",...n],t)}};var Kt=class extends e{constructor([n,t,o,m],r){let a=["zinterstore",n,t];Array.isArray(o)?a.push(...o):a.push(o),m&&("weights"in m&&m.weights?a.push("weights",...m.weights):"weight"in m&&typeof m.weight=="number"&&a.push("weights",m.weight),"aggregate"in m&&a.push("aggregate",m.aggregate)),super(a,r)}};var Zt=class extends e{constructor(n,t){super(["zlexcount",...n],t)}};var Gt=class extends e{constructor([n,t],o){let m=["zpopmax",n];typeof t=="number"&&m.push(t),super(m,o)}};var Ut=class extends e{constructor([n,t],o){let m=["zpopmin",n];typeof t=="number"&&m.push(t),super(m,o)}};var Bt=class extends e{constructor([n,t,o,m],r){let a=["zrange",n,t,o];m?.byScore&&a.push("byscore"),m?.byLex&&a.push("bylex"),m?.rev&&a.push("rev"),typeof m?.count<"u"&&typeof m?.offset<"u"&&a.push("limit",m.offset,m.count),m?.withScores&&a.push("withscores"),super(a,r)}};var Ht=class extends e{constructor(n,t){super(["zrank",...n],t)}};var Ft=class extends e{constructor(n,t){super(["zrem",...n],t)}};var $t=class extends e{constructor(n,t){super(["zremrangebylex",...n],t)}};var qt=class extends e{constructor(n,t){super(["zremrangebyrank",...n],t)}};var jt=class extends e{constructor(n,t){super(["zremrangebyscore",...n],t)}};var Xt=class extends e{constructor(n,t){super(["zrevrank",...n],t)}};var Wt=class extends e{constructor([n,t,o],m){let r=["zscan",n,t];o?.match&&r.push("match",o.match),typeof o?.count=="number"&&r.push("count",o.count),super(r,m)}};var _t=class extends e{constructor(n,t){super(["zscore",...n],t)}};var Yt=class extends e{constructor([n,t,o],m){let r=["zunion",n];Array.isArray(t)?r.push(...t):r.push(t),o&&("weights"in o&&o.weights?r.push("weights",...o.weights):"weight"in o&&typeof o.weight=="number"&&r.push("weights",o.weight),"aggregate"in o&&r.push("aggregate",o.aggregate),o?.withScores&&r.push("withscores")),super(r,m)}};var Vt=class extends e{constructor([n,t,o,m],r){let a=["zunionstore",n,t];Array.isArray(o)?a.push(...o):a.push(o),m&&("weights"in m&&m.weights?a.push("weights",...m.weights):"weight"in m&&typeof m.weight=="number"&&a.push("weights",m.weight),"aggregate"in m&&a.push("aggregate",m.aggregate)),super(a,r)}};var Qt=class extends e{constructor(n,t){super(["zdiffstore",...n],t)}};var ne=class extends e{constructor(n,t){let[o,m]=n;super(["zmscore",o,...m],t)}};var te=class{client;commands;commandOptions;multiExec;constructor(n){this.client=n.client,this.commands=[],this.commandOptions=n.commandOptions,this.multiExec=n.multiExec??!1}exec=async()=>{if(this.commands.length===0)throw new Error("Pipeline is empty");let n=this.multiExec?["multi-exec"]:["pipeline"];return(await this.client.request({path:n,body:Object.values(this.commands).map(o=>o.command)})).map(({error:o,result:m},r)=>{if(o)throw new c(`Command ${r+1} [ ${this.commands[r].command[0]} ] failed: ${o}`);return this.commands[r].deserialize(m)})};length(){return this.commands.length}chain(n){return this.commands.push(n),this}append=(...n)=>this.chain(new l(n,this.commandOptions));bitcount=(...n)=>this.chain(new C(n,this.commandOptions));bitop=(n,t,o,...m)=>this.chain(new g([n,t,o,...m],this.commandOptions));bitpos=(...n)=>this.chain(new x(n,this.commandOptions));copy=(...n)=>this.chain(new f(n,this.commandOptions));zdiffstore=(...n)=>this.chain(new Qt(n,this.commandOptions));dbsize=()=>this.chain(new y(this.commandOptions));decr=(...n)=>this.chain(new b(n,this.commandOptions));decrby=(...n)=>this.chain(new O(n,this.commandOptions));del=(...n)=>this.chain(new T(n,this.commandOptions));echo=(...n)=>this.chain(new w(n,this.commandOptions));eval=(...n)=>this.chain(new D(n,this.commandOptions));evalsha=(...n)=>this.chain(new k(n,this.commandOptions));exists=(...n)=>this.chain(new A(n,this.commandOptions));expire=(...n)=>this.chain(new S(n,this.commandOptions));expireat=(...n)=>this.chain(new R(n,this.commandOptions));flushall=n=>this.chain(new v(n,this.commandOptions));flushdb=(...n)=>this.chain(new M(n,this.commandOptions));get=(...n)=>this.chain(new N(n,this.commandOptions));getbit=(...n)=>this.chain(new K(n,this.commandOptions));getdel=(...n)=>this.chain(new Z(n,this.commandOptions));getrange=(...n)=>this.chain(new G(n,this.commandOptions));getset=(n,t)=>this.chain(new U([n,t],this.commandOptions));hdel=(...n)=>this.chain(new B(n,this.commandOptions));hexists=(...n)=>this.chain(new H(n,this.commandOptions));hget=(...n)=>this.chain(new F(n,this.commandOptions));hgetall=(...n)=>this.chain(new $(n,this.commandOptions));hincrby=(...n)=>this.chain(new q(n,this.commandOptions));hincrbyfloat=(...n)=>this.chain(new j(n,this.commandOptions));hkeys=(...n)=>this.chain(new X(n,this.commandOptions));hlen=(...n)=>this.chain(new W(n,this.commandOptions));hmget=(...n)=>this.chain(new _(n,this.commandOptions));hmset=(n,t)=>this.chain(new Y([n,t],this.commandOptions));hrandfield=(n,t,o)=>this.chain(new V([n,t,o],this.commandOptions));hscan=(...n)=>this.chain(new Q(n,this.commandOptions));hset=(n,t)=>this.chain(new nn([n,t],this.commandOptions));hsetnx=(n,t,o)=>this.chain(new tn([n,t,o],this.commandOptions));hstrlen=(...n)=>this.chain(new en(n,this.commandOptions));hvals=(...n)=>this.chain(new on(n,this.commandOptions));incr=(...n)=>this.chain(new sn(n,this.commandOptions));incrby=(...n)=>this.chain(new mn(n,this.commandOptions));incrbyfloat=(...n)=>this.chain(new rn(n,this.commandOptions));keys=(...n)=>this.chain(new vn(n,this.commandOptions));lindex=(...n)=>this.chain(new Mn(n,this.commandOptions));linsert=(n,t,o,m)=>this.chain(new En([n,t,o,m],this.commandOptions));llen=(...n)=>this.chain(new zn(n,this.commandOptions));lmove=(...n)=>this.chain(new In(n,this.commandOptions));lpop=(...n)=>this.chain(new Pn(n,this.commandOptions));lpos=(...n)=>this.chain(new Jn(n,this.commandOptions));lpush=(n,...t)=>this.chain(new Ln([n,...t],this.commandOptions));lpushx=(n,...t)=>this.chain(new Nn([n,...t],this.commandOptions));lrange=(...n)=>this.chain(new Kn(n,this.commandOptions));lrem=(n,t,o)=>this.chain(new Zn([n,t,o],this.commandOptions));lset=(n,t,o)=>this.chain(new Gn([n,t,o],this.commandOptions));ltrim=(...n)=>this.chain(new Un(n,this.commandOptions));mget=(...n)=>this.chain(new Bn(n,this.commandOptions));mset=n=>this.chain(new Hn([n],this.commandOptions));msetnx=n=>this.chain(new Fn([n],this.commandOptions));persist=(...n)=>this.chain(new $n(n,this.commandOptions));pexpire=(...n)=>this.chain(new qn(n,this.commandOptions));pexpireat=(...n)=>this.chain(new jn(n,this.commandOptions));ping=n=>this.chain(new Xn(n,this.commandOptions));psetex=(n,t,o)=>this.chain(new Wn([n,t,o],this.commandOptions));pttl=(...n)=>this.chain(new _n(n,this.commandOptions));publish=(...n)=>this.chain(new Yn(n,this.commandOptions));randomkey=()=>this.chain(new Vn(this.commandOptions));rename=(...n)=>this.chain(new Qn(n,this.commandOptions));renamenx=(...n)=>this.chain(new nt(n,this.commandOptions));rpop=(...n)=>this.chain(new tt(n,this.commandOptions));rpush=(n,...t)=>this.chain(new et([n,...t],this.commandOptions));rpushx=(n,...t)=>this.chain(new ot([n,...t],this.commandOptions));sadd=(n,...t)=>this.chain(new st([n,...t],this.commandOptions));scan=(...n)=>this.chain(new mt(n,this.commandOptions));scard=(...n)=>this.chain(new rt(n,this.commandOptions));scriptExists=(...n)=>this.chain(new at(n,this.commandOptions));scriptFlush=(...n)=>this.chain(new it(n,this.commandOptions));scriptLoad=(...n)=>this.chain(new pt(n,this.commandOptions));sdiff=(...n)=>this.chain(new dt(n,this.commandOptions));sdiffstore=(...n)=>this.chain(new ct(n,this.commandOptions));set=(n,t,o)=>this.chain(new ut([n,t,o],this.commandOptions));setbit=(...n)=>this.chain(new ht(n,this.commandOptions));setex=(n,t,o)=>this.chain(new lt([n,t,o],this.commandOptions));setnx=(n,t)=>this.chain(new Ct([n,t],this.commandOptions));setrange=(...n)=>this.chain(new gt(n,this.commandOptions));sinter=(...n)=>this.chain(new xt(n,this.commandOptions));sinterstore=(...n)=>this.chain(new ft(n,this.commandOptions));sismember=(n,t)=>this.chain(new yt([n,t],this.commandOptions));smembers=(...n)=>this.chain(new bt(n,this.commandOptions));smismember=(n,t)=>this.chain(new Ot([n,t],this.commandOptions));smove=(n,t,o)=>this.chain(new Tt([n,t,o],this.commandOptions));spop=(...n)=>this.chain(new wt(n,this.commandOptions));srandmember=(...n)=>this.chain(new Dt(n,this.commandOptions));srem=(n,...t)=>this.chain(new kt([n,...t],this.commandOptions));sscan=(...n)=>this.chain(new At(n,this.commandOptions));strlen=(...n)=>this.chain(new St(n,this.commandOptions));sunion=(...n)=>this.chain(new Rt(n,this.commandOptions));sunionstore=(...n)=>this.chain(new vt(n,this.commandOptions));time=()=>this.chain(new Mt(this.commandOptions));touch=(...n)=>this.chain(new Et(n,this.commandOptions));ttl=(...n)=>this.chain(new zt(n,this.commandOptions));type=(...n)=>this.chain(new It(n,this.commandOptions));unlink=(...n)=>this.chain(new Pt(n,this.commandOptions));zadd=(...n)=>"score"in n[1]?this.chain(new u([n[0],n[1],...n.slice(2)],this.commandOptions)):this.chain(new u([n[0],n[1],...n.slice(2)],this.commandOptions));zcard=(...n)=>this.chain(new Jt(n,this.commandOptions));zcount=(...n)=>this.chain(new Lt(n,this.commandOptions));zincrby=(n,t,o)=>this.chain(new Nt([n,t,o],this.commandOptions));zinterstore=(...n)=>this.chain(new Kt(n,this.commandOptions));zlexcount=(...n)=>this.chain(new Zt(n,this.commandOptions));zmscore=(...n)=>this.chain(new ne(n,this.commandOptions));zpopmax=(...n)=>this.chain(new Gt(n,this.commandOptions));zpopmin=(...n)=>this.chain(new Ut(n,this.commandOptions));zrange=(...n)=>this.chain(new Bt(n,this.commandOptions));zrank=(n,t)=>this.chain(new Ht([n,t],this.commandOptions));zrem=(n,...t)=>this.chain(new Ft([n,...t],this.commandOptions));zremrangebylex=(...n)=>this.chain(new $t(n,this.commandOptions));zremrangebyrank=(...n)=>this.chain(new qt(n,this.commandOptions));zremrangebyscore=(...n)=>this.chain(new jt(n,this.commandOptions));zrevrank=(n,t)=>this.chain(new Xt([n,t],this.commandOptions));zscan=(...n)=>this.chain(new Wt(n,this.commandOptions));zscore=(n,t)=>this.chain(new _t([n,t],this.commandOptions));zunionstore=(...n)=>this.chain(new Vt(n,this.commandOptions));zunion=(...n)=>this.chain(new Yt(n,this.commandOptions));get json(){return{arrappend:(...n)=>this.chain(new an(n,this.commandOptions)),arrindex:(...n)=>this.chain(new pn(n,this.commandOptions)),arrinsert:(...n)=>this.chain(new dn(n,this.commandOptions)),arrlen:(...n)=>this.chain(new cn(n,this.commandOptions)),arrpop:(...n)=>this.chain(new un(n,this.commandOptions)),arrtrim:(...n)=>this.chain(new hn(n,this.commandOptions)),clear:(...n)=>this.chain(new ln(n,this.commandOptions)),del:(...n)=>this.chain(new Cn(n,this.commandOptions)),forget:(...n)=>this.chain(new gn(n,this.commandOptions)),geoadd:(...n)=>this.chain(new E(n,this.commandOptions)),geodist:(...n)=>this.chain(new z(n,this.commandOptions)),geopos:(...n)=>this.chain(new I(n,this.commandOptions)),geohash:(...n)=>this.chain(new P(n,this.commandOptions)),geosearch:(...n)=>this.chain(new J(n,this.commandOptions)),geosearchstore:(...n)=>this.chain(new L(n,this.commandOptions)),get:(...n)=>this.chain(new xn(n,this.commandOptions)),mget:(...n)=>this.chain(new fn(n,this.commandOptions)),numincrby:(...n)=>this.chain(new yn(n,this.commandOptions)),nummultby:(...n)=>this.chain(new bn(n,this.commandOptions)),objkeys:(...n)=>this.chain(new On(n,this.commandOptions)),objlen:(...n)=>this.chain(new Tn(n,this.commandOptions)),resp:(...n)=>this.chain(new wn(n,this.commandOptions)),set:(...n)=>this.chain(new Dn(n,this.commandOptions)),strappend:(...n)=>this.chain(new kn(n,this.commandOptions)),strlen:(...n)=>this.chain(new An(n,this.commandOptions)),toggle:(...n)=>this.chain(new Sn(n,this.commandOptions)),type:(...n)=>this.chain(new Rn(n,this.commandOptions))}}};var xe=he(require("crypto-js/enc-hex")),fe=he(require("crypto-js/sha1")),ae=class{script;sha1;redis;constructor(n,t){this.redis=n,this.sha1=this.digest(t),this.script=t}async eval(n,t){return await this.redis.eval(this.script,n,t)}async evalsha(n,t){return await this.redis.evalsha(this.sha1,n,t)}async exec(n,t){return await this.redis.evalsha(this.sha1,n,t).catch(async m=>{if(m instanceof Error&&m.message.toLowerCase().includes("noscript"))return await this.redis.eval(this.script,n,t);throw m})}digest(n){return xe.default.stringify((0,fe.default)(n))}};var ie=class{client;opts;enableTelemetry;constructor(n,t){this.client=n,this.opts=t,this.enableTelemetry=t?.enableTelemetry??!0}get json(){return{arrappend:(...n)=>new an(n,this.opts).exec(this.client),arrindex:(...n)=>new pn(n,this.opts).exec(this.client),arrinsert:(...n)=>new dn(n,this.opts).exec(this.client),arrlen:(...n)=>new cn(n,this.opts).exec(this.client),arrpop:(...n)=>new un(n,this.opts).exec(this.client),arrtrim:(...n)=>new hn(n,this.opts).exec(this.client),clear:(...n)=>new ln(n,this.opts).exec(this.client),del:(...n)=>new Cn(n,this.opts).exec(this.client),forget:(...n)=>new gn(n,this.opts).exec(this.client),geoadd:(...n)=>new E(n,this.opts).exec(this.client),geopos:(...n)=>new I(n,this.opts).exec(this.client),geodist:(...n)=>new z(n,this.opts).exec(this.client),geohash:(...n)=>new P(n,this.opts).exec(this.client),geosearch:(...n)=>new J(n,this.opts).exec(this.client),geosearchstore:(...n)=>new L(n,this.opts).exec(this.client),get:(...n)=>new xn(n,this.opts).exec(this.client),mget:(...n)=>new fn(n,this.opts).exec(this.client),numincrby:(...n)=>new yn(n,this.opts).exec(this.client),nummultby:(...n)=>new bn(n,this.opts).exec(this.client),objkeys:(...n)=>new On(n,this.opts).exec(this.client),objlen:(...n)=>new Tn(n,this.opts).exec(this.client),resp:(...n)=>new wn(n,this.opts).exec(this.client),set:(...n)=>new Dn(n,this.opts).exec(this.client),strappend:(...n)=>new kn(n,this.opts).exec(this.client),strlen:(...n)=>new An(n,this.opts).exec(this.client),toggle:(...n)=>new Sn(n,this.opts).exec(this.client),type:(...n)=>new Rn(n,this.opts).exec(this.client)}}use=n=>{let t=this.client.request.bind(this.client);this.client.request=o=>n(o,t)};addTelemetry=n=>{if(this.enableTelemetry)try{this.client.mergeTelemetry(n)}catch{}};createScript(n){return new ae(this,n)}pipeline=()=>new te({client:this.client,commandOptions:this.opts,multiExec:!1});multi=()=>new te({client:this.client,commandOptions:this.opts,multiExec:!0});append=(...n)=>new l(n,this.opts).exec(this.client);bitcount=(...n)=>new C(n,this.opts).exec(this.client);bitop=(n,t,o,...m)=>new g([n,t,o,...m],this.opts).exec(this.client);bitpos=(...n)=>new x(n,this.opts).exec(this.client);copy=(...n)=>new f(n,this.opts).exec(this.client);dbsize=()=>new y(this.opts).exec(this.client);decr=(...n)=>new b(n,this.opts).exec(this.client);decrby=(...n)=>new O(n,this.opts).exec(this.client);del=(...n)=>new T(n,this.opts).exec(this.client);echo=(...n)=>new w(n,this.opts).exec(this.client);eval=(...n)=>new D(n,this.opts).exec(this.client);evalsha=(...n)=>new k(n,this.opts).exec(this.client);exists=(...n)=>new A(n,this.opts).exec(this.client);expire=(...n)=>new S(n,this.opts).exec(this.client);expireat=(...n)=>new R(n,this.opts).exec(this.client);flushall=n=>new v(n,this.opts).exec(this.client);flushdb=(...n)=>new M(n,this.opts).exec(this.client);get=(...n)=>new N(n,this.opts).exec(this.client);getbit=(...n)=>new K(n,this.opts).exec(this.client);getdel=(...n)=>new Z(n,this.opts).exec(this.client);getrange=(...n)=>new G(n,this.opts).exec(this.client);getset=(n,t)=>new U([n,t],this.opts).exec(this.client);hdel=(...n)=>new B(n,this.opts).exec(this.client);hexists=(...n)=>new H(n,this.opts).exec(this.client);hget=(...n)=>new F(n,this.opts).exec(this.client);hgetall=(...n)=>new $(n,this.opts).exec(this.client);hincrby=(...n)=>new q(n,this.opts).exec(this.client);hincrbyfloat=(...n)=>new j(n,this.opts).exec(this.client);hkeys=(...n)=>new X(n,this.opts).exec(this.client);hlen=(...n)=>new W(n,this.opts).exec(this.client);hmget=(...n)=>new _(n,this.opts).exec(this.client);hmset=(n,t)=>new Y([n,t],this.opts).exec(this.client);hrandfield=(n,t,o)=>new V([n,t,o],this.opts).exec(this.client);hscan=(...n)=>new Q(n,this.opts).exec(this.client);hset=(n,t)=>new nn([n,t],this.opts).exec(this.client);hsetnx=(n,t,o)=>new tn([n,t,o],this.opts).exec(this.client);hstrlen=(...n)=>new en(n,this.opts).exec(this.client);hvals=(...n)=>new on(n,this.opts).exec(this.client);incr=(...n)=>new sn(n,this.opts).exec(this.client);incrby=(...n)=>new mn(n,this.opts).exec(this.client);incrbyfloat=(...n)=>new rn(n,this.opts).exec(this.client);keys=(...n)=>new vn(n,this.opts).exec(this.client);lindex=(...n)=>new Mn(n,this.opts).exec(this.client);linsert=(n,t,o,m)=>new En([n,t,o,m],this.opts).exec(this.client);llen=(...n)=>new zn(n,this.opts).exec(this.client);lmove=(...n)=>new In(n,this.opts).exec(this.client);lpop=(...n)=>new Pn(n,this.opts).exec(this.client);lpos=(...n)=>new Jn(n,this.opts).exec(this.client);lpush=(n,...t)=>new Ln([n,...t],this.opts).exec(this.client);lpushx=(n,...t)=>new Nn([n,...t],this.opts).exec(this.client);lrange=(...n)=>new Kn(n,this.opts).exec(this.client);lrem=(n,t,o)=>new Zn([n,t,o],this.opts).exec(this.client);lset=(n,t,o)=>new Gn([n,t,o],this.opts).exec(this.client);ltrim=(...n)=>new Un(n,this.opts).exec(this.client);mget=(...n)=>new Bn(n,this.opts).exec(this.client);mset=n=>new Hn([n],this.opts).exec(this.client);msetnx=n=>new Fn([n],this.opts).exec(this.client);persist=(...n)=>new $n(n,this.opts).exec(this.client);pexpire=(...n)=>new qn(n,this.opts).exec(this.client);pexpireat=(...n)=>new jn(n,this.opts).exec(this.client);ping=n=>new Xn(n,this.opts).exec(this.client);psetex=(n,t,o)=>new Wn([n,t,o],this.opts).exec(this.client);pttl=(...n)=>new _n(n,this.opts).exec(this.client);publish=(...n)=>new Yn(n,this.opts).exec(this.client);randomkey=()=>new Vn().exec(this.client);rename=(...n)=>new Qn(n,this.opts).exec(this.client);renamenx=(...n)=>new nt(n,this.opts).exec(this.client);rpop=(...n)=>new tt(n,this.opts).exec(this.client);rpush=(n,...t)=>new et([n,...t],this.opts).exec(this.client);rpushx=(n,...t)=>new ot([n,...t],this.opts).exec(this.client);sadd=(n,...t)=>new st([n,...t],this.opts).exec(this.client);scan=(...n)=>new mt(n,this.opts).exec(this.client);scard=(...n)=>new rt(n,this.opts).exec(this.client);scriptExists=(...n)=>new at(n,this.opts).exec(this.client);scriptFlush=(...n)=>new it(n,this.opts).exec(this.client);scriptLoad=(...n)=>new pt(n,this.opts).exec(this.client);sdiff=(...n)=>new dt(n,this.opts).exec(this.client);sdiffstore=(...n)=>new ct(n,this.opts).exec(this.client);set=(n,t,o)=>new ut([n,t,o],this.opts).exec(this.client);setbit=(...n)=>new ht(n,this.opts).exec(this.client);setex=(n,t,o)=>new lt([n,t,o],this.opts).exec(this.client);setnx=(n,t)=>new Ct([n,t],this.opts).exec(this.client);setrange=(...n)=>new gt(n,this.opts).exec(this.client);sinter=(...n)=>new xt(n,this.opts).exec(this.client);sinterstore=(...n)=>new ft(n,this.opts).exec(this.client);sismember=(n,t)=>new yt([n,t],this.opts).exec(this.client);smismember=(n,t)=>new Ot([n,t],this.opts).exec(this.client);smembers=(...n)=>new bt(n,this.opts).exec(this.client);smove=(n,t,o)=>new Tt([n,t,o],this.opts).exec(this.client);spop=(...n)=>new wt(n,this.opts).exec(this.client);srandmember=(...n)=>new Dt(n,this.opts).exec(this.client);srem=(n,...t)=>new kt([n,...t],this.opts).exec(this.client);sscan=(...n)=>new At(n,this.opts).exec(this.client);strlen=(...n)=>new St(n,this.opts).exec(this.client);sunion=(...n)=>new Rt(n,this.opts).exec(this.client);sunionstore=(...n)=>new vt(n,this.opts).exec(this.client);time=()=>new Mt().exec(this.client);touch=(...n)=>new Et(n,this.opts).exec(this.client);ttl=(...n)=>new zt(n,this.opts).exec(this.client);type=(...n)=>new It(n,this.opts).exec(this.client);unlink=(...n)=>new Pt(n,this.opts).exec(this.client);xadd=(...n)=>new me(n,this.opts).exec(this.client);xrange=(...n)=>new re(n,this.opts).exec(this.client);zadd=(...n)=>"score"in n[1]?new u([n[0],n[1],...n.slice(2)],this.opts).exec(this.client):new u([n[0],n[1],...n.slice(2)],this.opts).exec(this.client);zcard=(...n)=>new Jt(n,this.opts).exec(this.client);zcount=(...n)=>new Lt(n,this.opts).exec(this.client);zdiffstore=(...n)=>new Qt(n,this.opts).exec(this.client);zincrby=(n,t,o)=>new Nt([n,t,o],this.opts).exec(this.client);zinterstore=(...n)=>new Kt(n,this.opts).exec(this.client);zlexcount=(...n)=>new Zt(n,this.opts).exec(this.client);zmscore=(...n)=>new ne(n,this.opts).exec(this.client);zpopmax=(...n)=>new Gt(n,this.opts).exec(this.client);zpopmin=(...n)=>new Ut(n,this.opts).exec(this.client);zrange=(...n)=>new Bt(n,this.opts).exec(this.client);zrank=(n,t)=>new Ht([n,t],this.opts).exec(this.client);zrem=(n,...t)=>new Ft([n,...t],this.opts).exec(this.client);zremrangebylex=(...n)=>new $t(n,this.opts).exec(this.client);zremrangebyrank=(...n)=>new qt(n,this.opts).exec(this.client);zremrangebyscore=(...n)=>new jt(n,this.opts).exec(this.client);zrevrank=(n,t)=>new Xt([n,t],this.opts).exec(this.client);zscan=(...n)=>new Wt(n,this.opts).exec(this.client);zscore=(n,t)=>new _t([n,t],this.opts).exec(this.client);zunion=(...n)=>new Yt(n,this.opts).exec(this.client);zunionstore=(...n)=>new Vt(n,this.opts).exec(this.client)};var ye="v0.0.0-ci.a0519b405e783d33aa4660281b294551474ad898";typeof atob>"u"&&(global.atob=function(s){return Buffer.from(s,"base64").toString("utf-8")});var de=class s extends ie{constructor(n){if("request"in n){super(n);return}(n.url.startsWith(" ")||n.url.endsWith(" ")||/\r|\n/.test(n.url))&&console.warn("The redis url contains whitespace or newline, which can cause errors!"),(n.token.startsWith(" ")||n.token.endsWith(" ")||/\r|\n/.test(n.token))&&console.warn("The redis token contains whitespace or newline, which can cause errors!");let t=new se({baseUrl:n.url,retry:n.retry,headers:{authorization:`Bearer ${n.token}`},agent:n.agent,responseEncoding:n.responseEncoding,cache:n.cache||"no-store"});super(t,{automaticDeserialization:n.automaticDeserialization,enableTelemetry:!process.env.UPSTASH_DISABLE_TELEMETRY}),this.addTelemetry({runtime:typeof EdgeRuntime=="string"?"edge-light":`node@${process.version}`,platform:process.env.VERCEL?"vercel":process.env.AWS_REGION?"aws":"unknown",sdk:`@upstash/redis@${ye}`})}static fromEnv(n){if(typeof process?.env>"u")throw new Error('Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please import from "@upstash/redis/cloudflare" instead');let t=process?.env.UPSTASH_REDIS_REST_URL;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");let o=process?.env.UPSTASH_REDIS_REST_TOKEN;if(!o)throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");return new s({...n,url:t,token:o})}};0&&(module.exports={Redis});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // platforms/nodejs.ts
31
+ var nodejs_exports = {};
32
+ __export(nodejs_exports, {
33
+ Redis: () => Redis2,
34
+ errors: () => error_exports
35
+ });
36
+ module.exports = __toCommonJS(nodejs_exports);
37
+
38
+ // pkg/error.ts
39
+ var error_exports = {};
40
+ __export(error_exports, {
41
+ UpstashError: () => UpstashError,
42
+ UrlError: () => UrlError
43
+ });
44
+ var UpstashError = class extends Error {
45
+ constructor(message) {
46
+ super(message);
47
+ this.name = "UpstashError";
48
+ }
49
+ };
50
+ var UrlError = class extends Error {
51
+ constructor(url) {
52
+ super(
53
+ `Upstash Redis client was passed an invalid URL. You should pass a URL starting with https. Received: "${url}". `
54
+ );
55
+ this.name = "UrlError";
56
+ }
57
+ };
58
+
59
+ // pkg/http.ts
60
+ var HttpClient = class {
61
+ baseUrl;
62
+ headers;
63
+ options;
64
+ readYourWrites;
65
+ upstashSyncToken = "";
66
+ hasCredentials;
67
+ retry;
68
+ constructor(config) {
69
+ this.options = {
70
+ backend: config.options?.backend,
71
+ agent: config.agent,
72
+ responseEncoding: config.responseEncoding ?? "base64",
73
+ // default to base64
74
+ cache: config.cache,
75
+ signal: config.signal,
76
+ keepAlive: config.keepAlive ?? true
77
+ };
78
+ this.upstashSyncToken = "";
79
+ this.readYourWrites = config.readYourWrites ?? true;
80
+ this.baseUrl = (config.baseUrl || "").replace(/\/$/, "");
81
+ const urlRegex = /^https?:\/\/[^\s#$./?].\S*$/;
82
+ if (this.baseUrl && !urlRegex.test(this.baseUrl)) {
83
+ throw new UrlError(this.baseUrl);
84
+ }
85
+ this.headers = {
86
+ "Content-Type": "application/json",
87
+ ...config.headers
88
+ };
89
+ this.hasCredentials = Boolean(this.baseUrl && this.headers.authorization.split(" ")[1]);
90
+ if (this.options.responseEncoding === "base64") {
91
+ this.headers["Upstash-Encoding"] = "base64";
92
+ }
93
+ this.retry = typeof config.retry === "boolean" && !config.retry ? {
94
+ attempts: 1,
95
+ backoff: () => 0
96
+ } : {
97
+ attempts: config.retry?.retries ?? 5,
98
+ backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
99
+ };
100
+ }
101
+ mergeTelemetry(telemetry) {
102
+ this.headers = merge(this.headers, "Upstash-Telemetry-Runtime", telemetry.runtime);
103
+ this.headers = merge(this.headers, "Upstash-Telemetry-Platform", telemetry.platform);
104
+ this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk);
105
+ }
106
+ async request(req) {
107
+ const requestOptions = {
108
+ //@ts-expect-error this should throw due to bun regression
109
+ cache: this.options.cache,
110
+ method: "POST",
111
+ headers: this.headers,
112
+ body: JSON.stringify(req.body),
113
+ keepalive: this.options.keepAlive,
114
+ agent: this.options.agent,
115
+ signal: this.options.signal,
116
+ /**
117
+ * Fastly specific
118
+ */
119
+ backend: this.options.backend
120
+ };
121
+ if (!this.hasCredentials) {
122
+ console.warn(
123
+ "[Upstash Redis] Redis client was initialized without url or token. Failed to execute command."
124
+ );
125
+ }
126
+ if (this.readYourWrites) {
127
+ const newHeader = this.upstashSyncToken;
128
+ this.headers["upstash-sync-token"] = newHeader;
129
+ }
130
+ let res = null;
131
+ let error = null;
132
+ for (let i = 0; i <= this.retry.attempts; i++) {
133
+ try {
134
+ res = await fetch([this.baseUrl, ...req.path ?? []].join("/"), requestOptions);
135
+ break;
136
+ } catch (error_) {
137
+ if (this.options.signal?.aborted) {
138
+ const myBlob = new Blob([
139
+ JSON.stringify({ result: this.options.signal.reason ?? "Aborted" })
140
+ ]);
141
+ const myOptions = {
142
+ status: 200,
143
+ statusText: this.options.signal.reason ?? "Aborted"
144
+ };
145
+ res = new Response(myBlob, myOptions);
146
+ break;
147
+ }
148
+ error = error_;
149
+ await new Promise((r) => setTimeout(r, this.retry.backoff(i)));
150
+ }
151
+ }
152
+ if (!res) {
153
+ throw error ?? new Error("Exhausted all retries");
154
+ }
155
+ const body = await res.json();
156
+ if (!res.ok) {
157
+ throw new UpstashError(`${body.error}, command was: ${JSON.stringify(req.body)}`);
158
+ }
159
+ if (this.readYourWrites) {
160
+ const headers = res.headers;
161
+ this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
162
+ }
163
+ if (this.readYourWrites) {
164
+ const headers = res.headers;
165
+ this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
166
+ }
167
+ if (this.options.responseEncoding === "base64") {
168
+ if (Array.isArray(body)) {
169
+ return body.map(({ result: result2, error: error2 }) => ({
170
+ result: decode(result2),
171
+ error: error2
172
+ }));
173
+ }
174
+ const result = decode(body.result);
175
+ return { result, error: body.error };
176
+ }
177
+ return body;
178
+ }
179
+ };
180
+ function base64decode(b64) {
181
+ let dec = "";
182
+ try {
183
+ const binString = atob(b64);
184
+ const size = binString.length;
185
+ const bytes = new Uint8Array(size);
186
+ for (let i = 0; i < size; i++) {
187
+ bytes[i] = binString.charCodeAt(i);
188
+ }
189
+ dec = new TextDecoder().decode(bytes);
190
+ } catch {
191
+ dec = b64;
192
+ }
193
+ return dec;
194
+ }
195
+ function decode(raw) {
196
+ let result = void 0;
197
+ switch (typeof raw) {
198
+ case "undefined": {
199
+ return raw;
200
+ }
201
+ case "number": {
202
+ result = raw;
203
+ break;
204
+ }
205
+ case "object": {
206
+ if (Array.isArray(raw)) {
207
+ result = raw.map(
208
+ (v) => typeof v === "string" ? base64decode(v) : Array.isArray(v) ? v.map((element) => decode(element)) : v
209
+ );
210
+ } else {
211
+ result = null;
212
+ }
213
+ break;
214
+ }
215
+ case "string": {
216
+ result = raw === "OK" ? "OK" : base64decode(raw);
217
+ break;
218
+ }
219
+ default: {
220
+ break;
221
+ }
222
+ }
223
+ return result;
224
+ }
225
+ function merge(obj, key, value) {
226
+ if (!value) {
227
+ return obj;
228
+ }
229
+ obj[key] = obj[key] ? [obj[key], value].join(",") : value;
230
+ return obj;
231
+ }
232
+
233
+ // pkg/auto-pipeline.ts
234
+ function createAutoPipelineProxy(_redis, json) {
235
+ const redis = _redis;
236
+ if (!redis.autoPipelineExecutor) {
237
+ redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
238
+ }
239
+ return new Proxy(redis, {
240
+ get: (redis2, command) => {
241
+ if (command === "pipelineCounter") {
242
+ return redis2.autoPipelineExecutor.pipelineCounter;
243
+ }
244
+ if (command === "json") {
245
+ return createAutoPipelineProxy(redis2, true);
246
+ }
247
+ const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
248
+ if (commandInRedisButNotPipeline) {
249
+ return redis2[command];
250
+ }
251
+ const isFunction = json ? typeof redis2.autoPipelineExecutor.pipeline.json[command] === "function" : typeof redis2.autoPipelineExecutor.pipeline[command] === "function";
252
+ if (isFunction) {
253
+ return (...args) => {
254
+ return redis2.autoPipelineExecutor.withAutoPipeline((pipeline) => {
255
+ if (json) {
256
+ pipeline.json[command](
257
+ ...args
258
+ );
259
+ } else {
260
+ pipeline[command](...args);
261
+ }
262
+ });
263
+ };
264
+ }
265
+ return redis2.autoPipelineExecutor.pipeline[command];
266
+ }
267
+ });
268
+ }
269
+ var AutoPipelineExecutor = class {
270
+ pipelinePromises = /* @__PURE__ */ new WeakMap();
271
+ activePipeline = null;
272
+ indexInCurrentPipeline = 0;
273
+ redis;
274
+ pipeline;
275
+ // only to make sure that proxy can work
276
+ pipelineCounter = 0;
277
+ // to keep track of how many times a pipeline was executed
278
+ constructor(redis) {
279
+ this.redis = redis;
280
+ this.pipeline = redis.pipeline();
281
+ }
282
+ async withAutoPipeline(executeWithPipeline) {
283
+ const pipeline = this.activePipeline ?? this.redis.pipeline();
284
+ if (!this.activePipeline) {
285
+ this.activePipeline = pipeline;
286
+ this.indexInCurrentPipeline = 0;
287
+ }
288
+ const index = this.indexInCurrentPipeline++;
289
+ executeWithPipeline(pipeline);
290
+ const pipelineDone = this.deferExecution().then(() => {
291
+ if (!this.pipelinePromises.has(pipeline)) {
292
+ const pipelinePromise = pipeline.exec({ keepErrors: true });
293
+ this.pipelineCounter += 1;
294
+ this.pipelinePromises.set(pipeline, pipelinePromise);
295
+ this.activePipeline = null;
296
+ }
297
+ return this.pipelinePromises.get(pipeline);
298
+ });
299
+ const results = await pipelineDone;
300
+ const commandResult = results[index];
301
+ if (commandResult.error) {
302
+ throw new UpstashError(`Command failed: ${commandResult.error}`);
303
+ }
304
+ return commandResult.result;
305
+ }
306
+ async deferExecution() {
307
+ await Promise.resolve();
308
+ await Promise.resolve();
309
+ }
310
+ };
311
+
312
+ // pkg/util.ts
313
+ function parseRecursive(obj) {
314
+ const parsed = Array.isArray(obj) ? obj.map((o) => {
315
+ try {
316
+ return parseRecursive(o);
317
+ } catch {
318
+ return o;
319
+ }
320
+ }) : JSON.parse(obj);
321
+ if (typeof parsed === "number" && parsed.toString() !== obj) {
322
+ return obj;
323
+ }
324
+ return parsed;
325
+ }
326
+ function parseResponse(result) {
327
+ try {
328
+ return parseRecursive(result);
329
+ } catch {
330
+ return result;
331
+ }
332
+ }
333
+ function deserializeScanResponse(result) {
334
+ return [result[0], ...parseResponse(result.slice(1))];
335
+ }
336
+
337
+ // pkg/commands/command.ts
338
+ var defaultSerializer = (c) => {
339
+ switch (typeof c) {
340
+ case "string":
341
+ case "number":
342
+ case "boolean": {
343
+ return c;
344
+ }
345
+ default: {
346
+ return JSON.stringify(c);
347
+ }
348
+ }
349
+ };
350
+ var Command = class {
351
+ command;
352
+ serialize;
353
+ deserialize;
354
+ /**
355
+ * Create a new command instance.
356
+ *
357
+ * You can define a custom `deserialize` function. By default we try to deserialize as json.
358
+ */
359
+ constructor(command, opts) {
360
+ this.serialize = defaultSerializer;
361
+ this.deserialize = opts?.automaticDeserialization === void 0 || opts.automaticDeserialization ? opts?.deserialize ?? parseResponse : (x) => x;
362
+ this.command = command.map((c) => this.serialize(c));
363
+ if (opts?.latencyLogging) {
364
+ const originalExec = this.exec.bind(this);
365
+ this.exec = async (client) => {
366
+ const start = performance.now();
367
+ const result = await originalExec(client);
368
+ const end = performance.now();
369
+ const loggerResult = (end - start).toFixed(2);
370
+ console.log(
371
+ `Latency for \x1B[38;2;19;185;39m${this.command[0].toString().toUpperCase()}\x1B[0m: \x1B[38;2;0;255;255m${loggerResult} ms\x1B[0m`
372
+ );
373
+ return result;
374
+ };
375
+ }
376
+ }
377
+ /**
378
+ * Execute the command using a client.
379
+ */
380
+ async exec(client) {
381
+ const { result, error } = await client.request({
382
+ body: this.command,
383
+ upstashSyncToken: client.upstashSyncToken
384
+ });
385
+ if (error) {
386
+ throw new UpstashError(error);
387
+ }
388
+ if (result === void 0) {
389
+ throw new TypeError("Request did not return a result");
390
+ }
391
+ return this.deserialize(result);
392
+ }
393
+ };
394
+
395
+ // pkg/commands/append.ts
396
+ var AppendCommand = class extends Command {
397
+ constructor(cmd, opts) {
398
+ super(["append", ...cmd], opts);
399
+ }
400
+ };
401
+
402
+ // pkg/commands/bitcount.ts
403
+ var BitCountCommand = class extends Command {
404
+ constructor([key, start, end], opts) {
405
+ const command = ["bitcount", key];
406
+ if (typeof start === "number") {
407
+ command.push(start);
408
+ }
409
+ if (typeof end === "number") {
410
+ command.push(end);
411
+ }
412
+ super(command, opts);
413
+ }
414
+ };
415
+
416
+ // pkg/commands/bitfield.ts
417
+ var BitFieldCommand = class {
418
+ constructor(args, client, opts, execOperation = (command) => command.exec(this.client)) {
419
+ this.client = client;
420
+ this.opts = opts;
421
+ this.execOperation = execOperation;
422
+ this.command = ["bitfield", ...args];
423
+ }
424
+ command;
425
+ chain(...args) {
426
+ this.command.push(...args);
427
+ return this;
428
+ }
429
+ get(...args) {
430
+ return this.chain("get", ...args);
431
+ }
432
+ set(...args) {
433
+ return this.chain("set", ...args);
434
+ }
435
+ incrby(...args) {
436
+ return this.chain("incrby", ...args);
437
+ }
438
+ overflow(overflow) {
439
+ return this.chain("overflow", overflow);
440
+ }
441
+ exec() {
442
+ const command = new Command(this.command, this.opts);
443
+ return this.execOperation(command);
444
+ }
445
+ };
446
+
447
+ // pkg/commands/bitop.ts
448
+ var BitOpCommand = class extends Command {
449
+ constructor(cmd, opts) {
450
+ super(["bitop", ...cmd], opts);
451
+ }
452
+ };
453
+
454
+ // pkg/commands/bitpos.ts
455
+ var BitPosCommand = class extends Command {
456
+ constructor(cmd, opts) {
457
+ super(["bitpos", ...cmd], opts);
458
+ }
459
+ };
460
+
461
+ // pkg/commands/copy.ts
462
+ var CopyCommand = class extends Command {
463
+ constructor([key, destinationKey, opts], commandOptions) {
464
+ super(["COPY", key, destinationKey, ...opts?.replace ? ["REPLACE"] : []], {
465
+ ...commandOptions,
466
+ deserialize(result) {
467
+ if (result > 0) {
468
+ return "COPIED";
469
+ }
470
+ return "NOT_COPIED";
471
+ }
472
+ });
473
+ }
474
+ };
475
+
476
+ // pkg/commands/dbsize.ts
477
+ var DBSizeCommand = class extends Command {
478
+ constructor(opts) {
479
+ super(["dbsize"], opts);
480
+ }
481
+ };
482
+
483
+ // pkg/commands/decr.ts
484
+ var DecrCommand = class extends Command {
485
+ constructor(cmd, opts) {
486
+ super(["decr", ...cmd], opts);
487
+ }
488
+ };
489
+
490
+ // pkg/commands/decrby.ts
491
+ var DecrByCommand = class extends Command {
492
+ constructor(cmd, opts) {
493
+ super(["decrby", ...cmd], opts);
494
+ }
495
+ };
496
+
497
+ // pkg/commands/del.ts
498
+ var DelCommand = class extends Command {
499
+ constructor(cmd, opts) {
500
+ super(["del", ...cmd], opts);
501
+ }
502
+ };
503
+
504
+ // pkg/commands/echo.ts
505
+ var EchoCommand = class extends Command {
506
+ constructor(cmd, opts) {
507
+ super(["echo", ...cmd], opts);
508
+ }
509
+ };
510
+
511
+ // pkg/commands/eval.ts
512
+ var EvalCommand = class extends Command {
513
+ constructor([script, keys, args], opts) {
514
+ super(["eval", script, keys.length, ...keys, ...args ?? []], opts);
515
+ }
516
+ };
517
+
518
+ // pkg/commands/evalsha.ts
519
+ var EvalshaCommand = class extends Command {
520
+ constructor([sha, keys, args], opts) {
521
+ super(["evalsha", sha, keys.length, ...keys, ...args ?? []], opts);
522
+ }
523
+ };
524
+
525
+ // pkg/commands/exists.ts
526
+ var ExistsCommand = class extends Command {
527
+ constructor(cmd, opts) {
528
+ super(["exists", ...cmd], opts);
529
+ }
530
+ };
531
+
532
+ // pkg/commands/expire.ts
533
+ var ExpireCommand = class extends Command {
534
+ constructor(cmd, opts) {
535
+ super(["expire", ...cmd.filter(Boolean)], opts);
536
+ }
537
+ };
538
+
539
+ // pkg/commands/expireat.ts
540
+ var ExpireAtCommand = class extends Command {
541
+ constructor(cmd, opts) {
542
+ super(["expireat", ...cmd], opts);
543
+ }
544
+ };
545
+
546
+ // pkg/commands/flushall.ts
547
+ var FlushAllCommand = class extends Command {
548
+ constructor(args, opts) {
549
+ const command = ["flushall"];
550
+ if (args && args.length > 0 && args[0].async) {
551
+ command.push("async");
552
+ }
553
+ super(command, opts);
554
+ }
555
+ };
556
+
557
+ // pkg/commands/flushdb.ts
558
+ var FlushDBCommand = class extends Command {
559
+ constructor([opts], cmdOpts) {
560
+ const command = ["flushdb"];
561
+ if (opts?.async) {
562
+ command.push("async");
563
+ }
564
+ super(command, cmdOpts);
565
+ }
566
+ };
567
+
568
+ // pkg/commands/geo_add.ts
569
+ var GeoAddCommand = class extends Command {
570
+ constructor([key, arg1, ...arg2], opts) {
571
+ const command = ["geoadd", key];
572
+ if ("nx" in arg1 && arg1.nx) {
573
+ command.push("nx");
574
+ } else if ("xx" in arg1 && arg1.xx) {
575
+ command.push("xx");
576
+ }
577
+ if ("ch" in arg1 && arg1.ch) {
578
+ command.push("ch");
579
+ }
580
+ if ("latitude" in arg1 && arg1.latitude) {
581
+ command.push(arg1.longitude, arg1.latitude, arg1.member);
582
+ }
583
+ command.push(
584
+ ...arg2.flatMap(({ latitude, longitude, member }) => [longitude, latitude, member])
585
+ );
586
+ super(command, opts);
587
+ }
588
+ };
589
+
590
+ // pkg/commands/geo_dist.ts
591
+ var GeoDistCommand = class extends Command {
592
+ constructor([key, member1, member2, unit = "M"], opts) {
593
+ super(["GEODIST", key, member1, member2, unit], opts);
594
+ }
595
+ };
596
+
597
+ // pkg/commands/geo_hash.ts
598
+ var GeoHashCommand = class extends Command {
599
+ constructor(cmd, opts) {
600
+ const [key] = cmd;
601
+ const members = Array.isArray(cmd[1]) ? cmd[1] : cmd.slice(1);
602
+ super(["GEOHASH", key, ...members], opts);
603
+ }
604
+ };
605
+
606
+ // pkg/commands/geo_pos.ts
607
+ var GeoPosCommand = class extends Command {
608
+ constructor(cmd, opts) {
609
+ const [key] = cmd;
610
+ const members = Array.isArray(cmd[1]) ? cmd[1] : cmd.slice(1);
611
+ super(["GEOPOS", key, ...members], {
612
+ deserialize: (result) => transform(result),
613
+ ...opts
614
+ });
615
+ }
616
+ };
617
+ function transform(result) {
618
+ const final = [];
619
+ for (const pos of result) {
620
+ if (!pos?.[0] || !pos?.[1]) {
621
+ continue;
622
+ }
623
+ final.push({ lng: Number.parseFloat(pos[0]), lat: Number.parseFloat(pos[1]) });
624
+ }
625
+ return final;
626
+ }
627
+
628
+ // pkg/commands/geo_search.ts
629
+ var GeoSearchCommand = class extends Command {
630
+ constructor([key, centerPoint, shape, order, opts], commandOptions) {
631
+ const command = ["GEOSEARCH", key];
632
+ if (centerPoint.type === "FROMMEMBER" || centerPoint.type === "frommember") {
633
+ command.push(centerPoint.type, centerPoint.member);
634
+ }
635
+ if (centerPoint.type === "FROMLONLAT" || centerPoint.type === "fromlonlat") {
636
+ command.push(centerPoint.type, centerPoint.coordinate.lon, centerPoint.coordinate.lat);
637
+ }
638
+ if (shape.type === "BYRADIUS" || shape.type === "byradius") {
639
+ command.push(shape.type, shape.radius, shape.radiusType);
640
+ }
641
+ if (shape.type === "BYBOX" || shape.type === "bybox") {
642
+ command.push(shape.type, shape.rect.width, shape.rect.height, shape.rectType);
643
+ }
644
+ command.push(order);
645
+ if (opts?.count) {
646
+ command.push("COUNT", opts.count.limit, ...opts.count.any ? ["ANY"] : []);
647
+ }
648
+ const transform2 = (result) => {
649
+ if (!opts?.withCoord && !opts?.withDist && !opts?.withHash) {
650
+ return result.map((member) => {
651
+ try {
652
+ return { member: JSON.parse(member) };
653
+ } catch {
654
+ return { member };
655
+ }
656
+ });
657
+ }
658
+ return result.map((members) => {
659
+ let counter = 1;
660
+ const obj = {};
661
+ try {
662
+ obj.member = JSON.parse(members[0]);
663
+ } catch {
664
+ obj.member = members[0];
665
+ }
666
+ if (opts.withDist) {
667
+ obj.dist = Number.parseFloat(members[counter++]);
668
+ }
669
+ if (opts.withHash) {
670
+ obj.hash = members[counter++].toString();
671
+ }
672
+ if (opts.withCoord) {
673
+ obj.coord = {
674
+ long: Number.parseFloat(members[counter][0]),
675
+ lat: Number.parseFloat(members[counter][1])
676
+ };
677
+ }
678
+ return obj;
679
+ });
680
+ };
681
+ super(
682
+ [
683
+ ...command,
684
+ ...opts?.withCoord ? ["WITHCOORD"] : [],
685
+ ...opts?.withDist ? ["WITHDIST"] : [],
686
+ ...opts?.withHash ? ["WITHHASH"] : []
687
+ ],
688
+ {
689
+ deserialize: transform2,
690
+ ...commandOptions
691
+ }
692
+ );
693
+ }
694
+ };
695
+
696
+ // pkg/commands/geo_search_store.ts
697
+ var GeoSearchStoreCommand = class extends Command {
698
+ constructor([destination, key, centerPoint, shape, order, opts], commandOptions) {
699
+ const command = ["GEOSEARCHSTORE", destination, key];
700
+ if (centerPoint.type === "FROMMEMBER" || centerPoint.type === "frommember") {
701
+ command.push(centerPoint.type, centerPoint.member);
702
+ }
703
+ if (centerPoint.type === "FROMLONLAT" || centerPoint.type === "fromlonlat") {
704
+ command.push(centerPoint.type, centerPoint.coordinate.lon, centerPoint.coordinate.lat);
705
+ }
706
+ if (shape.type === "BYRADIUS" || shape.type === "byradius") {
707
+ command.push(shape.type, shape.radius, shape.radiusType);
708
+ }
709
+ if (shape.type === "BYBOX" || shape.type === "bybox") {
710
+ command.push(shape.type, shape.rect.width, shape.rect.height, shape.rectType);
711
+ }
712
+ command.push(order);
713
+ if (opts?.count) {
714
+ command.push("COUNT", opts.count.limit, ...opts.count.any ? ["ANY"] : []);
715
+ }
716
+ super([...command, ...opts?.storeDist ? ["STOREDIST"] : []], commandOptions);
717
+ }
718
+ };
719
+
720
+ // pkg/commands/get.ts
721
+ var GetCommand = class extends Command {
722
+ constructor(cmd, opts) {
723
+ super(["get", ...cmd], opts);
724
+ }
725
+ };
726
+
727
+ // pkg/commands/getbit.ts
728
+ var GetBitCommand = class extends Command {
729
+ constructor(cmd, opts) {
730
+ super(["getbit", ...cmd], opts);
731
+ }
732
+ };
733
+
734
+ // pkg/commands/getdel.ts
735
+ var GetDelCommand = class extends Command {
736
+ constructor(cmd, opts) {
737
+ super(["getdel", ...cmd], opts);
738
+ }
739
+ };
740
+
741
+ // pkg/commands/getrange.ts
742
+ var GetRangeCommand = class extends Command {
743
+ constructor(cmd, opts) {
744
+ super(["getrange", ...cmd], opts);
745
+ }
746
+ };
747
+
748
+ // pkg/commands/getset.ts
749
+ var GetSetCommand = class extends Command {
750
+ constructor(cmd, opts) {
751
+ super(["getset", ...cmd], opts);
752
+ }
753
+ };
754
+
755
+ // pkg/commands/hdel.ts
756
+ var HDelCommand = class extends Command {
757
+ constructor(cmd, opts) {
758
+ super(["hdel", ...cmd], opts);
759
+ }
760
+ };
761
+
762
+ // pkg/commands/hexists.ts
763
+ var HExistsCommand = class extends Command {
764
+ constructor(cmd, opts) {
765
+ super(["hexists", ...cmd], opts);
766
+ }
767
+ };
768
+
769
+ // pkg/commands/hget.ts
770
+ var HGetCommand = class extends Command {
771
+ constructor(cmd, opts) {
772
+ super(["hget", ...cmd], opts);
773
+ }
774
+ };
775
+
776
+ // pkg/commands/hgetall.ts
777
+ function deserialize(result) {
778
+ if (result.length === 0) {
779
+ return null;
780
+ }
781
+ const obj = {};
782
+ while (result.length >= 2) {
783
+ const key = result.shift();
784
+ const value = result.shift();
785
+ try {
786
+ const valueIsNumberAndNotSafeInteger = !Number.isNaN(Number(value)) && !Number.isSafeInteger(Number(value));
787
+ obj[key] = valueIsNumberAndNotSafeInteger ? value : JSON.parse(value);
788
+ } catch {
789
+ obj[key] = value;
790
+ }
791
+ }
792
+ return obj;
793
+ }
794
+ var HGetAllCommand = class extends Command {
795
+ constructor(cmd, opts) {
796
+ super(["hgetall", ...cmd], {
797
+ deserialize: (result) => deserialize(result),
798
+ ...opts
799
+ });
800
+ }
801
+ };
802
+
803
+ // pkg/commands/hincrby.ts
804
+ var HIncrByCommand = class extends Command {
805
+ constructor(cmd, opts) {
806
+ super(["hincrby", ...cmd], opts);
807
+ }
808
+ };
809
+
810
+ // pkg/commands/hincrbyfloat.ts
811
+ var HIncrByFloatCommand = class extends Command {
812
+ constructor(cmd, opts) {
813
+ super(["hincrbyfloat", ...cmd], opts);
814
+ }
815
+ };
816
+
817
+ // pkg/commands/hkeys.ts
818
+ var HKeysCommand = class extends Command {
819
+ constructor([key], opts) {
820
+ super(["hkeys", key], opts);
821
+ }
822
+ };
823
+
824
+ // pkg/commands/hlen.ts
825
+ var HLenCommand = class extends Command {
826
+ constructor(cmd, opts) {
827
+ super(["hlen", ...cmd], opts);
828
+ }
829
+ };
830
+
831
+ // pkg/commands/hmget.ts
832
+ function deserialize2(fields, result) {
833
+ if (result.every((field) => field === null)) {
834
+ return null;
835
+ }
836
+ const obj = {};
837
+ for (const [i, field] of fields.entries()) {
838
+ try {
839
+ obj[field] = JSON.parse(result[i]);
840
+ } catch {
841
+ obj[field] = result[i];
842
+ }
843
+ }
844
+ return obj;
845
+ }
846
+ var HMGetCommand = class extends Command {
847
+ constructor([key, ...fields], opts) {
848
+ super(["hmget", key, ...fields], {
849
+ deserialize: (result) => deserialize2(fields, result),
850
+ ...opts
851
+ });
852
+ }
853
+ };
854
+
855
+ // pkg/commands/hmset.ts
856
+ var HMSetCommand = class extends Command {
857
+ constructor([key, kv], opts) {
858
+ super(["hmset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])], opts);
859
+ }
860
+ };
861
+
862
+ // pkg/commands/hrandfield.ts
863
+ function deserialize3(result) {
864
+ if (result.length === 0) {
865
+ return null;
866
+ }
867
+ const obj = {};
868
+ while (result.length >= 2) {
869
+ const key = result.shift();
870
+ const value = result.shift();
871
+ try {
872
+ obj[key] = JSON.parse(value);
873
+ } catch {
874
+ obj[key] = value;
875
+ }
876
+ }
877
+ return obj;
878
+ }
879
+ var HRandFieldCommand = class extends Command {
880
+ constructor(cmd, opts) {
881
+ const command = ["hrandfield", cmd[0]];
882
+ if (typeof cmd[1] === "number") {
883
+ command.push(cmd[1]);
884
+ }
885
+ if (cmd[2]) {
886
+ command.push("WITHVALUES");
887
+ }
888
+ super(command, {
889
+ // @ts-expect-error to silence compiler
890
+ deserialize: cmd[2] ? (result) => deserialize3(result) : opts?.deserialize,
891
+ ...opts
892
+ });
893
+ }
894
+ };
895
+
896
+ // pkg/commands/hscan.ts
897
+ var HScanCommand = class extends Command {
898
+ constructor([key, cursor, cmdOpts], opts) {
899
+ const command = ["hscan", key, cursor];
900
+ if (cmdOpts?.match) {
901
+ command.push("match", cmdOpts.match);
902
+ }
903
+ if (typeof cmdOpts?.count === "number") {
904
+ command.push("count", cmdOpts.count);
905
+ }
906
+ super(command, {
907
+ deserialize: deserializeScanResponse,
908
+ ...opts
909
+ });
910
+ }
911
+ };
912
+
913
+ // pkg/commands/hset.ts
914
+ var HSetCommand = class extends Command {
915
+ constructor([key, kv], opts) {
916
+ super(["hset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])], opts);
917
+ }
918
+ };
919
+
920
+ // pkg/commands/hsetnx.ts
921
+ var HSetNXCommand = class extends Command {
922
+ constructor(cmd, opts) {
923
+ super(["hsetnx", ...cmd], opts);
924
+ }
925
+ };
926
+
927
+ // pkg/commands/hstrlen.ts
928
+ var HStrLenCommand = class extends Command {
929
+ constructor(cmd, opts) {
930
+ super(["hstrlen", ...cmd], opts);
931
+ }
932
+ };
933
+
934
+ // pkg/commands/hvals.ts
935
+ var HValsCommand = class extends Command {
936
+ constructor(cmd, opts) {
937
+ super(["hvals", ...cmd], opts);
938
+ }
939
+ };
940
+
941
+ // pkg/commands/incr.ts
942
+ var IncrCommand = class extends Command {
943
+ constructor(cmd, opts) {
944
+ super(["incr", ...cmd], opts);
945
+ }
946
+ };
947
+
948
+ // pkg/commands/incrby.ts
949
+ var IncrByCommand = class extends Command {
950
+ constructor(cmd, opts) {
951
+ super(["incrby", ...cmd], opts);
952
+ }
953
+ };
954
+
955
+ // pkg/commands/incrbyfloat.ts
956
+ var IncrByFloatCommand = class extends Command {
957
+ constructor(cmd, opts) {
958
+ super(["incrbyfloat", ...cmd], opts);
959
+ }
960
+ };
961
+
962
+ // pkg/commands/json_arrappend.ts
963
+ var JsonArrAppendCommand = class extends Command {
964
+ constructor(cmd, opts) {
965
+ super(["JSON.ARRAPPEND", ...cmd], opts);
966
+ }
967
+ };
968
+
969
+ // pkg/commands/json_arrindex.ts
970
+ var JsonArrIndexCommand = class extends Command {
971
+ constructor(cmd, opts) {
972
+ super(["JSON.ARRINDEX", ...cmd], opts);
973
+ }
974
+ };
975
+
976
+ // pkg/commands/json_arrinsert.ts
977
+ var JsonArrInsertCommand = class extends Command {
978
+ constructor(cmd, opts) {
979
+ super(["JSON.ARRINSERT", ...cmd], opts);
980
+ }
981
+ };
982
+
983
+ // pkg/commands/json_arrlen.ts
984
+ var JsonArrLenCommand = class extends Command {
985
+ constructor(cmd, opts) {
986
+ super(["JSON.ARRLEN", cmd[0], cmd[1] ?? "$"], opts);
987
+ }
988
+ };
989
+
990
+ // pkg/commands/json_arrpop.ts
991
+ var JsonArrPopCommand = class extends Command {
992
+ constructor(cmd, opts) {
993
+ super(["JSON.ARRPOP", ...cmd], opts);
994
+ }
995
+ };
996
+
997
+ // pkg/commands/json_arrtrim.ts
998
+ var JsonArrTrimCommand = class extends Command {
999
+ constructor(cmd, opts) {
1000
+ const path = cmd[1] ?? "$";
1001
+ const start = cmd[2] ?? 0;
1002
+ const stop = cmd[3] ?? 0;
1003
+ super(["JSON.ARRTRIM", cmd[0], path, start, stop], opts);
1004
+ }
1005
+ };
1006
+
1007
+ // pkg/commands/json_clear.ts
1008
+ var JsonClearCommand = class extends Command {
1009
+ constructor(cmd, opts) {
1010
+ super(["JSON.CLEAR", ...cmd], opts);
1011
+ }
1012
+ };
1013
+
1014
+ // pkg/commands/json_del.ts
1015
+ var JsonDelCommand = class extends Command {
1016
+ constructor(cmd, opts) {
1017
+ super(["JSON.DEL", ...cmd], opts);
1018
+ }
1019
+ };
1020
+
1021
+ // pkg/commands/json_forget.ts
1022
+ var JsonForgetCommand = class extends Command {
1023
+ constructor(cmd, opts) {
1024
+ super(["JSON.FORGET", ...cmd], opts);
1025
+ }
1026
+ };
1027
+
1028
+ // pkg/commands/json_get.ts
1029
+ var JsonGetCommand = class extends Command {
1030
+ constructor(cmd, opts) {
1031
+ const command = ["JSON.GET"];
1032
+ if (typeof cmd[1] === "string") {
1033
+ command.push(...cmd);
1034
+ } else {
1035
+ command.push(cmd[0]);
1036
+ if (cmd[1]) {
1037
+ if (cmd[1].indent) {
1038
+ command.push("INDENT", cmd[1].indent);
1039
+ }
1040
+ if (cmd[1].newline) {
1041
+ command.push("NEWLINE", cmd[1].newline);
1042
+ }
1043
+ if (cmd[1].space) {
1044
+ command.push("SPACE", cmd[1].space);
1045
+ }
1046
+ }
1047
+ command.push(...cmd.slice(2));
1048
+ }
1049
+ super(command, opts);
1050
+ }
1051
+ };
1052
+
1053
+ // pkg/commands/json_mget.ts
1054
+ var JsonMGetCommand = class extends Command {
1055
+ constructor(cmd, opts) {
1056
+ super(["JSON.MGET", ...cmd[0], cmd[1]], opts);
1057
+ }
1058
+ };
1059
+
1060
+ // pkg/commands/json_mset.ts
1061
+ var JsonMSetCommand = class extends Command {
1062
+ constructor(cmd, opts) {
1063
+ const command = ["JSON.MSET"];
1064
+ for (const c of cmd) {
1065
+ command.push(c.key, c.path, c.value);
1066
+ }
1067
+ super(command, opts);
1068
+ }
1069
+ };
1070
+
1071
+ // pkg/commands/json_numincrby.ts
1072
+ var JsonNumIncrByCommand = class extends Command {
1073
+ constructor(cmd, opts) {
1074
+ super(["JSON.NUMINCRBY", ...cmd], opts);
1075
+ }
1076
+ };
1077
+
1078
+ // pkg/commands/json_nummultby.ts
1079
+ var JsonNumMultByCommand = class extends Command {
1080
+ constructor(cmd, opts) {
1081
+ super(["JSON.NUMMULTBY", ...cmd], opts);
1082
+ }
1083
+ };
1084
+
1085
+ // pkg/commands/json_objkeys.ts
1086
+ var JsonObjKeysCommand = class extends Command {
1087
+ constructor(cmd, opts) {
1088
+ super(["JSON.OBJKEYS", ...cmd], opts);
1089
+ }
1090
+ };
1091
+
1092
+ // pkg/commands/json_objlen.ts
1093
+ var JsonObjLenCommand = class extends Command {
1094
+ constructor(cmd, opts) {
1095
+ super(["JSON.OBJLEN", ...cmd], opts);
1096
+ }
1097
+ };
1098
+
1099
+ // pkg/commands/json_resp.ts
1100
+ var JsonRespCommand = class extends Command {
1101
+ constructor(cmd, opts) {
1102
+ super(["JSON.RESP", ...cmd], opts);
1103
+ }
1104
+ };
1105
+
1106
+ // pkg/commands/json_set.ts
1107
+ var JsonSetCommand = class extends Command {
1108
+ constructor(cmd, opts) {
1109
+ const command = ["JSON.SET", cmd[0], cmd[1], cmd[2]];
1110
+ if (cmd[3]) {
1111
+ if (cmd[3].nx) {
1112
+ command.push("NX");
1113
+ } else if (cmd[3].xx) {
1114
+ command.push("XX");
1115
+ }
1116
+ }
1117
+ super(command, opts);
1118
+ }
1119
+ };
1120
+
1121
+ // pkg/commands/json_strappend.ts
1122
+ var JsonStrAppendCommand = class extends Command {
1123
+ constructor(cmd, opts) {
1124
+ super(["JSON.STRAPPEND", ...cmd], opts);
1125
+ }
1126
+ };
1127
+
1128
+ // pkg/commands/json_strlen.ts
1129
+ var JsonStrLenCommand = class extends Command {
1130
+ constructor(cmd, opts) {
1131
+ super(["JSON.STRLEN", ...cmd], opts);
1132
+ }
1133
+ };
1134
+
1135
+ // pkg/commands/json_toggle.ts
1136
+ var JsonToggleCommand = class extends Command {
1137
+ constructor(cmd, opts) {
1138
+ super(["JSON.TOGGLE", ...cmd], opts);
1139
+ }
1140
+ };
1141
+
1142
+ // pkg/commands/json_type.ts
1143
+ var JsonTypeCommand = class extends Command {
1144
+ constructor(cmd, opts) {
1145
+ super(["JSON.TYPE", ...cmd], opts);
1146
+ }
1147
+ };
1148
+
1149
+ // pkg/commands/keys.ts
1150
+ var KeysCommand = class extends Command {
1151
+ constructor(cmd, opts) {
1152
+ super(["keys", ...cmd], opts);
1153
+ }
1154
+ };
1155
+
1156
+ // pkg/commands/lindex.ts
1157
+ var LIndexCommand = class extends Command {
1158
+ constructor(cmd, opts) {
1159
+ super(["lindex", ...cmd], opts);
1160
+ }
1161
+ };
1162
+
1163
+ // pkg/commands/linsert.ts
1164
+ var LInsertCommand = class extends Command {
1165
+ constructor(cmd, opts) {
1166
+ super(["linsert", ...cmd], opts);
1167
+ }
1168
+ };
1169
+
1170
+ // pkg/commands/llen.ts
1171
+ var LLenCommand = class extends Command {
1172
+ constructor(cmd, opts) {
1173
+ super(["llen", ...cmd], opts);
1174
+ }
1175
+ };
1176
+
1177
+ // pkg/commands/lmove.ts
1178
+ var LMoveCommand = class extends Command {
1179
+ constructor(cmd, opts) {
1180
+ super(["lmove", ...cmd], opts);
1181
+ }
1182
+ };
1183
+
1184
+ // pkg/commands/lmpop.ts
1185
+ var LmPopCommand = class extends Command {
1186
+ constructor(cmd, opts) {
1187
+ const [numkeys, keys, direction, count] = cmd;
1188
+ super(["LMPOP", numkeys, ...keys, direction, ...count ? ["COUNT", count] : []], opts);
1189
+ }
1190
+ };
1191
+
1192
+ // pkg/commands/lpop.ts
1193
+ var LPopCommand = class extends Command {
1194
+ constructor(cmd, opts) {
1195
+ super(["lpop", ...cmd], opts);
1196
+ }
1197
+ };
1198
+
1199
+ // pkg/commands/lpos.ts
1200
+ var LPosCommand = class extends Command {
1201
+ constructor(cmd, opts) {
1202
+ const args = ["lpos", cmd[0], cmd[1]];
1203
+ if (typeof cmd[2]?.rank === "number") {
1204
+ args.push("rank", cmd[2].rank);
1205
+ }
1206
+ if (typeof cmd[2]?.count === "number") {
1207
+ args.push("count", cmd[2].count);
1208
+ }
1209
+ if (typeof cmd[2]?.maxLen === "number") {
1210
+ args.push("maxLen", cmd[2].maxLen);
1211
+ }
1212
+ super(args, opts);
1213
+ }
1214
+ };
1215
+
1216
+ // pkg/commands/lpush.ts
1217
+ var LPushCommand = class extends Command {
1218
+ constructor(cmd, opts) {
1219
+ super(["lpush", ...cmd], opts);
1220
+ }
1221
+ };
1222
+
1223
+ // pkg/commands/lpushx.ts
1224
+ var LPushXCommand = class extends Command {
1225
+ constructor(cmd, opts) {
1226
+ super(["lpushx", ...cmd], opts);
1227
+ }
1228
+ };
1229
+
1230
+ // pkg/commands/lrange.ts
1231
+ var LRangeCommand = class extends Command {
1232
+ constructor(cmd, opts) {
1233
+ super(["lrange", ...cmd], opts);
1234
+ }
1235
+ };
1236
+
1237
+ // pkg/commands/lrem.ts
1238
+ var LRemCommand = class extends Command {
1239
+ constructor(cmd, opts) {
1240
+ super(["lrem", ...cmd], opts);
1241
+ }
1242
+ };
1243
+
1244
+ // pkg/commands/lset.ts
1245
+ var LSetCommand = class extends Command {
1246
+ constructor(cmd, opts) {
1247
+ super(["lset", ...cmd], opts);
1248
+ }
1249
+ };
1250
+
1251
+ // pkg/commands/ltrim.ts
1252
+ var LTrimCommand = class extends Command {
1253
+ constructor(cmd, opts) {
1254
+ super(["ltrim", ...cmd], opts);
1255
+ }
1256
+ };
1257
+
1258
+ // pkg/commands/mget.ts
1259
+ var MGetCommand = class extends Command {
1260
+ constructor(cmd, opts) {
1261
+ const keys = Array.isArray(cmd[0]) ? cmd[0] : cmd;
1262
+ super(["mget", ...keys], opts);
1263
+ }
1264
+ };
1265
+
1266
+ // pkg/commands/mset.ts
1267
+ var MSetCommand = class extends Command {
1268
+ constructor([kv], opts) {
1269
+ super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])], opts);
1270
+ }
1271
+ };
1272
+
1273
+ // pkg/commands/msetnx.ts
1274
+ var MSetNXCommand = class extends Command {
1275
+ constructor([kv], opts) {
1276
+ super(["msetnx", ...Object.entries(kv).flat()], opts);
1277
+ }
1278
+ };
1279
+
1280
+ // pkg/commands/persist.ts
1281
+ var PersistCommand = class extends Command {
1282
+ constructor(cmd, opts) {
1283
+ super(["persist", ...cmd], opts);
1284
+ }
1285
+ };
1286
+
1287
+ // pkg/commands/pexpire.ts
1288
+ var PExpireCommand = class extends Command {
1289
+ constructor(cmd, opts) {
1290
+ super(["pexpire", ...cmd], opts);
1291
+ }
1292
+ };
1293
+
1294
+ // pkg/commands/pexpireat.ts
1295
+ var PExpireAtCommand = class extends Command {
1296
+ constructor(cmd, opts) {
1297
+ super(["pexpireat", ...cmd], opts);
1298
+ }
1299
+ };
1300
+
1301
+ // pkg/commands/pfadd.ts
1302
+ var PfAddCommand = class extends Command {
1303
+ constructor(cmd, opts) {
1304
+ super(["pfadd", ...cmd], opts);
1305
+ }
1306
+ };
1307
+
1308
+ // pkg/commands/pfcount.ts
1309
+ var PfCountCommand = class extends Command {
1310
+ constructor(cmd, opts) {
1311
+ super(["pfcount", ...cmd], opts);
1312
+ }
1313
+ };
1314
+
1315
+ // pkg/commands/pfmerge.ts
1316
+ var PfMergeCommand = class extends Command {
1317
+ constructor(cmd, opts) {
1318
+ super(["pfmerge", ...cmd], opts);
1319
+ }
1320
+ };
1321
+
1322
+ // pkg/commands/ping.ts
1323
+ var PingCommand = class extends Command {
1324
+ constructor(cmd, opts) {
1325
+ const command = ["ping"];
1326
+ if (cmd?.[0] !== void 0) {
1327
+ command.push(cmd[0]);
1328
+ }
1329
+ super(command, opts);
1330
+ }
1331
+ };
1332
+
1333
+ // pkg/commands/psetex.ts
1334
+ var PSetEXCommand = class extends Command {
1335
+ constructor(cmd, opts) {
1336
+ super(["psetex", ...cmd], opts);
1337
+ }
1338
+ };
1339
+
1340
+ // pkg/commands/pttl.ts
1341
+ var PTtlCommand = class extends Command {
1342
+ constructor(cmd, opts) {
1343
+ super(["pttl", ...cmd], opts);
1344
+ }
1345
+ };
1346
+
1347
+ // pkg/commands/publish.ts
1348
+ var PublishCommand = class extends Command {
1349
+ constructor(cmd, opts) {
1350
+ super(["publish", ...cmd], opts);
1351
+ }
1352
+ };
1353
+
1354
+ // pkg/commands/randomkey.ts
1355
+ var RandomKeyCommand = class extends Command {
1356
+ constructor(opts) {
1357
+ super(["randomkey"], opts);
1358
+ }
1359
+ };
1360
+
1361
+ // pkg/commands/rename.ts
1362
+ var RenameCommand = class extends Command {
1363
+ constructor(cmd, opts) {
1364
+ super(["rename", ...cmd], opts);
1365
+ }
1366
+ };
1367
+
1368
+ // pkg/commands/renamenx.ts
1369
+ var RenameNXCommand = class extends Command {
1370
+ constructor(cmd, opts) {
1371
+ super(["renamenx", ...cmd], opts);
1372
+ }
1373
+ };
1374
+
1375
+ // pkg/commands/rpop.ts
1376
+ var RPopCommand = class extends Command {
1377
+ constructor(cmd, opts) {
1378
+ super(["rpop", ...cmd], opts);
1379
+ }
1380
+ };
1381
+
1382
+ // pkg/commands/rpush.ts
1383
+ var RPushCommand = class extends Command {
1384
+ constructor(cmd, opts) {
1385
+ super(["rpush", ...cmd], opts);
1386
+ }
1387
+ };
1388
+
1389
+ // pkg/commands/rpushx.ts
1390
+ var RPushXCommand = class extends Command {
1391
+ constructor(cmd, opts) {
1392
+ super(["rpushx", ...cmd], opts);
1393
+ }
1394
+ };
1395
+
1396
+ // pkg/commands/sadd.ts
1397
+ var SAddCommand = class extends Command {
1398
+ constructor(cmd, opts) {
1399
+ super(["sadd", ...cmd], opts);
1400
+ }
1401
+ };
1402
+
1403
+ // pkg/commands/scan.ts
1404
+ var ScanCommand = class extends Command {
1405
+ constructor([cursor, opts], cmdOpts) {
1406
+ const command = ["scan", cursor];
1407
+ if (opts?.match) {
1408
+ command.push("match", opts.match);
1409
+ }
1410
+ if (typeof opts?.count === "number") {
1411
+ command.push("count", opts.count);
1412
+ }
1413
+ if (opts?.type && opts.type.length > 0) {
1414
+ command.push("type", opts.type);
1415
+ }
1416
+ super(command, {
1417
+ deserialize: deserializeScanResponse,
1418
+ ...cmdOpts
1419
+ });
1420
+ }
1421
+ };
1422
+
1423
+ // pkg/commands/scard.ts
1424
+ var SCardCommand = class extends Command {
1425
+ constructor(cmd, opts) {
1426
+ super(["scard", ...cmd], opts);
1427
+ }
1428
+ };
1429
+
1430
+ // pkg/commands/script_exists.ts
1431
+ var ScriptExistsCommand = class extends Command {
1432
+ constructor(hashes, opts) {
1433
+ super(["script", "exists", ...hashes], {
1434
+ deserialize: (result) => result,
1435
+ ...opts
1436
+ });
1437
+ }
1438
+ };
1439
+
1440
+ // pkg/commands/script_flush.ts
1441
+ var ScriptFlushCommand = class extends Command {
1442
+ constructor([opts], cmdOpts) {
1443
+ const cmd = ["script", "flush"];
1444
+ if (opts?.sync) {
1445
+ cmd.push("sync");
1446
+ } else if (opts?.async) {
1447
+ cmd.push("async");
1448
+ }
1449
+ super(cmd, cmdOpts);
1450
+ }
1451
+ };
1452
+
1453
+ // pkg/commands/script_load.ts
1454
+ var ScriptLoadCommand = class extends Command {
1455
+ constructor(args, opts) {
1456
+ super(["script", "load", ...args], opts);
1457
+ }
1458
+ };
1459
+
1460
+ // pkg/commands/sdiff.ts
1461
+ var SDiffCommand = class extends Command {
1462
+ constructor(cmd, opts) {
1463
+ super(["sdiff", ...cmd], opts);
1464
+ }
1465
+ };
1466
+
1467
+ // pkg/commands/sdiffstore.ts
1468
+ var SDiffStoreCommand = class extends Command {
1469
+ constructor(cmd, opts) {
1470
+ super(["sdiffstore", ...cmd], opts);
1471
+ }
1472
+ };
1473
+
1474
+ // pkg/commands/set.ts
1475
+ var SetCommand = class extends Command {
1476
+ constructor([key, value, opts], cmdOpts) {
1477
+ const command = ["set", key, value];
1478
+ if (opts) {
1479
+ if ("nx" in opts && opts.nx) {
1480
+ command.push("nx");
1481
+ } else if ("xx" in opts && opts.xx) {
1482
+ command.push("xx");
1483
+ }
1484
+ if ("get" in opts && opts.get) {
1485
+ command.push("get");
1486
+ }
1487
+ if ("ex" in opts && typeof opts.ex === "number") {
1488
+ command.push("ex", opts.ex);
1489
+ } else if ("px" in opts && typeof opts.px === "number") {
1490
+ command.push("px", opts.px);
1491
+ } else if ("exat" in opts && typeof opts.exat === "number") {
1492
+ command.push("exat", opts.exat);
1493
+ } else if ("pxat" in opts && typeof opts.pxat === "number") {
1494
+ command.push("pxat", opts.pxat);
1495
+ } else if ("keepTtl" in opts && opts.keepTtl) {
1496
+ command.push("keepTtl");
1497
+ }
1498
+ }
1499
+ super(command, cmdOpts);
1500
+ }
1501
+ };
1502
+
1503
+ // pkg/commands/setbit.ts
1504
+ var SetBitCommand = class extends Command {
1505
+ constructor(cmd, opts) {
1506
+ super(["setbit", ...cmd], opts);
1507
+ }
1508
+ };
1509
+
1510
+ // pkg/commands/setex.ts
1511
+ var SetExCommand = class extends Command {
1512
+ constructor(cmd, opts) {
1513
+ super(["setex", ...cmd], opts);
1514
+ }
1515
+ };
1516
+
1517
+ // pkg/commands/setnx.ts
1518
+ var SetNxCommand = class extends Command {
1519
+ constructor(cmd, opts) {
1520
+ super(["setnx", ...cmd], opts);
1521
+ }
1522
+ };
1523
+
1524
+ // pkg/commands/setrange.ts
1525
+ var SetRangeCommand = class extends Command {
1526
+ constructor(cmd, opts) {
1527
+ super(["setrange", ...cmd], opts);
1528
+ }
1529
+ };
1530
+
1531
+ // pkg/commands/sinter.ts
1532
+ var SInterCommand = class extends Command {
1533
+ constructor(cmd, opts) {
1534
+ super(["sinter", ...cmd], opts);
1535
+ }
1536
+ };
1537
+
1538
+ // pkg/commands/sinterstore.ts
1539
+ var SInterStoreCommand = class extends Command {
1540
+ constructor(cmd, opts) {
1541
+ super(["sinterstore", ...cmd], opts);
1542
+ }
1543
+ };
1544
+
1545
+ // pkg/commands/sismember.ts
1546
+ var SIsMemberCommand = class extends Command {
1547
+ constructor(cmd, opts) {
1548
+ super(["sismember", ...cmd], opts);
1549
+ }
1550
+ };
1551
+
1552
+ // pkg/commands/smembers.ts
1553
+ var SMembersCommand = class extends Command {
1554
+ constructor(cmd, opts) {
1555
+ super(["smembers", ...cmd], opts);
1556
+ }
1557
+ };
1558
+
1559
+ // pkg/commands/smismember.ts
1560
+ var SMIsMemberCommand = class extends Command {
1561
+ constructor(cmd, opts) {
1562
+ super(["smismember", cmd[0], ...cmd[1]], opts);
1563
+ }
1564
+ };
1565
+
1566
+ // pkg/commands/smove.ts
1567
+ var SMoveCommand = class extends Command {
1568
+ constructor(cmd, opts) {
1569
+ super(["smove", ...cmd], opts);
1570
+ }
1571
+ };
1572
+
1573
+ // pkg/commands/spop.ts
1574
+ var SPopCommand = class extends Command {
1575
+ constructor([key, count], opts) {
1576
+ const command = ["spop", key];
1577
+ if (typeof count === "number") {
1578
+ command.push(count);
1579
+ }
1580
+ super(command, opts);
1581
+ }
1582
+ };
1583
+
1584
+ // pkg/commands/srandmember.ts
1585
+ var SRandMemberCommand = class extends Command {
1586
+ constructor([key, count], opts) {
1587
+ const command = ["srandmember", key];
1588
+ if (typeof count === "number") {
1589
+ command.push(count);
1590
+ }
1591
+ super(command, opts);
1592
+ }
1593
+ };
1594
+
1595
+ // pkg/commands/srem.ts
1596
+ var SRemCommand = class extends Command {
1597
+ constructor(cmd, opts) {
1598
+ super(["srem", ...cmd], opts);
1599
+ }
1600
+ };
1601
+
1602
+ // pkg/commands/sscan.ts
1603
+ var SScanCommand = class extends Command {
1604
+ constructor([key, cursor, opts], cmdOpts) {
1605
+ const command = ["sscan", key, cursor];
1606
+ if (opts?.match) {
1607
+ command.push("match", opts.match);
1608
+ }
1609
+ if (typeof opts?.count === "number") {
1610
+ command.push("count", opts.count);
1611
+ }
1612
+ super(command, {
1613
+ deserialize: deserializeScanResponse,
1614
+ ...cmdOpts
1615
+ });
1616
+ }
1617
+ };
1618
+
1619
+ // pkg/commands/strlen.ts
1620
+ var StrLenCommand = class extends Command {
1621
+ constructor(cmd, opts) {
1622
+ super(["strlen", ...cmd], opts);
1623
+ }
1624
+ };
1625
+
1626
+ // pkg/commands/sunion.ts
1627
+ var SUnionCommand = class extends Command {
1628
+ constructor(cmd, opts) {
1629
+ super(["sunion", ...cmd], opts);
1630
+ }
1631
+ };
1632
+
1633
+ // pkg/commands/sunionstore.ts
1634
+ var SUnionStoreCommand = class extends Command {
1635
+ constructor(cmd, opts) {
1636
+ super(["sunionstore", ...cmd], opts);
1637
+ }
1638
+ };
1639
+
1640
+ // pkg/commands/time.ts
1641
+ var TimeCommand = class extends Command {
1642
+ constructor(opts) {
1643
+ super(["time"], opts);
1644
+ }
1645
+ };
1646
+
1647
+ // pkg/commands/touch.ts
1648
+ var TouchCommand = class extends Command {
1649
+ constructor(cmd, opts) {
1650
+ super(["touch", ...cmd], opts);
1651
+ }
1652
+ };
1653
+
1654
+ // pkg/commands/ttl.ts
1655
+ var TtlCommand = class extends Command {
1656
+ constructor(cmd, opts) {
1657
+ super(["ttl", ...cmd], opts);
1658
+ }
1659
+ };
1660
+
1661
+ // pkg/commands/type.ts
1662
+ var TypeCommand = class extends Command {
1663
+ constructor(cmd, opts) {
1664
+ super(["type", ...cmd], opts);
1665
+ }
1666
+ };
1667
+
1668
+ // pkg/commands/unlink.ts
1669
+ var UnlinkCommand = class extends Command {
1670
+ constructor(cmd, opts) {
1671
+ super(["unlink", ...cmd], opts);
1672
+ }
1673
+ };
1674
+
1675
+ // pkg/commands/xack.ts
1676
+ var XAckCommand = class extends Command {
1677
+ constructor([key, group, id], opts) {
1678
+ const ids = Array.isArray(id) ? [...id] : [id];
1679
+ super(["XACK", key, group, ...ids], opts);
1680
+ }
1681
+ };
1682
+
1683
+ // pkg/commands/xadd.ts
1684
+ var XAddCommand = class extends Command {
1685
+ constructor([key, id, entries, opts], commandOptions) {
1686
+ const command = ["XADD", key];
1687
+ if (opts) {
1688
+ if (opts.nomkStream) {
1689
+ command.push("NOMKSTREAM");
1690
+ }
1691
+ if (opts.trim) {
1692
+ command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
1693
+ if (opts.trim.limit !== void 0) {
1694
+ command.push("LIMIT", opts.trim.limit);
1695
+ }
1696
+ }
1697
+ }
1698
+ command.push(id);
1699
+ for (const [k, v] of Object.entries(entries)) {
1700
+ command.push(k, v);
1701
+ }
1702
+ super(command, commandOptions);
1703
+ }
1704
+ };
1705
+
1706
+ // pkg/commands/xautoclaim.ts
1707
+ var XAutoClaim = class extends Command {
1708
+ constructor([key, group, consumer, minIdleTime, start, options], opts) {
1709
+ const commands = [];
1710
+ if (options?.count) {
1711
+ commands.push("COUNT", options.count);
1712
+ }
1713
+ if (options?.justId) {
1714
+ commands.push("JUSTID");
1715
+ }
1716
+ super(["XAUTOCLAIM", key, group, consumer, minIdleTime, start, ...commands], opts);
1717
+ }
1718
+ };
1719
+
1720
+ // pkg/commands/xclaim.ts
1721
+ var XClaimCommand = class extends Command {
1722
+ constructor([key, group, consumer, minIdleTime, id, options], opts) {
1723
+ const ids = Array.isArray(id) ? [...id] : [id];
1724
+ const commands = [];
1725
+ if (options?.idleMS) {
1726
+ commands.push("IDLE", options.idleMS);
1727
+ }
1728
+ if (options?.idleMS) {
1729
+ commands.push("TIME", options.timeMS);
1730
+ }
1731
+ if (options?.retryCount) {
1732
+ commands.push("RETRYCOUNT", options.retryCount);
1733
+ }
1734
+ if (options?.force) {
1735
+ commands.push("FORCE");
1736
+ }
1737
+ if (options?.justId) {
1738
+ commands.push("JUSTID");
1739
+ }
1740
+ if (options?.lastId) {
1741
+ commands.push("LASTID", options.lastId);
1742
+ }
1743
+ super(["XCLAIM", key, group, consumer, minIdleTime, ...ids, ...commands], opts);
1744
+ }
1745
+ };
1746
+
1747
+ // pkg/commands/xdel.ts
1748
+ var XDelCommand = class extends Command {
1749
+ constructor([key, ids], opts) {
1750
+ const cmds = Array.isArray(ids) ? [...ids] : [ids];
1751
+ super(["XDEL", key, ...cmds], opts);
1752
+ }
1753
+ };
1754
+
1755
+ // pkg/commands/xgroup.ts
1756
+ var XGroupCommand = class extends Command {
1757
+ constructor([key, opts], commandOptions) {
1758
+ const command = ["XGROUP"];
1759
+ switch (opts.type) {
1760
+ case "CREATE": {
1761
+ command.push("CREATE", key, opts.group, opts.id);
1762
+ if (opts.options) {
1763
+ if (opts.options.MKSTREAM) {
1764
+ command.push("MKSTREAM");
1765
+ }
1766
+ if (opts.options.ENTRIESREAD !== void 0) {
1767
+ command.push("ENTRIESREAD", opts.options.ENTRIESREAD.toString());
1768
+ }
1769
+ }
1770
+ break;
1771
+ }
1772
+ case "CREATECONSUMER": {
1773
+ command.push("CREATECONSUMER", key, opts.group, opts.consumer);
1774
+ break;
1775
+ }
1776
+ case "DELCONSUMER": {
1777
+ command.push("DELCONSUMER", key, opts.group, opts.consumer);
1778
+ break;
1779
+ }
1780
+ case "DESTROY": {
1781
+ command.push("DESTROY", key, opts.group);
1782
+ break;
1783
+ }
1784
+ case "SETID": {
1785
+ command.push("SETID", key, opts.group, opts.id);
1786
+ if (opts.options?.ENTRIESREAD !== void 0) {
1787
+ command.push("ENTRIESREAD", opts.options.ENTRIESREAD.toString());
1788
+ }
1789
+ break;
1790
+ }
1791
+ default: {
1792
+ throw new Error("Invalid XGROUP");
1793
+ }
1794
+ }
1795
+ super(command, commandOptions);
1796
+ }
1797
+ };
1798
+
1799
+ // pkg/commands/xinfo.ts
1800
+ var XInfoCommand = class extends Command {
1801
+ constructor([key, options], opts) {
1802
+ const cmds = [];
1803
+ if (options.type === "CONSUMERS") {
1804
+ cmds.push("CONSUMERS", key, options.group);
1805
+ } else {
1806
+ cmds.push("GROUPS", key);
1807
+ }
1808
+ super(["XINFO", ...cmds], opts);
1809
+ }
1810
+ };
1811
+
1812
+ // pkg/commands/xlen.ts
1813
+ var XLenCommand = class extends Command {
1814
+ constructor(cmd, opts) {
1815
+ super(["XLEN", ...cmd], opts);
1816
+ }
1817
+ };
1818
+
1819
+ // pkg/commands/xpending.ts
1820
+ var XPendingCommand = class extends Command {
1821
+ constructor([key, group, start, end, count, options], opts) {
1822
+ const consumers = options?.consumer === void 0 ? [] : Array.isArray(options.consumer) ? [...options.consumer] : [options.consumer];
1823
+ super(
1824
+ [
1825
+ "XPENDING",
1826
+ key,
1827
+ group,
1828
+ ...options?.idleTime ? ["IDLE", options.idleTime] : [],
1829
+ start,
1830
+ end,
1831
+ count,
1832
+ ...consumers
1833
+ ],
1834
+ opts
1835
+ );
1836
+ }
1837
+ };
1838
+
1839
+ // pkg/commands/xrange.ts
1840
+ function deserialize4(result) {
1841
+ const obj = {};
1842
+ for (const e of result) {
1843
+ while (e.length >= 2) {
1844
+ const streamId = e.shift();
1845
+ const entries = e.shift();
1846
+ if (!(streamId in obj)) {
1847
+ obj[streamId] = {};
1848
+ }
1849
+ while (entries.length >= 2) {
1850
+ const field = entries.shift();
1851
+ const value = entries.shift();
1852
+ try {
1853
+ obj[streamId][field] = JSON.parse(value);
1854
+ } catch {
1855
+ obj[streamId][field] = value;
1856
+ }
1857
+ }
1858
+ }
1859
+ }
1860
+ return obj;
1861
+ }
1862
+ var XRangeCommand = class extends Command {
1863
+ constructor([key, start, end, count], opts) {
1864
+ const command = ["XRANGE", key, start, end];
1865
+ if (typeof count === "number") {
1866
+ command.push("COUNT", count);
1867
+ }
1868
+ super(command, {
1869
+ deserialize: (result) => deserialize4(result),
1870
+ ...opts
1871
+ });
1872
+ }
1873
+ };
1874
+
1875
+ // pkg/commands/xread.ts
1876
+ var UNBALANCED_XREAD_ERR = "ERR Unbalanced XREAD list of streams: for each stream key an ID or '$' must be specified";
1877
+ var XReadCommand = class extends Command {
1878
+ constructor([key, id, options], opts) {
1879
+ if (Array.isArray(key) && Array.isArray(id) && key.length !== id.length) {
1880
+ throw new Error(UNBALANCED_XREAD_ERR);
1881
+ }
1882
+ const commands = [];
1883
+ if (typeof options?.count === "number") {
1884
+ commands.push("COUNT", options.count);
1885
+ }
1886
+ if (typeof options?.blockMS === "number") {
1887
+ commands.push("BLOCK", options.blockMS);
1888
+ }
1889
+ commands.push(
1890
+ "STREAMS",
1891
+ ...Array.isArray(key) ? [...key] : [key],
1892
+ ...Array.isArray(id) ? [...id] : [id]
1893
+ );
1894
+ super(["XREAD", ...commands], opts);
1895
+ }
1896
+ };
1897
+
1898
+ // pkg/commands/xreadgroup.ts
1899
+ var UNBALANCED_XREADGROUP_ERR = "ERR Unbalanced XREADGROUP list of streams: for each stream key an ID or '$' must be specified";
1900
+ var XReadGroupCommand = class extends Command {
1901
+ constructor([group, consumer, key, id, options], opts) {
1902
+ if (Array.isArray(key) && Array.isArray(id) && key.length !== id.length) {
1903
+ throw new Error(UNBALANCED_XREADGROUP_ERR);
1904
+ }
1905
+ const commands = [];
1906
+ if (typeof options?.count === "number") {
1907
+ commands.push("COUNT", options.count);
1908
+ }
1909
+ if (typeof options?.blockMS === "number") {
1910
+ commands.push("BLOCK", options.blockMS);
1911
+ }
1912
+ if (typeof options?.NOACK === "boolean" && options.NOACK) {
1913
+ commands.push("NOACK");
1914
+ }
1915
+ commands.push(
1916
+ "STREAMS",
1917
+ ...Array.isArray(key) ? [...key] : [key],
1918
+ ...Array.isArray(id) ? [...id] : [id]
1919
+ );
1920
+ super(["XREADGROUP", "GROUP", group, consumer, ...commands], opts);
1921
+ }
1922
+ };
1923
+
1924
+ // pkg/commands/xrevrange.ts
1925
+ var XRevRangeCommand = class extends Command {
1926
+ constructor([key, end, start, count], opts) {
1927
+ const command = ["XREVRANGE", key, end, start];
1928
+ if (typeof count === "number") {
1929
+ command.push("COUNT", count);
1930
+ }
1931
+ super(command, {
1932
+ deserialize: (result) => deserialize5(result),
1933
+ ...opts
1934
+ });
1935
+ }
1936
+ };
1937
+ function deserialize5(result) {
1938
+ const obj = {};
1939
+ for (const e of result) {
1940
+ while (e.length >= 2) {
1941
+ const streamId = e.shift();
1942
+ const entries = e.shift();
1943
+ if (!(streamId in obj)) {
1944
+ obj[streamId] = {};
1945
+ }
1946
+ while (entries.length >= 2) {
1947
+ const field = entries.shift();
1948
+ const value = entries.shift();
1949
+ try {
1950
+ obj[streamId][field] = JSON.parse(value);
1951
+ } catch {
1952
+ obj[streamId][field] = value;
1953
+ }
1954
+ }
1955
+ }
1956
+ }
1957
+ return obj;
1958
+ }
1959
+
1960
+ // pkg/commands/xtrim.ts
1961
+ var XTrimCommand = class extends Command {
1962
+ constructor([key, options], opts) {
1963
+ const { limit, strategy, threshold, exactness = "~" } = options;
1964
+ super(["XTRIM", key, strategy, exactness, threshold, ...limit ? ["LIMIT", limit] : []], opts);
1965
+ }
1966
+ };
1967
+
1968
+ // pkg/commands/zadd.ts
1969
+ var ZAddCommand = class extends Command {
1970
+ constructor([key, arg1, ...arg2], opts) {
1971
+ const command = ["zadd", key];
1972
+ if ("nx" in arg1 && arg1.nx) {
1973
+ command.push("nx");
1974
+ } else if ("xx" in arg1 && arg1.xx) {
1975
+ command.push("xx");
1976
+ }
1977
+ if ("ch" in arg1 && arg1.ch) {
1978
+ command.push("ch");
1979
+ }
1980
+ if ("incr" in arg1 && arg1.incr) {
1981
+ command.push("incr");
1982
+ }
1983
+ if ("lt" in arg1 && arg1.lt) {
1984
+ command.push("lt");
1985
+ } else if ("gt" in arg1 && arg1.gt) {
1986
+ command.push("gt");
1987
+ }
1988
+ if ("score" in arg1 && "member" in arg1) {
1989
+ command.push(arg1.score, arg1.member);
1990
+ }
1991
+ command.push(...arg2.flatMap(({ score, member }) => [score, member]));
1992
+ super(command, opts);
1993
+ }
1994
+ };
1995
+
1996
+ // pkg/commands/zcard.ts
1997
+ var ZCardCommand = class extends Command {
1998
+ constructor(cmd, opts) {
1999
+ super(["zcard", ...cmd], opts);
2000
+ }
2001
+ };
2002
+
2003
+ // pkg/commands/zcount.ts
2004
+ var ZCountCommand = class extends Command {
2005
+ constructor(cmd, opts) {
2006
+ super(["zcount", ...cmd], opts);
2007
+ }
2008
+ };
2009
+
2010
+ // pkg/commands/zincrby.ts
2011
+ var ZIncrByCommand = class extends Command {
2012
+ constructor(cmd, opts) {
2013
+ super(["zincrby", ...cmd], opts);
2014
+ }
2015
+ };
2016
+
2017
+ // pkg/commands/zinterstore.ts
2018
+ var ZInterStoreCommand = class extends Command {
2019
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
2020
+ const command = ["zinterstore", destination, numKeys];
2021
+ if (Array.isArray(keyOrKeys)) {
2022
+ command.push(...keyOrKeys);
2023
+ } else {
2024
+ command.push(keyOrKeys);
2025
+ }
2026
+ if (opts) {
2027
+ if ("weights" in opts && opts.weights) {
2028
+ command.push("weights", ...opts.weights);
2029
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2030
+ command.push("weights", opts.weight);
2031
+ }
2032
+ if ("aggregate" in opts) {
2033
+ command.push("aggregate", opts.aggregate);
2034
+ }
2035
+ }
2036
+ super(command, cmdOpts);
2037
+ }
2038
+ };
2039
+
2040
+ // pkg/commands/zlexcount.ts
2041
+ var ZLexCountCommand = class extends Command {
2042
+ constructor(cmd, opts) {
2043
+ super(["zlexcount", ...cmd], opts);
2044
+ }
2045
+ };
2046
+
2047
+ // pkg/commands/zpopmax.ts
2048
+ var ZPopMaxCommand = class extends Command {
2049
+ constructor([key, count], opts) {
2050
+ const command = ["zpopmax", key];
2051
+ if (typeof count === "number") {
2052
+ command.push(count);
2053
+ }
2054
+ super(command, opts);
2055
+ }
2056
+ };
2057
+
2058
+ // pkg/commands/zpopmin.ts
2059
+ var ZPopMinCommand = class extends Command {
2060
+ constructor([key, count], opts) {
2061
+ const command = ["zpopmin", key];
2062
+ if (typeof count === "number") {
2063
+ command.push(count);
2064
+ }
2065
+ super(command, opts);
2066
+ }
2067
+ };
2068
+
2069
+ // pkg/commands/zrange.ts
2070
+ var ZRangeCommand = class extends Command {
2071
+ constructor([key, min, max, opts], cmdOpts) {
2072
+ const command = ["zrange", key, min, max];
2073
+ if (opts?.byScore) {
2074
+ command.push("byscore");
2075
+ }
2076
+ if (opts?.byLex) {
2077
+ command.push("bylex");
2078
+ }
2079
+ if (opts?.rev) {
2080
+ command.push("rev");
2081
+ }
2082
+ if (opts?.count !== void 0 && opts.offset !== void 0) {
2083
+ command.push("limit", opts.offset, opts.count);
2084
+ }
2085
+ if (opts?.withScores) {
2086
+ command.push("withscores");
2087
+ }
2088
+ super(command, cmdOpts);
2089
+ }
2090
+ };
2091
+
2092
+ // pkg/commands/zrank.ts
2093
+ var ZRankCommand = class extends Command {
2094
+ constructor(cmd, opts) {
2095
+ super(["zrank", ...cmd], opts);
2096
+ }
2097
+ };
2098
+
2099
+ // pkg/commands/zrem.ts
2100
+ var ZRemCommand = class extends Command {
2101
+ constructor(cmd, opts) {
2102
+ super(["zrem", ...cmd], opts);
2103
+ }
2104
+ };
2105
+
2106
+ // pkg/commands/zremrangebylex.ts
2107
+ var ZRemRangeByLexCommand = class extends Command {
2108
+ constructor(cmd, opts) {
2109
+ super(["zremrangebylex", ...cmd], opts);
2110
+ }
2111
+ };
2112
+
2113
+ // pkg/commands/zremrangebyrank.ts
2114
+ var ZRemRangeByRankCommand = class extends Command {
2115
+ constructor(cmd, opts) {
2116
+ super(["zremrangebyrank", ...cmd], opts);
2117
+ }
2118
+ };
2119
+
2120
+ // pkg/commands/zremrangebyscore.ts
2121
+ var ZRemRangeByScoreCommand = class extends Command {
2122
+ constructor(cmd, opts) {
2123
+ super(["zremrangebyscore", ...cmd], opts);
2124
+ }
2125
+ };
2126
+
2127
+ // pkg/commands/zrevrank.ts
2128
+ var ZRevRankCommand = class extends Command {
2129
+ constructor(cmd, opts) {
2130
+ super(["zrevrank", ...cmd], opts);
2131
+ }
2132
+ };
2133
+
2134
+ // pkg/commands/zscan.ts
2135
+ var ZScanCommand = class extends Command {
2136
+ constructor([key, cursor, opts], cmdOpts) {
2137
+ const command = ["zscan", key, cursor];
2138
+ if (opts?.match) {
2139
+ command.push("match", opts.match);
2140
+ }
2141
+ if (typeof opts?.count === "number") {
2142
+ command.push("count", opts.count);
2143
+ }
2144
+ super(command, {
2145
+ deserialize: deserializeScanResponse,
2146
+ ...cmdOpts
2147
+ });
2148
+ }
2149
+ };
2150
+
2151
+ // pkg/commands/zscore.ts
2152
+ var ZScoreCommand = class extends Command {
2153
+ constructor(cmd, opts) {
2154
+ super(["zscore", ...cmd], opts);
2155
+ }
2156
+ };
2157
+
2158
+ // pkg/commands/zunion.ts
2159
+ var ZUnionCommand = class extends Command {
2160
+ constructor([numKeys, keyOrKeys, opts], cmdOpts) {
2161
+ const command = ["zunion", numKeys];
2162
+ if (Array.isArray(keyOrKeys)) {
2163
+ command.push(...keyOrKeys);
2164
+ } else {
2165
+ command.push(keyOrKeys);
2166
+ }
2167
+ if (opts) {
2168
+ if ("weights" in opts && opts.weights) {
2169
+ command.push("weights", ...opts.weights);
2170
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2171
+ command.push("weights", opts.weight);
2172
+ }
2173
+ if ("aggregate" in opts) {
2174
+ command.push("aggregate", opts.aggregate);
2175
+ }
2176
+ if (opts.withScores) {
2177
+ command.push("withscores");
2178
+ }
2179
+ }
2180
+ super(command, cmdOpts);
2181
+ }
2182
+ };
2183
+
2184
+ // pkg/commands/zunionstore.ts
2185
+ var ZUnionStoreCommand = class extends Command {
2186
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
2187
+ const command = ["zunionstore", destination, numKeys];
2188
+ if (Array.isArray(keyOrKeys)) {
2189
+ command.push(...keyOrKeys);
2190
+ } else {
2191
+ command.push(keyOrKeys);
2192
+ }
2193
+ if (opts) {
2194
+ if ("weights" in opts && opts.weights) {
2195
+ command.push("weights", ...opts.weights);
2196
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2197
+ command.push("weights", opts.weight);
2198
+ }
2199
+ if ("aggregate" in opts) {
2200
+ command.push("aggregate", opts.aggregate);
2201
+ }
2202
+ }
2203
+ super(command, cmdOpts);
2204
+ }
2205
+ };
2206
+
2207
+ // pkg/commands/zdiffstore.ts
2208
+ var ZDiffStoreCommand = class extends Command {
2209
+ constructor(cmd, opts) {
2210
+ super(["zdiffstore", ...cmd], opts);
2211
+ }
2212
+ };
2213
+
2214
+ // pkg/commands/zmscore.ts
2215
+ var ZMScoreCommand = class extends Command {
2216
+ constructor(cmd, opts) {
2217
+ const [key, members] = cmd;
2218
+ super(["zmscore", key, ...members], opts);
2219
+ }
2220
+ };
2221
+
2222
+ // pkg/pipeline.ts
2223
+ var Pipeline = class {
2224
+ client;
2225
+ commands;
2226
+ commandOptions;
2227
+ multiExec;
2228
+ constructor(opts) {
2229
+ this.client = opts.client;
2230
+ this.commands = [];
2231
+ this.commandOptions = opts.commandOptions;
2232
+ this.multiExec = opts.multiExec ?? false;
2233
+ if (this.commandOptions?.latencyLogging) {
2234
+ const originalExec = this.exec.bind(this);
2235
+ this.exec = async (options) => {
2236
+ const start = performance.now();
2237
+ const result = await (options ? originalExec(options) : originalExec());
2238
+ const end = performance.now();
2239
+ const loggerResult = (end - start).toFixed(2);
2240
+ console.log(
2241
+ `Latency for \x1B[38;2;19;185;39m${this.multiExec ? ["MULTI-EXEC"] : ["PIPELINE"].toString().toUpperCase()}\x1B[0m: \x1B[38;2;0;255;255m${loggerResult} ms\x1B[0m`
2242
+ );
2243
+ return result;
2244
+ };
2245
+ }
2246
+ }
2247
+ exec = async (options) => {
2248
+ if (this.commands.length === 0) {
2249
+ throw new Error("Pipeline is empty");
2250
+ }
2251
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
2252
+ const res = await this.client.request({
2253
+ path,
2254
+ body: Object.values(this.commands).map((c) => c.command)
2255
+ });
2256
+ return options?.keepErrors ? res.map(({ error, result }, i) => {
2257
+ return {
2258
+ error,
2259
+ result: this.commands[i].deserialize(result)
2260
+ };
2261
+ }) : res.map(({ error, result }, i) => {
2262
+ if (error) {
2263
+ throw new UpstashError(
2264
+ `Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`
2265
+ );
2266
+ }
2267
+ return this.commands[i].deserialize(result);
2268
+ });
2269
+ };
2270
+ /**
2271
+ * Returns the length of pipeline before the execution
2272
+ */
2273
+ length() {
2274
+ return this.commands.length;
2275
+ }
2276
+ /**
2277
+ * Pushes a command into the pipeline and returns a chainable instance of the
2278
+ * pipeline
2279
+ */
2280
+ chain(command) {
2281
+ this.commands.push(command);
2282
+ return this;
2283
+ }
2284
+ /**
2285
+ * @see https://redis.io/commands/append
2286
+ */
2287
+ append = (...args) => this.chain(new AppendCommand(args, this.commandOptions));
2288
+ /**
2289
+ * @see https://redis.io/commands/bitcount
2290
+ */
2291
+ bitcount = (...args) => this.chain(new BitCountCommand(args, this.commandOptions));
2292
+ /**
2293
+ * Returns an instance that can be used to execute `BITFIELD` commands on one key.
2294
+ *
2295
+ * @example
2296
+ * ```typescript
2297
+ * redis.set("mykey", 0);
2298
+ * const result = await redis.pipeline()
2299
+ * .bitfield("mykey")
2300
+ * .set("u4", 0, 16)
2301
+ * .incr("u4", "#1", 1)
2302
+ * .exec();
2303
+ * console.log(result); // [[0, 1]]
2304
+ * ```
2305
+ *
2306
+ * @see https://redis.io/commands/bitfield
2307
+ */
2308
+ bitfield = (...args) => new BitFieldCommand(args, this.client, this.commandOptions, this.chain.bind(this));
2309
+ /**
2310
+ * @see https://redis.io/commands/bitop
2311
+ */
2312
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => this.chain(
2313
+ new BitOpCommand([op, destinationKey, sourceKey, ...sourceKeys], this.commandOptions)
2314
+ );
2315
+ /**
2316
+ * @see https://redis.io/commands/bitpos
2317
+ */
2318
+ bitpos = (...args) => this.chain(new BitPosCommand(args, this.commandOptions));
2319
+ /**
2320
+ * @see https://redis.io/commands/copy
2321
+ */
2322
+ copy = (...args) => this.chain(new CopyCommand(args, this.commandOptions));
2323
+ /**
2324
+ * @see https://redis.io/commands/zdiffstore
2325
+ */
2326
+ zdiffstore = (...args) => this.chain(new ZDiffStoreCommand(args, this.commandOptions));
2327
+ /**
2328
+ * @see https://redis.io/commands/dbsize
2329
+ */
2330
+ dbsize = () => this.chain(new DBSizeCommand(this.commandOptions));
2331
+ /**
2332
+ * @see https://redis.io/commands/decr
2333
+ */
2334
+ decr = (...args) => this.chain(new DecrCommand(args, this.commandOptions));
2335
+ /**
2336
+ * @see https://redis.io/commands/decrby
2337
+ */
2338
+ decrby = (...args) => this.chain(new DecrByCommand(args, this.commandOptions));
2339
+ /**
2340
+ * @see https://redis.io/commands/del
2341
+ */
2342
+ del = (...args) => this.chain(new DelCommand(args, this.commandOptions));
2343
+ /**
2344
+ * @see https://redis.io/commands/echo
2345
+ */
2346
+ echo = (...args) => this.chain(new EchoCommand(args, this.commandOptions));
2347
+ /**
2348
+ * @see https://redis.io/commands/eval
2349
+ */
2350
+ eval = (...args) => this.chain(new EvalCommand(args, this.commandOptions));
2351
+ /**
2352
+ * @see https://redis.io/commands/evalsha
2353
+ */
2354
+ evalsha = (...args) => this.chain(new EvalshaCommand(args, this.commandOptions));
2355
+ /**
2356
+ * @see https://redis.io/commands/exists
2357
+ */
2358
+ exists = (...args) => this.chain(new ExistsCommand(args, this.commandOptions));
2359
+ /**
2360
+ * @see https://redis.io/commands/expire
2361
+ */
2362
+ expire = (...args) => this.chain(new ExpireCommand(args, this.commandOptions));
2363
+ /**
2364
+ * @see https://redis.io/commands/expireat
2365
+ */
2366
+ expireat = (...args) => this.chain(new ExpireAtCommand(args, this.commandOptions));
2367
+ /**
2368
+ * @see https://redis.io/commands/flushall
2369
+ */
2370
+ flushall = (args) => this.chain(new FlushAllCommand(args, this.commandOptions));
2371
+ /**
2372
+ * @see https://redis.io/commands/flushdb
2373
+ */
2374
+ flushdb = (...args) => this.chain(new FlushDBCommand(args, this.commandOptions));
2375
+ /**
2376
+ * @see https://redis.io/commands/geoadd
2377
+ */
2378
+ geoadd = (...args) => this.chain(new GeoAddCommand(args, this.commandOptions));
2379
+ /**
2380
+ * @see https://redis.io/commands/geodist
2381
+ */
2382
+ geodist = (...args) => this.chain(new GeoDistCommand(args, this.commandOptions));
2383
+ /**
2384
+ * @see https://redis.io/commands/geopos
2385
+ */
2386
+ geopos = (...args) => this.chain(new GeoPosCommand(args, this.commandOptions));
2387
+ /**
2388
+ * @see https://redis.io/commands/geohash
2389
+ */
2390
+ geohash = (...args) => this.chain(new GeoHashCommand(args, this.commandOptions));
2391
+ /**
2392
+ * @see https://redis.io/commands/geosearch
2393
+ */
2394
+ geosearch = (...args) => this.chain(new GeoSearchCommand(args, this.commandOptions));
2395
+ /**
2396
+ * @see https://redis.io/commands/geosearchstore
2397
+ */
2398
+ geosearchstore = (...args) => this.chain(new GeoSearchStoreCommand(args, this.commandOptions));
2399
+ /**
2400
+ * @see https://redis.io/commands/get
2401
+ */
2402
+ get = (...args) => this.chain(new GetCommand(args, this.commandOptions));
2403
+ /**
2404
+ * @see https://redis.io/commands/getbit
2405
+ */
2406
+ getbit = (...args) => this.chain(new GetBitCommand(args, this.commandOptions));
2407
+ /**
2408
+ * @see https://redis.io/commands/getdel
2409
+ */
2410
+ getdel = (...args) => this.chain(new GetDelCommand(args, this.commandOptions));
2411
+ /**
2412
+ * @see https://redis.io/commands/getrange
2413
+ */
2414
+ getrange = (...args) => this.chain(new GetRangeCommand(args, this.commandOptions));
2415
+ /**
2416
+ * @see https://redis.io/commands/getset
2417
+ */
2418
+ getset = (key, value) => this.chain(new GetSetCommand([key, value], this.commandOptions));
2419
+ /**
2420
+ * @see https://redis.io/commands/hdel
2421
+ */
2422
+ hdel = (...args) => this.chain(new HDelCommand(args, this.commandOptions));
2423
+ /**
2424
+ * @see https://redis.io/commands/hexists
2425
+ */
2426
+ hexists = (...args) => this.chain(new HExistsCommand(args, this.commandOptions));
2427
+ /**
2428
+ * @see https://redis.io/commands/hget
2429
+ */
2430
+ hget = (...args) => this.chain(new HGetCommand(args, this.commandOptions));
2431
+ /**
2432
+ * @see https://redis.io/commands/hgetall
2433
+ */
2434
+ hgetall = (...args) => this.chain(new HGetAllCommand(args, this.commandOptions));
2435
+ /**
2436
+ * @see https://redis.io/commands/hincrby
2437
+ */
2438
+ hincrby = (...args) => this.chain(new HIncrByCommand(args, this.commandOptions));
2439
+ /**
2440
+ * @see https://redis.io/commands/hincrbyfloat
2441
+ */
2442
+ hincrbyfloat = (...args) => this.chain(new HIncrByFloatCommand(args, this.commandOptions));
2443
+ /**
2444
+ * @see https://redis.io/commands/hkeys
2445
+ */
2446
+ hkeys = (...args) => this.chain(new HKeysCommand(args, this.commandOptions));
2447
+ /**
2448
+ * @see https://redis.io/commands/hlen
2449
+ */
2450
+ hlen = (...args) => this.chain(new HLenCommand(args, this.commandOptions));
2451
+ /**
2452
+ * @see https://redis.io/commands/hmget
2453
+ */
2454
+ hmget = (...args) => this.chain(new HMGetCommand(args, this.commandOptions));
2455
+ /**
2456
+ * @see https://redis.io/commands/hmset
2457
+ */
2458
+ hmset = (key, kv) => this.chain(new HMSetCommand([key, kv], this.commandOptions));
2459
+ /**
2460
+ * @see https://redis.io/commands/hrandfield
2461
+ */
2462
+ hrandfield = (key, count, withValues) => this.chain(new HRandFieldCommand([key, count, withValues], this.commandOptions));
2463
+ /**
2464
+ * @see https://redis.io/commands/hscan
2465
+ */
2466
+ hscan = (...args) => this.chain(new HScanCommand(args, this.commandOptions));
2467
+ /**
2468
+ * @see https://redis.io/commands/hset
2469
+ */
2470
+ hset = (key, kv) => this.chain(new HSetCommand([key, kv], this.commandOptions));
2471
+ /**
2472
+ * @see https://redis.io/commands/hsetnx
2473
+ */
2474
+ hsetnx = (key, field, value) => this.chain(new HSetNXCommand([key, field, value], this.commandOptions));
2475
+ /**
2476
+ * @see https://redis.io/commands/hstrlen
2477
+ */
2478
+ hstrlen = (...args) => this.chain(new HStrLenCommand(args, this.commandOptions));
2479
+ /**
2480
+ * @see https://redis.io/commands/hvals
2481
+ */
2482
+ hvals = (...args) => this.chain(new HValsCommand(args, this.commandOptions));
2483
+ /**
2484
+ * @see https://redis.io/commands/incr
2485
+ */
2486
+ incr = (...args) => this.chain(new IncrCommand(args, this.commandOptions));
2487
+ /**
2488
+ * @see https://redis.io/commands/incrby
2489
+ */
2490
+ incrby = (...args) => this.chain(new IncrByCommand(args, this.commandOptions));
2491
+ /**
2492
+ * @see https://redis.io/commands/incrbyfloat
2493
+ */
2494
+ incrbyfloat = (...args) => this.chain(new IncrByFloatCommand(args, this.commandOptions));
2495
+ /**
2496
+ * @see https://redis.io/commands/keys
2497
+ */
2498
+ keys = (...args) => this.chain(new KeysCommand(args, this.commandOptions));
2499
+ /**
2500
+ * @see https://redis.io/commands/lindex
2501
+ */
2502
+ lindex = (...args) => this.chain(new LIndexCommand(args, this.commandOptions));
2503
+ /**
2504
+ * @see https://redis.io/commands/linsert
2505
+ */
2506
+ linsert = (key, direction, pivot, value) => this.chain(new LInsertCommand([key, direction, pivot, value], this.commandOptions));
2507
+ /**
2508
+ * @see https://redis.io/commands/llen
2509
+ */
2510
+ llen = (...args) => this.chain(new LLenCommand(args, this.commandOptions));
2511
+ /**
2512
+ * @see https://redis.io/commands/lmove
2513
+ */
2514
+ lmove = (...args) => this.chain(new LMoveCommand(args, this.commandOptions));
2515
+ /**
2516
+ * @see https://redis.io/commands/lpop
2517
+ */
2518
+ lpop = (...args) => this.chain(new LPopCommand(args, this.commandOptions));
2519
+ /**
2520
+ * @see https://redis.io/commands/lmpop
2521
+ */
2522
+ lmpop = (...args) => this.chain(new LmPopCommand(args, this.commandOptions));
2523
+ /**
2524
+ * @see https://redis.io/commands/lpos
2525
+ */
2526
+ lpos = (...args) => this.chain(new LPosCommand(args, this.commandOptions));
2527
+ /**
2528
+ * @see https://redis.io/commands/lpush
2529
+ */
2530
+ lpush = (key, ...elements) => this.chain(new LPushCommand([key, ...elements], this.commandOptions));
2531
+ /**
2532
+ * @see https://redis.io/commands/lpushx
2533
+ */
2534
+ lpushx = (key, ...elements) => this.chain(new LPushXCommand([key, ...elements], this.commandOptions));
2535
+ /**
2536
+ * @see https://redis.io/commands/lrange
2537
+ */
2538
+ lrange = (...args) => this.chain(new LRangeCommand(args, this.commandOptions));
2539
+ /**
2540
+ * @see https://redis.io/commands/lrem
2541
+ */
2542
+ lrem = (key, count, value) => this.chain(new LRemCommand([key, count, value], this.commandOptions));
2543
+ /**
2544
+ * @see https://redis.io/commands/lset
2545
+ */
2546
+ lset = (key, index, value) => this.chain(new LSetCommand([key, index, value], this.commandOptions));
2547
+ /**
2548
+ * @see https://redis.io/commands/ltrim
2549
+ */
2550
+ ltrim = (...args) => this.chain(new LTrimCommand(args, this.commandOptions));
2551
+ /**
2552
+ * @see https://redis.io/commands/mget
2553
+ */
2554
+ mget = (...args) => this.chain(new MGetCommand(args, this.commandOptions));
2555
+ /**
2556
+ * @see https://redis.io/commands/mset
2557
+ */
2558
+ mset = (kv) => this.chain(new MSetCommand([kv], this.commandOptions));
2559
+ /**
2560
+ * @see https://redis.io/commands/msetnx
2561
+ */
2562
+ msetnx = (kv) => this.chain(new MSetNXCommand([kv], this.commandOptions));
2563
+ /**
2564
+ * @see https://redis.io/commands/persist
2565
+ */
2566
+ persist = (...args) => this.chain(new PersistCommand(args, this.commandOptions));
2567
+ /**
2568
+ * @see https://redis.io/commands/pexpire
2569
+ */
2570
+ pexpire = (...args) => this.chain(new PExpireCommand(args, this.commandOptions));
2571
+ /**
2572
+ * @see https://redis.io/commands/pexpireat
2573
+ */
2574
+ pexpireat = (...args) => this.chain(new PExpireAtCommand(args, this.commandOptions));
2575
+ /**
2576
+ * @see https://redis.io/commands/pfadd
2577
+ */
2578
+ pfadd = (...args) => this.chain(new PfAddCommand(args, this.commandOptions));
2579
+ /**
2580
+ * @see https://redis.io/commands/pfcount
2581
+ */
2582
+ pfcount = (...args) => this.chain(new PfCountCommand(args, this.commandOptions));
2583
+ /**
2584
+ * @see https://redis.io/commands/pfmerge
2585
+ */
2586
+ pfmerge = (...args) => this.chain(new PfMergeCommand(args, this.commandOptions));
2587
+ /**
2588
+ * @see https://redis.io/commands/ping
2589
+ */
2590
+ ping = (args) => this.chain(new PingCommand(args, this.commandOptions));
2591
+ /**
2592
+ * @see https://redis.io/commands/psetex
2593
+ */
2594
+ psetex = (key, ttl, value) => this.chain(new PSetEXCommand([key, ttl, value], this.commandOptions));
2595
+ /**
2596
+ * @see https://redis.io/commands/pttl
2597
+ */
2598
+ pttl = (...args) => this.chain(new PTtlCommand(args, this.commandOptions));
2599
+ /**
2600
+ * @see https://redis.io/commands/publish
2601
+ */
2602
+ publish = (...args) => this.chain(new PublishCommand(args, this.commandOptions));
2603
+ /**
2604
+ * @see https://redis.io/commands/randomkey
2605
+ */
2606
+ randomkey = () => this.chain(new RandomKeyCommand(this.commandOptions));
2607
+ /**
2608
+ * @see https://redis.io/commands/rename
2609
+ */
2610
+ rename = (...args) => this.chain(new RenameCommand(args, this.commandOptions));
2611
+ /**
2612
+ * @see https://redis.io/commands/renamenx
2613
+ */
2614
+ renamenx = (...args) => this.chain(new RenameNXCommand(args, this.commandOptions));
2615
+ /**
2616
+ * @see https://redis.io/commands/rpop
2617
+ */
2618
+ rpop = (...args) => this.chain(new RPopCommand(args, this.commandOptions));
2619
+ /**
2620
+ * @see https://redis.io/commands/rpush
2621
+ */
2622
+ rpush = (key, ...elements) => this.chain(new RPushCommand([key, ...elements], this.commandOptions));
2623
+ /**
2624
+ * @see https://redis.io/commands/rpushx
2625
+ */
2626
+ rpushx = (key, ...elements) => this.chain(new RPushXCommand([key, ...elements], this.commandOptions));
2627
+ /**
2628
+ * @see https://redis.io/commands/sadd
2629
+ */
2630
+ sadd = (key, member, ...members) => this.chain(new SAddCommand([key, member, ...members], this.commandOptions));
2631
+ /**
2632
+ * @see https://redis.io/commands/scan
2633
+ */
2634
+ scan = (...args) => this.chain(new ScanCommand(args, this.commandOptions));
2635
+ /**
2636
+ * @see https://redis.io/commands/scard
2637
+ */
2638
+ scard = (...args) => this.chain(new SCardCommand(args, this.commandOptions));
2639
+ /**
2640
+ * @see https://redis.io/commands/script-exists
2641
+ */
2642
+ scriptExists = (...args) => this.chain(new ScriptExistsCommand(args, this.commandOptions));
2643
+ /**
2644
+ * @see https://redis.io/commands/script-flush
2645
+ */
2646
+ scriptFlush = (...args) => this.chain(new ScriptFlushCommand(args, this.commandOptions));
2647
+ /**
2648
+ * @see https://redis.io/commands/script-load
2649
+ */
2650
+ scriptLoad = (...args) => this.chain(new ScriptLoadCommand(args, this.commandOptions));
2651
+ /*)*
2652
+ * @see https://redis.io/commands/sdiff
2653
+ */
2654
+ sdiff = (...args) => this.chain(new SDiffCommand(args, this.commandOptions));
2655
+ /**
2656
+ * @see https://redis.io/commands/sdiffstore
2657
+ */
2658
+ sdiffstore = (...args) => this.chain(new SDiffStoreCommand(args, this.commandOptions));
2659
+ /**
2660
+ * @see https://redis.io/commands/set
2661
+ */
2662
+ set = (key, value, opts) => this.chain(new SetCommand([key, value, opts], this.commandOptions));
2663
+ /**
2664
+ * @see https://redis.io/commands/setbit
2665
+ */
2666
+ setbit = (...args) => this.chain(new SetBitCommand(args, this.commandOptions));
2667
+ /**
2668
+ * @see https://redis.io/commands/setex
2669
+ */
2670
+ setex = (key, ttl, value) => this.chain(new SetExCommand([key, ttl, value], this.commandOptions));
2671
+ /**
2672
+ * @see https://redis.io/commands/setnx
2673
+ */
2674
+ setnx = (key, value) => this.chain(new SetNxCommand([key, value], this.commandOptions));
2675
+ /**
2676
+ * @see https://redis.io/commands/setrange
2677
+ */
2678
+ setrange = (...args) => this.chain(new SetRangeCommand(args, this.commandOptions));
2679
+ /**
2680
+ * @see https://redis.io/commands/sinter
2681
+ */
2682
+ sinter = (...args) => this.chain(new SInterCommand(args, this.commandOptions));
2683
+ /**
2684
+ * @see https://redis.io/commands/sinterstore
2685
+ */
2686
+ sinterstore = (...args) => this.chain(new SInterStoreCommand(args, this.commandOptions));
2687
+ /**
2688
+ * @see https://redis.io/commands/sismember
2689
+ */
2690
+ sismember = (key, member) => this.chain(new SIsMemberCommand([key, member], this.commandOptions));
2691
+ /**
2692
+ * @see https://redis.io/commands/smembers
2693
+ */
2694
+ smembers = (...args) => this.chain(new SMembersCommand(args, this.commandOptions));
2695
+ /**
2696
+ * @see https://redis.io/commands/smismember
2697
+ */
2698
+ smismember = (key, members) => this.chain(new SMIsMemberCommand([key, members], this.commandOptions));
2699
+ /**
2700
+ * @see https://redis.io/commands/smove
2701
+ */
2702
+ smove = (source, destination, member) => this.chain(new SMoveCommand([source, destination, member], this.commandOptions));
2703
+ /**
2704
+ * @see https://redis.io/commands/spop
2705
+ */
2706
+ spop = (...args) => this.chain(new SPopCommand(args, this.commandOptions));
2707
+ /**
2708
+ * @see https://redis.io/commands/srandmember
2709
+ */
2710
+ srandmember = (...args) => this.chain(new SRandMemberCommand(args, this.commandOptions));
2711
+ /**
2712
+ * @see https://redis.io/commands/srem
2713
+ */
2714
+ srem = (key, ...members) => this.chain(new SRemCommand([key, ...members], this.commandOptions));
2715
+ /**
2716
+ * @see https://redis.io/commands/sscan
2717
+ */
2718
+ sscan = (...args) => this.chain(new SScanCommand(args, this.commandOptions));
2719
+ /**
2720
+ * @see https://redis.io/commands/strlen
2721
+ */
2722
+ strlen = (...args) => this.chain(new StrLenCommand(args, this.commandOptions));
2723
+ /**
2724
+ * @see https://redis.io/commands/sunion
2725
+ */
2726
+ sunion = (...args) => this.chain(new SUnionCommand(args, this.commandOptions));
2727
+ /**
2728
+ * @see https://redis.io/commands/sunionstore
2729
+ */
2730
+ sunionstore = (...args) => this.chain(new SUnionStoreCommand(args, this.commandOptions));
2731
+ /**
2732
+ * @see https://redis.io/commands/time
2733
+ */
2734
+ time = () => this.chain(new TimeCommand(this.commandOptions));
2735
+ /**
2736
+ * @see https://redis.io/commands/touch
2737
+ */
2738
+ touch = (...args) => this.chain(new TouchCommand(args, this.commandOptions));
2739
+ /**
2740
+ * @see https://redis.io/commands/ttl
2741
+ */
2742
+ ttl = (...args) => this.chain(new TtlCommand(args, this.commandOptions));
2743
+ /**
2744
+ * @see https://redis.io/commands/type
2745
+ */
2746
+ type = (...args) => this.chain(new TypeCommand(args, this.commandOptions));
2747
+ /**
2748
+ * @see https://redis.io/commands/unlink
2749
+ */
2750
+ unlink = (...args) => this.chain(new UnlinkCommand(args, this.commandOptions));
2751
+ /**
2752
+ * @see https://redis.io/commands/zadd
2753
+ */
2754
+ zadd = (...args) => {
2755
+ if ("score" in args[1]) {
2756
+ return this.chain(
2757
+ new ZAddCommand([args[0], args[1], ...args.slice(2)], this.commandOptions)
2758
+ );
2759
+ }
2760
+ return this.chain(
2761
+ new ZAddCommand(
2762
+ [args[0], args[1], ...args.slice(2)],
2763
+ this.commandOptions
2764
+ )
2765
+ );
2766
+ };
2767
+ /**
2768
+ * @see https://redis.io/commands/xadd
2769
+ */
2770
+ xadd = (...args) => this.chain(new XAddCommand(args, this.commandOptions));
2771
+ /**
2772
+ * @see https://redis.io/commands/xack
2773
+ */
2774
+ xack = (...args) => this.chain(new XAckCommand(args, this.commandOptions));
2775
+ /**
2776
+ * @see https://redis.io/commands/xdel
2777
+ */
2778
+ xdel = (...args) => this.chain(new XDelCommand(args, this.commandOptions));
2779
+ /**
2780
+ * @see https://redis.io/commands/xgroup
2781
+ */
2782
+ xgroup = (...args) => this.chain(new XGroupCommand(args, this.commandOptions));
2783
+ /**
2784
+ * @see https://redis.io/commands/xread
2785
+ */
2786
+ xread = (...args) => this.chain(new XReadCommand(args, this.commandOptions));
2787
+ /**
2788
+ * @see https://redis.io/commands/xreadgroup
2789
+ */
2790
+ xreadgroup = (...args) => this.chain(new XReadGroupCommand(args, this.commandOptions));
2791
+ /**
2792
+ * @see https://redis.io/commands/xinfo
2793
+ */
2794
+ xinfo = (...args) => this.chain(new XInfoCommand(args, this.commandOptions));
2795
+ /**
2796
+ * @see https://redis.io/commands/xlen
2797
+ */
2798
+ xlen = (...args) => this.chain(new XLenCommand(args, this.commandOptions));
2799
+ /**
2800
+ * @see https://redis.io/commands/xpending
2801
+ */
2802
+ xpending = (...args) => this.chain(new XPendingCommand(args, this.commandOptions));
2803
+ /**
2804
+ * @see https://redis.io/commands/xclaim
2805
+ */
2806
+ xclaim = (...args) => this.chain(new XClaimCommand(args, this.commandOptions));
2807
+ /**
2808
+ * @see https://redis.io/commands/xautoclaim
2809
+ */
2810
+ xautoclaim = (...args) => this.chain(new XAutoClaim(args, this.commandOptions));
2811
+ /**
2812
+ * @see https://redis.io/commands/xtrim
2813
+ */
2814
+ xtrim = (...args) => this.chain(new XTrimCommand(args, this.commandOptions));
2815
+ /**
2816
+ * @see https://redis.io/commands/xrange
2817
+ */
2818
+ xrange = (...args) => this.chain(new XRangeCommand(args, this.commandOptions));
2819
+ /**
2820
+ * @see https://redis.io/commands/xrevrange
2821
+ */
2822
+ xrevrange = (...args) => this.chain(new XRevRangeCommand(args, this.commandOptions));
2823
+ /**
2824
+ * @see https://redis.io/commands/zcard
2825
+ */
2826
+ zcard = (...args) => this.chain(new ZCardCommand(args, this.commandOptions));
2827
+ /**
2828
+ * @see https://redis.io/commands/zcount
2829
+ */
2830
+ zcount = (...args) => this.chain(new ZCountCommand(args, this.commandOptions));
2831
+ /**
2832
+ * @see https://redis.io/commands/zincrby
2833
+ */
2834
+ zincrby = (key, increment, member) => this.chain(new ZIncrByCommand([key, increment, member], this.commandOptions));
2835
+ /**
2836
+ * @see https://redis.io/commands/zinterstore
2837
+ */
2838
+ zinterstore = (...args) => this.chain(new ZInterStoreCommand(args, this.commandOptions));
2839
+ /**
2840
+ * @see https://redis.io/commands/zlexcount
2841
+ */
2842
+ zlexcount = (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions));
2843
+ /**
2844
+ * @see https://redis.io/commands/zmscore
2845
+ */
2846
+ zmscore = (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions));
2847
+ /**
2848
+ * @see https://redis.io/commands/zpopmax
2849
+ */
2850
+ zpopmax = (...args) => this.chain(new ZPopMaxCommand(args, this.commandOptions));
2851
+ /**
2852
+ * @see https://redis.io/commands/zpopmin
2853
+ */
2854
+ zpopmin = (...args) => this.chain(new ZPopMinCommand(args, this.commandOptions));
2855
+ /**
2856
+ * @see https://redis.io/commands/zrange
2857
+ */
2858
+ zrange = (...args) => this.chain(new ZRangeCommand(args, this.commandOptions));
2859
+ /**
2860
+ * @see https://redis.io/commands/zrank
2861
+ */
2862
+ zrank = (key, member) => this.chain(new ZRankCommand([key, member], this.commandOptions));
2863
+ /**
2864
+ * @see https://redis.io/commands/zrem
2865
+ */
2866
+ zrem = (key, ...members) => this.chain(new ZRemCommand([key, ...members], this.commandOptions));
2867
+ /**
2868
+ * @see https://redis.io/commands/zremrangebylex
2869
+ */
2870
+ zremrangebylex = (...args) => this.chain(new ZRemRangeByLexCommand(args, this.commandOptions));
2871
+ /**
2872
+ * @see https://redis.io/commands/zremrangebyrank
2873
+ */
2874
+ zremrangebyrank = (...args) => this.chain(new ZRemRangeByRankCommand(args, this.commandOptions));
2875
+ /**
2876
+ * @see https://redis.io/commands/zremrangebyscore
2877
+ */
2878
+ zremrangebyscore = (...args) => this.chain(new ZRemRangeByScoreCommand(args, this.commandOptions));
2879
+ /**
2880
+ * @see https://redis.io/commands/zrevrank
2881
+ */
2882
+ zrevrank = (key, member) => this.chain(new ZRevRankCommand([key, member], this.commandOptions));
2883
+ /**
2884
+ * @see https://redis.io/commands/zscan
2885
+ */
2886
+ zscan = (...args) => this.chain(new ZScanCommand(args, this.commandOptions));
2887
+ /**
2888
+ * @see https://redis.io/commands/zscore
2889
+ */
2890
+ zscore = (key, member) => this.chain(new ZScoreCommand([key, member], this.commandOptions));
2891
+ /**
2892
+ * @see https://redis.io/commands/zunionstore
2893
+ */
2894
+ zunionstore = (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions));
2895
+ /**
2896
+ * @see https://redis.io/commands/zunion
2897
+ */
2898
+ zunion = (...args) => this.chain(new ZUnionCommand(args, this.commandOptions));
2899
+ /**
2900
+ * @see https://redis.io/commands/?group=json
2901
+ */
2902
+ get json() {
2903
+ return {
2904
+ /**
2905
+ * @see https://redis.io/commands/json.arrappend
2906
+ */
2907
+ arrappend: (...args) => this.chain(new JsonArrAppendCommand(args, this.commandOptions)),
2908
+ /**
2909
+ * @see https://redis.io/commands/json.arrindex
2910
+ */
2911
+ arrindex: (...args) => this.chain(new JsonArrIndexCommand(args, this.commandOptions)),
2912
+ /**
2913
+ * @see https://redis.io/commands/json.arrinsert
2914
+ */
2915
+ arrinsert: (...args) => this.chain(new JsonArrInsertCommand(args, this.commandOptions)),
2916
+ /**
2917
+ * @see https://redis.io/commands/json.arrlen
2918
+ */
2919
+ arrlen: (...args) => this.chain(new JsonArrLenCommand(args, this.commandOptions)),
2920
+ /**
2921
+ * @see https://redis.io/commands/json.arrpop
2922
+ */
2923
+ arrpop: (...args) => this.chain(new JsonArrPopCommand(args, this.commandOptions)),
2924
+ /**
2925
+ * @see https://redis.io/commands/json.arrtrim
2926
+ */
2927
+ arrtrim: (...args) => this.chain(new JsonArrTrimCommand(args, this.commandOptions)),
2928
+ /**
2929
+ * @see https://redis.io/commands/json.clear
2930
+ */
2931
+ clear: (...args) => this.chain(new JsonClearCommand(args, this.commandOptions)),
2932
+ /**
2933
+ * @see https://redis.io/commands/json.del
2934
+ */
2935
+ del: (...args) => this.chain(new JsonDelCommand(args, this.commandOptions)),
2936
+ /**
2937
+ * @see https://redis.io/commands/json.forget
2938
+ */
2939
+ forget: (...args) => this.chain(new JsonForgetCommand(args, this.commandOptions)),
2940
+ /**
2941
+ * @see https://redis.io/commands/json.get
2942
+ */
2943
+ get: (...args) => this.chain(new JsonGetCommand(args, this.commandOptions)),
2944
+ /**
2945
+ * @see https://redis.io/commands/json.mget
2946
+ */
2947
+ mget: (...args) => this.chain(new JsonMGetCommand(args, this.commandOptions)),
2948
+ /**
2949
+ * @see https://redis.io/commands/json.mset
2950
+ */
2951
+ mset: (...args) => this.chain(new JsonMSetCommand(args, this.commandOptions)),
2952
+ /**
2953
+ * @see https://redis.io/commands/json.numincrby
2954
+ */
2955
+ numincrby: (...args) => this.chain(new JsonNumIncrByCommand(args, this.commandOptions)),
2956
+ /**
2957
+ * @see https://redis.io/commands/json.nummultby
2958
+ */
2959
+ nummultby: (...args) => this.chain(new JsonNumMultByCommand(args, this.commandOptions)),
2960
+ /**
2961
+ * @see https://redis.io/commands/json.objkeys
2962
+ */
2963
+ objkeys: (...args) => this.chain(new JsonObjKeysCommand(args, this.commandOptions)),
2964
+ /**
2965
+ * @see https://redis.io/commands/json.objlen
2966
+ */
2967
+ objlen: (...args) => this.chain(new JsonObjLenCommand(args, this.commandOptions)),
2968
+ /**
2969
+ * @see https://redis.io/commands/json.resp
2970
+ */
2971
+ resp: (...args) => this.chain(new JsonRespCommand(args, this.commandOptions)),
2972
+ /**
2973
+ * @see https://redis.io/commands/json.set
2974
+ */
2975
+ set: (...args) => this.chain(new JsonSetCommand(args, this.commandOptions)),
2976
+ /**
2977
+ * @see https://redis.io/commands/json.strappend
2978
+ */
2979
+ strappend: (...args) => this.chain(new JsonStrAppendCommand(args, this.commandOptions)),
2980
+ /**
2981
+ * @see https://redis.io/commands/json.strlen
2982
+ */
2983
+ strlen: (...args) => this.chain(new JsonStrLenCommand(args, this.commandOptions)),
2984
+ /**
2985
+ * @see https://redis.io/commands/json.toggle
2986
+ */
2987
+ toggle: (...args) => this.chain(new JsonToggleCommand(args, this.commandOptions)),
2988
+ /**
2989
+ * @see https://redis.io/commands/json.type
2990
+ */
2991
+ type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
2992
+ };
2993
+ }
2994
+ };
2995
+
2996
+ // pkg/script.ts
2997
+ var import_enc_hex = __toESM(require("crypto-js/enc-hex.js"));
2998
+ var import_sha1 = __toESM(require("crypto-js/sha1.js"));
2999
+ var Script = class {
3000
+ script;
3001
+ sha1;
3002
+ redis;
3003
+ constructor(redis, script) {
3004
+ this.redis = redis;
3005
+ this.sha1 = this.digest(script);
3006
+ this.script = script;
3007
+ }
3008
+ /**
3009
+ * Send an `EVAL` command to redis.
3010
+ */
3011
+ async eval(keys, args) {
3012
+ return await this.redis.eval(this.script, keys, args);
3013
+ }
3014
+ /**
3015
+ * Calculates the sha1 hash of the script and then calls `EVALSHA`.
3016
+ */
3017
+ async evalsha(keys, args) {
3018
+ return await this.redis.evalsha(this.sha1, keys, args);
3019
+ }
3020
+ /**
3021
+ * Optimistically try to run `EVALSHA` first.
3022
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL`.
3023
+ *
3024
+ * Following calls will be able to use the cached script
3025
+ */
3026
+ async exec(keys, args) {
3027
+ const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (error) => {
3028
+ if (error instanceof Error && error.message.toLowerCase().includes("noscript")) {
3029
+ return await this.redis.eval(this.script, keys, args);
3030
+ }
3031
+ throw error;
3032
+ });
3033
+ return res;
3034
+ }
3035
+ /**
3036
+ * Compute the sha1 hash of the script and return its hex representation.
3037
+ */
3038
+ digest(s) {
3039
+ return import_enc_hex.default.stringify((0, import_sha1.default)(s));
3040
+ }
3041
+ };
3042
+
3043
+ // pkg/redis.ts
3044
+ var Redis = class {
3045
+ client;
3046
+ opts;
3047
+ enableTelemetry;
3048
+ enableAutoPipelining;
3049
+ /**
3050
+ * Create a new redis client
3051
+ *
3052
+ * @example
3053
+ * ```typescript
3054
+ * const redis = new Redis({
3055
+ * url: "<UPSTASH_REDIS_REST_URL>",
3056
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
3057
+ * });
3058
+ * ```
3059
+ */
3060
+ constructor(client, opts) {
3061
+ this.client = client;
3062
+ this.opts = opts;
3063
+ this.enableTelemetry = opts?.enableTelemetry ?? true;
3064
+ if (opts?.readYourWrites === false) {
3065
+ this.client.readYourWrites = false;
3066
+ }
3067
+ this.enableAutoPipelining = opts?.enableAutoPipelining ?? true;
3068
+ }
3069
+ get readYourWritesSyncToken() {
3070
+ return this.client.upstashSyncToken;
3071
+ }
3072
+ set readYourWritesSyncToken(session) {
3073
+ this.client.upstashSyncToken = session;
3074
+ }
3075
+ get json() {
3076
+ return {
3077
+ /**
3078
+ * @see https://redis.io/commands/json.arrappend
3079
+ */
3080
+ arrappend: (...args) => new JsonArrAppendCommand(args, this.opts).exec(this.client),
3081
+ /**
3082
+ * @see https://redis.io/commands/json.arrindex
3083
+ */
3084
+ arrindex: (...args) => new JsonArrIndexCommand(args, this.opts).exec(this.client),
3085
+ /**
3086
+ * @see https://redis.io/commands/json.arrinsert
3087
+ */
3088
+ arrinsert: (...args) => new JsonArrInsertCommand(args, this.opts).exec(this.client),
3089
+ /**
3090
+ * @see https://redis.io/commands/json.arrlen
3091
+ */
3092
+ arrlen: (...args) => new JsonArrLenCommand(args, this.opts).exec(this.client),
3093
+ /**
3094
+ * @see https://redis.io/commands/json.arrpop
3095
+ */
3096
+ arrpop: (...args) => new JsonArrPopCommand(args, this.opts).exec(this.client),
3097
+ /**
3098
+ * @see https://redis.io/commands/json.arrtrim
3099
+ */
3100
+ arrtrim: (...args) => new JsonArrTrimCommand(args, this.opts).exec(this.client),
3101
+ /**
3102
+ * @see https://redis.io/commands/json.clear
3103
+ */
3104
+ clear: (...args) => new JsonClearCommand(args, this.opts).exec(this.client),
3105
+ /**
3106
+ * @see https://redis.io/commands/json.del
3107
+ */
3108
+ del: (...args) => new JsonDelCommand(args, this.opts).exec(this.client),
3109
+ /**
3110
+ * @see https://redis.io/commands/json.forget
3111
+ */
3112
+ forget: (...args) => new JsonForgetCommand(args, this.opts).exec(this.client),
3113
+ /**
3114
+ * @see https://redis.io/commands/json.get
3115
+ */
3116
+ get: (...args) => new JsonGetCommand(args, this.opts).exec(this.client),
3117
+ /**
3118
+ * @see https://redis.io/commands/json.mget
3119
+ */
3120
+ mget: (...args) => new JsonMGetCommand(args, this.opts).exec(this.client),
3121
+ /**
3122
+ * @see https://redis.io/commands/json.mset
3123
+ */
3124
+ mset: (...args) => new JsonMSetCommand(args, this.opts).exec(this.client),
3125
+ /**
3126
+ * @see https://redis.io/commands/json.numincrby
3127
+ */
3128
+ numincrby: (...args) => new JsonNumIncrByCommand(args, this.opts).exec(this.client),
3129
+ /**
3130
+ * @see https://redis.io/commands/json.nummultby
3131
+ */
3132
+ nummultby: (...args) => new JsonNumMultByCommand(args, this.opts).exec(this.client),
3133
+ /**
3134
+ * @see https://redis.io/commands/json.objkeys
3135
+ */
3136
+ objkeys: (...args) => new JsonObjKeysCommand(args, this.opts).exec(this.client),
3137
+ /**
3138
+ * @see https://redis.io/commands/json.objlen
3139
+ */
3140
+ objlen: (...args) => new JsonObjLenCommand(args, this.opts).exec(this.client),
3141
+ /**
3142
+ * @see https://redis.io/commands/json.resp
3143
+ */
3144
+ resp: (...args) => new JsonRespCommand(args, this.opts).exec(this.client),
3145
+ /**
3146
+ * @see https://redis.io/commands/json.set
3147
+ */
3148
+ set: (...args) => new JsonSetCommand(args, this.opts).exec(this.client),
3149
+ /**
3150
+ * @see https://redis.io/commands/json.strappend
3151
+ */
3152
+ strappend: (...args) => new JsonStrAppendCommand(args, this.opts).exec(this.client),
3153
+ /**
3154
+ * @see https://redis.io/commands/json.strlen
3155
+ */
3156
+ strlen: (...args) => new JsonStrLenCommand(args, this.opts).exec(this.client),
3157
+ /**
3158
+ * @see https://redis.io/commands/json.toggle
3159
+ */
3160
+ toggle: (...args) => new JsonToggleCommand(args, this.opts).exec(this.client),
3161
+ /**
3162
+ * @see https://redis.io/commands/json.type
3163
+ */
3164
+ type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
3165
+ };
3166
+ }
3167
+ /**
3168
+ * Wrap a new middleware around the HTTP client.
3169
+ */
3170
+ use = (middleware) => {
3171
+ const makeRequest = this.client.request.bind(this.client);
3172
+ this.client.request = (req) => middleware(req, makeRequest);
3173
+ };
3174
+ /**
3175
+ * Technically this is not private, we can hide it from intellisense by doing this
3176
+ */
3177
+ addTelemetry = (telemetry) => {
3178
+ if (!this.enableTelemetry) {
3179
+ return;
3180
+ }
3181
+ try {
3182
+ this.client.mergeTelemetry(telemetry);
3183
+ } catch {
3184
+ }
3185
+ };
3186
+ createScript(script) {
3187
+ return new Script(this, script);
3188
+ }
3189
+ /**
3190
+ * Create a new pipeline that allows you to send requests in bulk.
3191
+ *
3192
+ * @see {@link Pipeline}
3193
+ */
3194
+ pipeline = () => new Pipeline({
3195
+ client: this.client,
3196
+ commandOptions: this.opts,
3197
+ multiExec: false
3198
+ });
3199
+ autoPipeline = () => {
3200
+ return createAutoPipelineProxy(this);
3201
+ };
3202
+ /**
3203
+ * Create a new transaction to allow executing multiple steps atomically.
3204
+ *
3205
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
3206
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
3207
+ * guarantees that the commands are executed as a single isolated operation.
3208
+ *
3209
+ * @see {@link Pipeline}
3210
+ */
3211
+ multi = () => new Pipeline({
3212
+ client: this.client,
3213
+ commandOptions: this.opts,
3214
+ multiExec: true
3215
+ });
3216
+ /**
3217
+ * Returns an instance that can be used to execute `BITFIELD` commands on one key.
3218
+ *
3219
+ * @example
3220
+ * ```typescript
3221
+ * redis.set("mykey", 0);
3222
+ * const result = await redis.bitfield("mykey")
3223
+ * .set("u4", 0, 16)
3224
+ * .incr("u4", "#1", 1)
3225
+ * .exec();
3226
+ * console.log(result); // [0, 1]
3227
+ * ```
3228
+ *
3229
+ * @see https://redis.io/commands/bitfield
3230
+ */
3231
+ bitfield = (...args) => new BitFieldCommand(args, this.client, this.opts);
3232
+ /**
3233
+ * @see https://redis.io/commands/append
3234
+ */
3235
+ append = (...args) => new AppendCommand(args, this.opts).exec(this.client);
3236
+ /**
3237
+ * @see https://redis.io/commands/bitcount
3238
+ */
3239
+ bitcount = (...args) => new BitCountCommand(args, this.opts).exec(this.client);
3240
+ /**
3241
+ * @see https://redis.io/commands/bitop
3242
+ */
3243
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => new BitOpCommand([op, destinationKey, sourceKey, ...sourceKeys], this.opts).exec(
3244
+ this.client
3245
+ );
3246
+ /**
3247
+ * @see https://redis.io/commands/bitpos
3248
+ */
3249
+ bitpos = (...args) => new BitPosCommand(args, this.opts).exec(this.client);
3250
+ /**
3251
+ * @see https://redis.io/commands/copy
3252
+ */
3253
+ copy = (...args) => new CopyCommand(args, this.opts).exec(this.client);
3254
+ /**
3255
+ * @see https://redis.io/commands/dbsize
3256
+ */
3257
+ dbsize = () => new DBSizeCommand(this.opts).exec(this.client);
3258
+ /**
3259
+ * @see https://redis.io/commands/decr
3260
+ */
3261
+ decr = (...args) => new DecrCommand(args, this.opts).exec(this.client);
3262
+ /**
3263
+ * @see https://redis.io/commands/decrby
3264
+ */
3265
+ decrby = (...args) => new DecrByCommand(args, this.opts).exec(this.client);
3266
+ /**
3267
+ * @see https://redis.io/commands/del
3268
+ */
3269
+ del = (...args) => new DelCommand(args, this.opts).exec(this.client);
3270
+ /**
3271
+ * @see https://redis.io/commands/echo
3272
+ */
3273
+ echo = (...args) => new EchoCommand(args, this.opts).exec(this.client);
3274
+ /**
3275
+ * @see https://redis.io/commands/eval
3276
+ */
3277
+ eval = (...args) => new EvalCommand(args, this.opts).exec(this.client);
3278
+ /**
3279
+ * @see https://redis.io/commands/evalsha
3280
+ */
3281
+ evalsha = (...args) => new EvalshaCommand(args, this.opts).exec(this.client);
3282
+ /**
3283
+ * @see https://redis.io/commands/exists
3284
+ */
3285
+ exists = (...args) => new ExistsCommand(args, this.opts).exec(this.client);
3286
+ /**
3287
+ * @see https://redis.io/commands/expire
3288
+ */
3289
+ expire = (...args) => new ExpireCommand(args, this.opts).exec(this.client);
3290
+ /**
3291
+ * @see https://redis.io/commands/expireat
3292
+ */
3293
+ expireat = (...args) => new ExpireAtCommand(args, this.opts).exec(this.client);
3294
+ /**
3295
+ * @see https://redis.io/commands/flushall
3296
+ */
3297
+ flushall = (args) => new FlushAllCommand(args, this.opts).exec(this.client);
3298
+ /**
3299
+ * @see https://redis.io/commands/flushdb
3300
+ */
3301
+ flushdb = (...args) => new FlushDBCommand(args, this.opts).exec(this.client);
3302
+ /**
3303
+ * @see https://redis.io/commands/geoadd
3304
+ */
3305
+ geoadd = (...args) => new GeoAddCommand(args, this.opts).exec(this.client);
3306
+ /**
3307
+ * @see https://redis.io/commands/geopos
3308
+ */
3309
+ geopos = (...args) => new GeoPosCommand(args, this.opts).exec(this.client);
3310
+ /**
3311
+ * @see https://redis.io/commands/geodist
3312
+ */
3313
+ geodist = (...args) => new GeoDistCommand(args, this.opts).exec(this.client);
3314
+ /**
3315
+ * @see https://redis.io/commands/geohash
3316
+ */
3317
+ geohash = (...args) => new GeoHashCommand(args, this.opts).exec(this.client);
3318
+ /**
3319
+ * @see https://redis.io/commands/geosearch
3320
+ */
3321
+ geosearch = (...args) => new GeoSearchCommand(args, this.opts).exec(this.client);
3322
+ /**
3323
+ * @see https://redis.io/commands/geosearchstore
3324
+ */
3325
+ geosearchstore = (...args) => new GeoSearchStoreCommand(args, this.opts).exec(this.client);
3326
+ /**
3327
+ * @see https://redis.io/commands/get
3328
+ */
3329
+ get = (...args) => new GetCommand(args, this.opts).exec(this.client);
3330
+ /**
3331
+ * @see https://redis.io/commands/getbit
3332
+ */
3333
+ getbit = (...args) => new GetBitCommand(args, this.opts).exec(this.client);
3334
+ /**
3335
+ * @see https://redis.io/commands/getdel
3336
+ */
3337
+ getdel = (...args) => new GetDelCommand(args, this.opts).exec(this.client);
3338
+ /**
3339
+ * @see https://redis.io/commands/getrange
3340
+ */
3341
+ getrange = (...args) => new GetRangeCommand(args, this.opts).exec(this.client);
3342
+ /**
3343
+ * @see https://redis.io/commands/getset
3344
+ */
3345
+ getset = (key, value) => new GetSetCommand([key, value], this.opts).exec(this.client);
3346
+ /**
3347
+ * @see https://redis.io/commands/hdel
3348
+ */
3349
+ hdel = (...args) => new HDelCommand(args, this.opts).exec(this.client);
3350
+ /**
3351
+ * @see https://redis.io/commands/hexists
3352
+ */
3353
+ hexists = (...args) => new HExistsCommand(args, this.opts).exec(this.client);
3354
+ /**
3355
+ * @see https://redis.io/commands/hget
3356
+ */
3357
+ hget = (...args) => new HGetCommand(args, this.opts).exec(this.client);
3358
+ /**
3359
+ * @see https://redis.io/commands/hgetall
3360
+ */
3361
+ hgetall = (...args) => new HGetAllCommand(args, this.opts).exec(this.client);
3362
+ /**
3363
+ * @see https://redis.io/commands/hincrby
3364
+ */
3365
+ hincrby = (...args) => new HIncrByCommand(args, this.opts).exec(this.client);
3366
+ /**
3367
+ * @see https://redis.io/commands/hincrbyfloat
3368
+ */
3369
+ hincrbyfloat = (...args) => new HIncrByFloatCommand(args, this.opts).exec(this.client);
3370
+ /**
3371
+ * @see https://redis.io/commands/hkeys
3372
+ */
3373
+ hkeys = (...args) => new HKeysCommand(args, this.opts).exec(this.client);
3374
+ /**
3375
+ * @see https://redis.io/commands/hlen
3376
+ */
3377
+ hlen = (...args) => new HLenCommand(args, this.opts).exec(this.client);
3378
+ /**
3379
+ * @see https://redis.io/commands/hmget
3380
+ */
3381
+ hmget = (...args) => new HMGetCommand(args, this.opts).exec(this.client);
3382
+ /**
3383
+ * @see https://redis.io/commands/hmset
3384
+ */
3385
+ hmset = (key, kv) => new HMSetCommand([key, kv], this.opts).exec(this.client);
3386
+ /**
3387
+ * @see https://redis.io/commands/hrandfield
3388
+ */
3389
+ hrandfield = (key, count, withValues) => new HRandFieldCommand([key, count, withValues], this.opts).exec(this.client);
3390
+ /**
3391
+ * @see https://redis.io/commands/hscan
3392
+ */
3393
+ hscan = (...args) => new HScanCommand(args, this.opts).exec(this.client);
3394
+ /**
3395
+ * @see https://redis.io/commands/hset
3396
+ */
3397
+ hset = (key, kv) => new HSetCommand([key, kv], this.opts).exec(this.client);
3398
+ /**
3399
+ * @see https://redis.io/commands/hsetnx
3400
+ */
3401
+ hsetnx = (key, field, value) => new HSetNXCommand([key, field, value], this.opts).exec(this.client);
3402
+ /**
3403
+ * @see https://redis.io/commands/hstrlen
3404
+ */
3405
+ hstrlen = (...args) => new HStrLenCommand(args, this.opts).exec(this.client);
3406
+ /**
3407
+ * @see https://redis.io/commands/hvals
3408
+ */
3409
+ hvals = (...args) => new HValsCommand(args, this.opts).exec(this.client);
3410
+ /**
3411
+ * @see https://redis.io/commands/incr
3412
+ */
3413
+ incr = (...args) => new IncrCommand(args, this.opts).exec(this.client);
3414
+ /**
3415
+ * @see https://redis.io/commands/incrby
3416
+ */
3417
+ incrby = (...args) => new IncrByCommand(args, this.opts).exec(this.client);
3418
+ /**
3419
+ * @see https://redis.io/commands/incrbyfloat
3420
+ */
3421
+ incrbyfloat = (...args) => new IncrByFloatCommand(args, this.opts).exec(this.client);
3422
+ /**
3423
+ * @see https://redis.io/commands/keys
3424
+ */
3425
+ keys = (...args) => new KeysCommand(args, this.opts).exec(this.client);
3426
+ /**
3427
+ * @see https://redis.io/commands/lindex
3428
+ */
3429
+ lindex = (...args) => new LIndexCommand(args, this.opts).exec(this.client);
3430
+ /**
3431
+ * @see https://redis.io/commands/linsert
3432
+ */
3433
+ linsert = (key, direction, pivot, value) => new LInsertCommand([key, direction, pivot, value], this.opts).exec(this.client);
3434
+ /**
3435
+ * @see https://redis.io/commands/llen
3436
+ */
3437
+ llen = (...args) => new LLenCommand(args, this.opts).exec(this.client);
3438
+ /**
3439
+ * @see https://redis.io/commands/lmove
3440
+ */
3441
+ lmove = (...args) => new LMoveCommand(args, this.opts).exec(this.client);
3442
+ /**
3443
+ * @see https://redis.io/commands/lpop
3444
+ */
3445
+ lpop = (...args) => new LPopCommand(args, this.opts).exec(this.client);
3446
+ /**
3447
+ * @see https://redis.io/commands/lmpop
3448
+ */
3449
+ lmpop = (...args) => new LmPopCommand(args, this.opts).exec(this.client);
3450
+ /**
3451
+ * @see https://redis.io/commands/lpos
3452
+ */
3453
+ lpos = (...args) => new LPosCommand(args, this.opts).exec(this.client);
3454
+ /**
3455
+ * @see https://redis.io/commands/lpush
3456
+ */
3457
+ lpush = (key, ...elements) => new LPushCommand([key, ...elements], this.opts).exec(this.client);
3458
+ /**
3459
+ * @see https://redis.io/commands/lpushx
3460
+ */
3461
+ lpushx = (key, ...elements) => new LPushXCommand([key, ...elements], this.opts).exec(this.client);
3462
+ /**
3463
+ * @see https://redis.io/commands/lrange
3464
+ */
3465
+ lrange = (...args) => new LRangeCommand(args, this.opts).exec(this.client);
3466
+ /**
3467
+ * @see https://redis.io/commands/lrem
3468
+ */
3469
+ lrem = (key, count, value) => new LRemCommand([key, count, value], this.opts).exec(this.client);
3470
+ /**
3471
+ * @see https://redis.io/commands/lset
3472
+ */
3473
+ lset = (key, index, value) => new LSetCommand([key, index, value], this.opts).exec(this.client);
3474
+ /**
3475
+ * @see https://redis.io/commands/ltrim
3476
+ */
3477
+ ltrim = (...args) => new LTrimCommand(args, this.opts).exec(this.client);
3478
+ /**
3479
+ * @see https://redis.io/commands/mget
3480
+ */
3481
+ mget = (...args) => new MGetCommand(args, this.opts).exec(this.client);
3482
+ /**
3483
+ * @see https://redis.io/commands/mset
3484
+ */
3485
+ mset = (kv) => new MSetCommand([kv], this.opts).exec(this.client);
3486
+ /**
3487
+ * @see https://redis.io/commands/msetnx
3488
+ */
3489
+ msetnx = (kv) => new MSetNXCommand([kv], this.opts).exec(this.client);
3490
+ /**
3491
+ * @see https://redis.io/commands/persist
3492
+ */
3493
+ persist = (...args) => new PersistCommand(args, this.opts).exec(this.client);
3494
+ /**
3495
+ * @see https://redis.io/commands/pexpire
3496
+ */
3497
+ pexpire = (...args) => new PExpireCommand(args, this.opts).exec(this.client);
3498
+ /**
3499
+ * @see https://redis.io/commands/pexpireat
3500
+ */
3501
+ pexpireat = (...args) => new PExpireAtCommand(args, this.opts).exec(this.client);
3502
+ /**
3503
+ * @see https://redis.io/commands/pfadd
3504
+ */
3505
+ pfadd = (...args) => new PfAddCommand(args, this.opts).exec(this.client);
3506
+ /**
3507
+ * @see https://redis.io/commands/pfcount
3508
+ */
3509
+ pfcount = (...args) => new PfCountCommand(args, this.opts).exec(this.client);
3510
+ /**
3511
+ * @see https://redis.io/commands/pfmerge
3512
+ */
3513
+ pfmerge = (...args) => new PfMergeCommand(args, this.opts).exec(this.client);
3514
+ /**
3515
+ * @see https://redis.io/commands/ping
3516
+ */
3517
+ ping = (args) => new PingCommand(args, this.opts).exec(this.client);
3518
+ /**
3519
+ * @see https://redis.io/commands/psetex
3520
+ */
3521
+ psetex = (key, ttl, value) => new PSetEXCommand([key, ttl, value], this.opts).exec(this.client);
3522
+ /**
3523
+ * @see https://redis.io/commands/pttl
3524
+ */
3525
+ pttl = (...args) => new PTtlCommand(args, this.opts).exec(this.client);
3526
+ /**
3527
+ * @see https://redis.io/commands/publish
3528
+ */
3529
+ publish = (...args) => new PublishCommand(args, this.opts).exec(this.client);
3530
+ /**
3531
+ * @see https://redis.io/commands/randomkey
3532
+ */
3533
+ randomkey = () => new RandomKeyCommand().exec(this.client);
3534
+ /**
3535
+ * @see https://redis.io/commands/rename
3536
+ */
3537
+ rename = (...args) => new RenameCommand(args, this.opts).exec(this.client);
3538
+ /**
3539
+ * @see https://redis.io/commands/renamenx
3540
+ */
3541
+ renamenx = (...args) => new RenameNXCommand(args, this.opts).exec(this.client);
3542
+ /**
3543
+ * @see https://redis.io/commands/rpop
3544
+ */
3545
+ rpop = (...args) => new RPopCommand(args, this.opts).exec(this.client);
3546
+ /**
3547
+ * @see https://redis.io/commands/rpush
3548
+ */
3549
+ rpush = (key, ...elements) => new RPushCommand([key, ...elements], this.opts).exec(this.client);
3550
+ /**
3551
+ * @see https://redis.io/commands/rpushx
3552
+ */
3553
+ rpushx = (key, ...elements) => new RPushXCommand([key, ...elements], this.opts).exec(this.client);
3554
+ /**
3555
+ * @see https://redis.io/commands/sadd
3556
+ */
3557
+ sadd = (key, member, ...members) => new SAddCommand([key, member, ...members], this.opts).exec(this.client);
3558
+ /**
3559
+ * @see https://redis.io/commands/scan
3560
+ */
3561
+ scan = (...args) => new ScanCommand(args, this.opts).exec(this.client);
3562
+ /**
3563
+ * @see https://redis.io/commands/scard
3564
+ */
3565
+ scard = (...args) => new SCardCommand(args, this.opts).exec(this.client);
3566
+ /**
3567
+ * @see https://redis.io/commands/script-exists
3568
+ */
3569
+ scriptExists = (...args) => new ScriptExistsCommand(args, this.opts).exec(this.client);
3570
+ /**
3571
+ * @see https://redis.io/commands/script-flush
3572
+ */
3573
+ scriptFlush = (...args) => new ScriptFlushCommand(args, this.opts).exec(this.client);
3574
+ /**
3575
+ * @see https://redis.io/commands/script-load
3576
+ */
3577
+ scriptLoad = (...args) => new ScriptLoadCommand(args, this.opts).exec(this.client);
3578
+ /**
3579
+ * @see https://redis.io/commands/sdiff
3580
+ */
3581
+ sdiff = (...args) => new SDiffCommand(args, this.opts).exec(this.client);
3582
+ /**
3583
+ * @see https://redis.io/commands/sdiffstore
3584
+ */
3585
+ sdiffstore = (...args) => new SDiffStoreCommand(args, this.opts).exec(this.client);
3586
+ /**
3587
+ * @see https://redis.io/commands/set
3588
+ */
3589
+ set = (key, value, opts) => new SetCommand([key, value, opts], this.opts).exec(this.client);
3590
+ /**
3591
+ * @see https://redis.io/commands/setbit
3592
+ */
3593
+ setbit = (...args) => new SetBitCommand(args, this.opts).exec(this.client);
3594
+ /**
3595
+ * @see https://redis.io/commands/setex
3596
+ */
3597
+ setex = (key, ttl, value) => new SetExCommand([key, ttl, value], this.opts).exec(this.client);
3598
+ /**
3599
+ * @see https://redis.io/commands/setnx
3600
+ */
3601
+ setnx = (key, value) => new SetNxCommand([key, value], this.opts).exec(this.client);
3602
+ /**
3603
+ * @see https://redis.io/commands/setrange
3604
+ */
3605
+ setrange = (...args) => new SetRangeCommand(args, this.opts).exec(this.client);
3606
+ /**
3607
+ * @see https://redis.io/commands/sinter
3608
+ */
3609
+ sinter = (...args) => new SInterCommand(args, this.opts).exec(this.client);
3610
+ /**
3611
+ * @see https://redis.io/commands/sinterstore
3612
+ */
3613
+ sinterstore = (...args) => new SInterStoreCommand(args, this.opts).exec(this.client);
3614
+ /**
3615
+ * @see https://redis.io/commands/sismember
3616
+ */
3617
+ sismember = (key, member) => new SIsMemberCommand([key, member], this.opts).exec(this.client);
3618
+ /**
3619
+ * @see https://redis.io/commands/smismember
3620
+ */
3621
+ smismember = (key, members) => new SMIsMemberCommand([key, members], this.opts).exec(this.client);
3622
+ /**
3623
+ * @see https://redis.io/commands/smembers
3624
+ */
3625
+ smembers = (...args) => new SMembersCommand(args, this.opts).exec(this.client);
3626
+ /**
3627
+ * @see https://redis.io/commands/smove
3628
+ */
3629
+ smove = (source, destination, member) => new SMoveCommand([source, destination, member], this.opts).exec(this.client);
3630
+ /**
3631
+ * @see https://redis.io/commands/spop
3632
+ */
3633
+ spop = (...args) => new SPopCommand(args, this.opts).exec(this.client);
3634
+ /**
3635
+ * @see https://redis.io/commands/srandmember
3636
+ */
3637
+ srandmember = (...args) => new SRandMemberCommand(args, this.opts).exec(this.client);
3638
+ /**
3639
+ * @see https://redis.io/commands/srem
3640
+ */
3641
+ srem = (key, ...members) => new SRemCommand([key, ...members], this.opts).exec(this.client);
3642
+ /**
3643
+ * @see https://redis.io/commands/sscan
3644
+ */
3645
+ sscan = (...args) => new SScanCommand(args, this.opts).exec(this.client);
3646
+ /**
3647
+ * @see https://redis.io/commands/strlen
3648
+ */
3649
+ strlen = (...args) => new StrLenCommand(args, this.opts).exec(this.client);
3650
+ /**
3651
+ * @see https://redis.io/commands/sunion
3652
+ */
3653
+ sunion = (...args) => new SUnionCommand(args, this.opts).exec(this.client);
3654
+ /**
3655
+ * @see https://redis.io/commands/sunionstore
3656
+ */
3657
+ sunionstore = (...args) => new SUnionStoreCommand(args, this.opts).exec(this.client);
3658
+ /**
3659
+ * @see https://redis.io/commands/time
3660
+ */
3661
+ time = () => new TimeCommand().exec(this.client);
3662
+ /**
3663
+ * @see https://redis.io/commands/touch
3664
+ */
3665
+ touch = (...args) => new TouchCommand(args, this.opts).exec(this.client);
3666
+ /**
3667
+ * @see https://redis.io/commands/ttl
3668
+ */
3669
+ ttl = (...args) => new TtlCommand(args, this.opts).exec(this.client);
3670
+ /**
3671
+ * @see https://redis.io/commands/type
3672
+ */
3673
+ type = (...args) => new TypeCommand(args, this.opts).exec(this.client);
3674
+ /**
3675
+ * @see https://redis.io/commands/unlink
3676
+ */
3677
+ unlink = (...args) => new UnlinkCommand(args, this.opts).exec(this.client);
3678
+ /**
3679
+ * @see https://redis.io/commands/xadd
3680
+ */
3681
+ xadd = (...args) => new XAddCommand(args, this.opts).exec(this.client);
3682
+ /**
3683
+ * @see https://redis.io/commands/xack
3684
+ */
3685
+ xack = (...args) => new XAckCommand(args, this.opts).exec(this.client);
3686
+ /**
3687
+ * @see https://redis.io/commands/xdel
3688
+ */
3689
+ xdel = (...args) => new XDelCommand(args, this.opts).exec(this.client);
3690
+ /**
3691
+ * @see https://redis.io/commands/xgroup
3692
+ */
3693
+ xgroup = (...args) => new XGroupCommand(args, this.opts).exec(this.client);
3694
+ /**
3695
+ * @see https://redis.io/commands/xread
3696
+ */
3697
+ xread = (...args) => new XReadCommand(args, this.opts).exec(this.client);
3698
+ /**
3699
+ * @see https://redis.io/commands/xreadgroup
3700
+ */
3701
+ xreadgroup = (...args) => new XReadGroupCommand(args, this.opts).exec(this.client);
3702
+ /**
3703
+ * @see https://redis.io/commands/xinfo
3704
+ */
3705
+ xinfo = (...args) => new XInfoCommand(args, this.opts).exec(this.client);
3706
+ /**
3707
+ * @see https://redis.io/commands/xlen
3708
+ */
3709
+ xlen = (...args) => new XLenCommand(args, this.opts).exec(this.client);
3710
+ /**
3711
+ * @see https://redis.io/commands/xpending
3712
+ */
3713
+ xpending = (...args) => new XPendingCommand(args, this.opts).exec(this.client);
3714
+ /**
3715
+ * @see https://redis.io/commands/xclaim
3716
+ */
3717
+ xclaim = (...args) => new XClaimCommand(args, this.opts).exec(this.client);
3718
+ /**
3719
+ * @see https://redis.io/commands/xautoclaim
3720
+ */
3721
+ xautoclaim = (...args) => new XAutoClaim(args, this.opts).exec(this.client);
3722
+ /**
3723
+ * @see https://redis.io/commands/xtrim
3724
+ */
3725
+ xtrim = (...args) => new XTrimCommand(args, this.opts).exec(this.client);
3726
+ /**
3727
+ * @see https://redis.io/commands/xrange
3728
+ */
3729
+ xrange = (...args) => new XRangeCommand(args, this.opts).exec(this.client);
3730
+ /**
3731
+ * @see https://redis.io/commands/xrevrange
3732
+ */
3733
+ xrevrange = (...args) => new XRevRangeCommand(args, this.opts).exec(this.client);
3734
+ /**
3735
+ * @see https://redis.io/commands/zadd
3736
+ */
3737
+ zadd = (...args) => {
3738
+ if ("score" in args[1]) {
3739
+ return new ZAddCommand([args[0], args[1], ...args.slice(2)], this.opts).exec(
3740
+ this.client
3741
+ );
3742
+ }
3743
+ return new ZAddCommand(
3744
+ [args[0], args[1], ...args.slice(2)],
3745
+ this.opts
3746
+ ).exec(this.client);
3747
+ };
3748
+ /**
3749
+ * @see https://redis.io/commands/zcard
3750
+ */
3751
+ zcard = (...args) => new ZCardCommand(args, this.opts).exec(this.client);
3752
+ /**
3753
+ * @see https://redis.io/commands/zcount
3754
+ */
3755
+ zcount = (...args) => new ZCountCommand(args, this.opts).exec(this.client);
3756
+ /**
3757
+ * @see https://redis.io/commands/zdiffstore
3758
+ */
3759
+ zdiffstore = (...args) => new ZDiffStoreCommand(args, this.opts).exec(this.client);
3760
+ /**
3761
+ * @see https://redis.io/commands/zincrby
3762
+ */
3763
+ zincrby = (key, increment, member) => new ZIncrByCommand([key, increment, member], this.opts).exec(this.client);
3764
+ /**
3765
+ * @see https://redis.io/commands/zinterstore
3766
+ */
3767
+ zinterstore = (...args) => new ZInterStoreCommand(args, this.opts).exec(this.client);
3768
+ /**
3769
+ * @see https://redis.io/commands/zlexcount
3770
+ */
3771
+ zlexcount = (...args) => new ZLexCountCommand(args, this.opts).exec(this.client);
3772
+ /**
3773
+ * @see https://redis.io/commands/zmscore
3774
+ */
3775
+ zmscore = (...args) => new ZMScoreCommand(args, this.opts).exec(this.client);
3776
+ /**
3777
+ * @see https://redis.io/commands/zpopmax
3778
+ */
3779
+ zpopmax = (...args) => new ZPopMaxCommand(args, this.opts).exec(this.client);
3780
+ /**
3781
+ * @see https://redis.io/commands/zpopmin
3782
+ */
3783
+ zpopmin = (...args) => new ZPopMinCommand(args, this.opts).exec(this.client);
3784
+ /**
3785
+ * @see https://redis.io/commands/zrange
3786
+ */
3787
+ zrange = (...args) => new ZRangeCommand(args, this.opts).exec(this.client);
3788
+ /**
3789
+ * @see https://redis.io/commands/zrank
3790
+ */
3791
+ zrank = (key, member) => new ZRankCommand([key, member], this.opts).exec(this.client);
3792
+ /**
3793
+ * @see https://redis.io/commands/zrem
3794
+ */
3795
+ zrem = (key, ...members) => new ZRemCommand([key, ...members], this.opts).exec(this.client);
3796
+ /**
3797
+ * @see https://redis.io/commands/zremrangebylex
3798
+ */
3799
+ zremrangebylex = (...args) => new ZRemRangeByLexCommand(args, this.opts).exec(this.client);
3800
+ /**
3801
+ * @see https://redis.io/commands/zremrangebyrank
3802
+ */
3803
+ zremrangebyrank = (...args) => new ZRemRangeByRankCommand(args, this.opts).exec(this.client);
3804
+ /**
3805
+ * @see https://redis.io/commands/zremrangebyscore
3806
+ */
3807
+ zremrangebyscore = (...args) => new ZRemRangeByScoreCommand(args, this.opts).exec(this.client);
3808
+ /**
3809
+ * @see https://redis.io/commands/zrevrank
3810
+ */
3811
+ zrevrank = (key, member) => new ZRevRankCommand([key, member], this.opts).exec(this.client);
3812
+ /**
3813
+ * @see https://redis.io/commands/zscan
3814
+ */
3815
+ zscan = (...args) => new ZScanCommand(args, this.opts).exec(this.client);
3816
+ /**
3817
+ * @see https://redis.io/commands/zscore
3818
+ */
3819
+ zscore = (key, member) => new ZScoreCommand([key, member], this.opts).exec(this.client);
3820
+ /**
3821
+ * @see https://redis.io/commands/zunion
3822
+ */
3823
+ zunion = (...args) => new ZUnionCommand(args, this.opts).exec(this.client);
3824
+ /**
3825
+ * @see https://redis.io/commands/zunionstore
3826
+ */
3827
+ zunionstore = (...args) => new ZUnionStoreCommand(args, this.opts).exec(this.client);
3828
+ };
3829
+
3830
+ // version.ts
3831
+ var VERSION = "v1.30.2";
3832
+
3833
+ // platforms/nodejs.ts
3834
+ if (typeof atob === "undefined") {
3835
+ global.atob = (b64) => Buffer.from(b64, "base64").toString("utf8");
3836
+ }
3837
+ var Redis2 = class _Redis extends Redis {
3838
+ /**
3839
+ * Create a new redis client by providing a custom `Requester` implementation
3840
+ *
3841
+ * @example
3842
+ * ```ts
3843
+ *
3844
+ * import { UpstashRequest, Requester, UpstashResponse, Redis } from "@upstash/redis"
3845
+ *
3846
+ * const requester: Requester = {
3847
+ * request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
3848
+ * // ...
3849
+ * }
3850
+ * }
3851
+ *
3852
+ * const redis = new Redis(requester)
3853
+ * ```
3854
+ */
3855
+ constructor(configOrRequester) {
3856
+ if ("request" in configOrRequester) {
3857
+ super(configOrRequester);
3858
+ return;
3859
+ }
3860
+ if (!configOrRequester.url) {
3861
+ console.warn(
3862
+ `[Upstash Redis] The 'url' property is missing or undefined in your Redis config.`
3863
+ );
3864
+ } else if (configOrRequester.url.startsWith(" ") || configOrRequester.url.endsWith(" ") || /\r|\n/.test(configOrRequester.url)) {
3865
+ console.warn(
3866
+ "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!"
3867
+ );
3868
+ }
3869
+ if (!configOrRequester.token) {
3870
+ console.warn(
3871
+ `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.`
3872
+ );
3873
+ } else if (configOrRequester.token.startsWith(" ") || configOrRequester.token.endsWith(" ") || /\r|\n/.test(configOrRequester.token)) {
3874
+ console.warn(
3875
+ "[Upstash Redis] The redis token contains whitespace or newline, which can cause errors!"
3876
+ );
3877
+ }
3878
+ const client = new HttpClient({
3879
+ baseUrl: configOrRequester.url,
3880
+ retry: configOrRequester.retry,
3881
+ headers: { authorization: `Bearer ${configOrRequester.token}` },
3882
+ agent: configOrRequester.agent,
3883
+ responseEncoding: configOrRequester.responseEncoding,
3884
+ cache: configOrRequester.cache ?? "no-store",
3885
+ signal: configOrRequester.signal,
3886
+ keepAlive: configOrRequester.keepAlive,
3887
+ readYourWrites: configOrRequester.readYourWrites
3888
+ });
3889
+ super(client, {
3890
+ automaticDeserialization: configOrRequester.automaticDeserialization,
3891
+ enableTelemetry: !process.env.UPSTASH_DISABLE_TELEMETRY,
3892
+ latencyLogging: configOrRequester.latencyLogging,
3893
+ enableAutoPipelining: configOrRequester.enableAutoPipelining
3894
+ });
3895
+ this.addTelemetry({
3896
+ runtime: (
3897
+ // @ts-expect-error to silence compiler
3898
+ typeof EdgeRuntime === "string" ? "edge-light" : `node@${process.version}`
3899
+ ),
3900
+ platform: process.env.VERCEL ? "vercel" : process.env.AWS_REGION ? "aws" : "unknown",
3901
+ sdk: `@upstash/redis@${VERSION}`
3902
+ });
3903
+ if (this.enableAutoPipelining) {
3904
+ return this.autoPipeline();
3905
+ }
3906
+ }
3907
+ /**
3908
+ * Create a new Upstash Redis instance from environment variables.
3909
+ *
3910
+ * Use this to automatically load connection secrets from your environment
3911
+ * variables. For instance when using the Vercel integration.
3912
+ *
3913
+ * This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
3914
+ * your environment using `process.env`.
3915
+ */
3916
+ static fromEnv(config) {
3917
+ if (process.env === void 0) {
3918
+ throw new TypeError(
3919
+ '[Upstash Redis] Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please import from "@upstash/redis/cloudflare" instead'
3920
+ );
3921
+ }
3922
+ const url = process.env.UPSTASH_REDIS_REST_URL || process.env.KV_REST_API_URL;
3923
+ if (!url) {
3924
+ console.warn("[Upstash Redis] Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
3925
+ }
3926
+ const token = process.env.UPSTASH_REDIS_REST_TOKEN || process.env.KV_REST_API_TOKEN;
3927
+ if (!token) {
3928
+ console.warn(
3929
+ "[Upstash Redis] Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`"
3930
+ );
3931
+ }
3932
+ return new _Redis({ ...config, url, token });
3933
+ }
3934
+ };
3935
+ // Annotate the CommonJS export names for ESM import in node:
3936
+ 0 && (module.exports = {
3937
+ Redis,
3938
+ errors
3939
+ });