Skip to content

Commit bcf0d2c

Browse files
committed
connection management working
1 parent 4049428 commit bcf0d2c

File tree

5 files changed

+13164
-176
lines changed

5 files changed

+13164
-176
lines changed

main.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const isDev = process.env.NODE_ENV !== 'production';
77
let mainWindow;
88
let redis = null;
99
const connectionsFile = path.join(app.getPath('userData'), 'connections.json');
10+
const KEYS_PER_PAGE = 50;
1011

1112
function createWindow() {
1213
mainWindow = new BrowserWindow({
@@ -113,6 +114,23 @@ ipcMain.handle('connect-redis', async (event, connection) => {
113114
});
114115

115116
// 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+
116134
ipcMain.handle('redis-get', async (event, key) => {
117135
try {
118136
if (!redis) throw new Error('Not connected to Redis');
@@ -143,10 +161,29 @@ ipcMain.handle('redis-delete', async (event, key) => {
143161
}
144162
});
145163

146-
ipcMain.handle('redis-keys', async () => {
164+
ipcMain.handle('redis-search', async (event, pattern) => {
147165
try {
148166
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+
150187
return { success: true, data: keys };
151188
} catch (error) {
152189
return { success: false, error: error.message };

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)