@upstash/redis 0.0.0-ci.f5cad9e7bda3d77569d9df207b4e1565f75d6154 → 0.0.0-ci.f725f60c40a2b7f0e25dd9bf83a931c24624cdf6-20260123181037

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