@upstash/redis 0.0.0-ci.f79c0d6d7212dfe450359da7ed92d84d639af819-20231031072701 → 0.0.0-ci.fa1d496e56b9c6b274a4edb64a8fbcbcb5d5080b-20251205201758

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