@upstash/redis 0.0.0-ci.a4e344e7de745c98ae89c879eb39ab17466fd7ba → 0.0.0-ci.ab13a19fb29aed87c738632a215dbb1ec16a825e-20241004200556

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