UNPKG

p3x-redis-ui-server

Version:

🏍️ P3X Redis UI server — Socket.IO backend for the dual Angular + React frontend with AI queries, 54 languages, and auto data decompression

2 lines (1 loc) 2.17 kB
import e from"ioredis";import{EventEmitter as t}from"events";import s from"./redis-info.mjs";import a from"./set-default-options-from-server.mjs";export default class r extends e.Cluster{constructor(e,t={}){e=Array.isArray(e)?e:[e],(t=a(t,e)).clusterRetryStrategy=null,super(e,t)}async _getClusterInfoKeyspace(e){const t=await Promise.all(this.nodes("master").map(e=>e.info("keyspace")));let a=0,r=0,n=0;for(const e of t){if(!e)continue;const t=s.parse(e).databases[0];if(!t)continue;const{keys:i=0,expires:o=0,avg_ttl:l=0}=t;a+=i,r+=o,n+=l}return n=n?Math.round(n/r):0,{keys:a,expires:r,avg_ttl:n}}async originalDbsize(...e){return super.dbsize(...e)}async dbsize(){return(await Promise.all(this.nodes("master").map(e=>e.dbsize()))).reduce((e,t)=>e+t,0)}async flushdb(...e){return await Promise.all(this.nodes("master").map(t=>t.flushdb(...e))),"OK"}async flushall(...e){return await Promise.all(this.nodes("master").map(t=>t.flushall(...e))),"OK"}async aclSetuser(...e){return await Promise.all(this.nodes("master").map(t=>t.call("ACL","SETUSER",...e))),"OK"}async aclDeluser(...e){return await Promise.all(this.nodes("master").map(t=>t.call("ACL","DELUSER",...e))),"OK"}originalRename(...e){return super.rename(...e)}async rename(e,t,s){let a=null,r=null;try{let[s,r]=await Promise.all([this.dumpBuffer(e),this.ttl(e)]);r=parseInt(r),r<0&&(r=0),await this.del(t),await this.restore(t,r,s),await this.del(e),a="OK"}catch(e){r=e}if("function"==typeof s)s(r,a);else if(r)throw r;return a}originalPipeline(...e){return super.pipeline(...e)}pipeline(...e){const t=new Proxy([],{get:(e,s)=>(...a)=>"exec"===s?async function(e){const t=[];for(let s of e){const e=await s();t.push(e)}return t}(e):(e.push(async()=>{let e=null,t=null;try{t=await this[s](...a)}catch(t){e=t}return[e,t]}),t)});return t}scanStream(...e){const s=new t;return this._streamNodes({stream:s,method:"scanStream",params:e}),s}async _streamNodes(e={}){let{nodes:s=this.nodes("master"),stream:a=new t,method:r,params:n=[]}=e;try{const e=[];for(let t of s)e.push(new Promise((e,s)=>{const i=t[r](...n);i.on("data",e=>{a.emit("data",e)}),i.on("end",()=>{e()})}));await Promise.all(e)}finally{a.emit("end")}}}