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) 704 B
export default async e=>{const{socket:t,payload:s}=e;try{const o=t.p3xrs.ioredis,n=s.maxKeys||100,r=s.topN||20,a=await new Promise((e,t)=>{const s=[],r=o.scanStream({count:200});r.on("data",e=>{s.length<n&&s.push(...e)}),r.on("end",()=>e(s.slice(0,n))),r.on("error",t)}),c=500,l=[];for(let e=0;e<a.length;e+=c){const t=a.slice(e,e+c),s=o.pipeline();for(const e of t)s.call("MEMORY","USAGE",e);const n=await s.exec();for(let e=0;e<t.length;e++){const s=n[e][0],o=n[e][1];s||"number"!=typeof o||l.push({key:t[e],bytes:o})}}l.sort((e,t)=>t.bytes-e.bytes);const i=l.slice(0,r);t.emit(e.responseEvent,{status:"ok",data:i})}catch(s){console.error(s),t.emit(e.responseEvent,{status:"error",error:s.message})}};