@@ -7,6 +7,7 @@ const isDev = process.env.NODE_ENV !== 'production';
7
7
let mainWindow ;
8
8
let redis = null ;
9
9
const connectionsFile = path . join ( app . getPath ( 'userData' ) , 'connections.json' ) ;
10
+ const KEYS_PER_PAGE = 50 ;
10
11
11
12
function createWindow ( ) {
12
13
mainWindow = new BrowserWindow ( {
@@ -113,6 +114,23 @@ ipcMain.handle('connect-redis', async (event, connection) => {
113
114
} ) ;
114
115
115
116
// Redis CRUD operations
117
+ ipcMain . handle ( 'redis-scan' , async ( event , { cursor = '0' , pattern = '*' , count = KEYS_PER_PAGE } ) => {
118
+ try {
119
+ if ( ! redis ) throw new Error ( 'Not connected to Redis' ) ;
120
+ const [ newCursor , keys ] = await redis . scan ( cursor , 'MATCH' , pattern , 'COUNT' , count ) ;
121
+ return {
122
+ success : true ,
123
+ data : {
124
+ cursor : newCursor ,
125
+ keys,
126
+ hasMore : newCursor !== '0'
127
+ }
128
+ } ;
129
+ } catch ( error ) {
130
+ return { success : false , error : error . message } ;
131
+ }
132
+ } ) ;
133
+
116
134
ipcMain . handle ( 'redis-get' , async ( event , key ) => {
117
135
try {
118
136
if ( ! redis ) throw new Error ( 'Not connected to Redis' ) ;
@@ -143,10 +161,29 @@ ipcMain.handle('redis-delete', async (event, key) => {
143
161
}
144
162
} ) ;
145
163
146
- ipcMain . handle ( 'redis-keys ' , async ( ) => {
164
+ ipcMain . handle ( 'redis-search ' , async ( event , pattern ) => {
147
165
try {
148
166
if ( ! redis ) throw new Error ( 'Not connected to Redis' ) ;
149
- const keys = await redis . keys ( '*' ) ;
167
+ const keys = [ ] ;
168
+ let cursor = '0' ;
169
+
170
+ do {
171
+ const [ newCursor , scanKeys ] = await redis . scan (
172
+ cursor ,
173
+ 'MATCH' ,
174
+ pattern ,
175
+ 'COUNT' ,
176
+ KEYS_PER_PAGE
177
+ ) ;
178
+ cursor = newCursor ;
179
+ keys . push ( ...scanKeys ) ;
180
+
181
+ // Limit total results to prevent memory issues
182
+ if ( keys . length > 1000 ) {
183
+ break ;
184
+ }
185
+ } while ( cursor !== '0' ) ;
186
+
150
187
return { success : true , data : keys } ;
151
188
} catch ( error ) {
152
189
return { success : false , error : error . message } ;
0 commit comments