redis export keys

This commit is contained in:
Jan Prochazka 2022-03-27 12:57:44 +02:00
parent c0fdcf2fd1
commit 1f0ae98c88
5 changed files with 43 additions and 0 deletions

View File

@ -180,6 +180,11 @@ module.exports = {
return this.loadDataCore('loadKeys', { conid, database, root });
},
exportKeys_meta: true,
async exportKeys({ conid, database, options }) {
return this.loadDataCore('exportKeys', { conid, database, options });
},
loadKeyInfo_meta: true,
async loadKeyInfo({ conid, database, key }) {
return this.loadDataCore('loadKeyInfo', { conid, database, key });

View File

@ -201,6 +201,10 @@ async function handleLoadKeys({ msgid, root }) {
return handleDriverDataCore(msgid, driver => driver.loadKeys(systemConnection, root));
}
async function handleExportKeys({ msgid, options }) {
return handleDriverDataCore(msgid, driver => driver.exportKeys(systemConnection, options));
}
async function handleLoadKeyInfo({ msgid, key }) {
return handleDriverDataCore(msgid, driver => driver.loadKeyInfo(systemConnection, key));
}
@ -307,6 +311,7 @@ const messageHandlers = {
generateDeploySql: handleGenerateDeploySql,
loadFieldValues: handleLoadFieldValues,
sqlSelect: handleSqlSelect,
exportKeys: handleExportKeys,
// runCommand: handleRunCommand,
};

View File

@ -89,6 +89,7 @@ export interface EngineDriver {
}[]
>;
loadKeys(pool, root: string): Promise;
exportKeys(pool, options: {}): Promise;
loadKeyInfo(pool, key): Promise;
loadKeyTableRange(pool, key, cursor, count): Promise;
loadFieldValues(pool: any, name: NamedObjectInfo, field: string, search: string): Promise;

View File

@ -6,6 +6,7 @@
import FontIcon from '../icons/FontIcon.svelte';
import ConfirmModal from '../modals/ConfirmModal.svelte';
import { showModal } from '../modals/modalTools';
import newQuery from '../query/newQuery';
import { activeDbKeysStore } from '../stores';
import { apiCall } from '../utility/api';
import openNewTab from '../utility/openNewTab';
@ -77,6 +78,23 @@
},
},
],
{
label: 'Generate script',
onClick: async () => {
const data = await apiCall('database-connections/export-keys', {
conid,
database,
options: {
keyPrefix: item.root || item.key,
},
});
newQuery({
title: 'Export #',
initialData: data,
});
},
},
];
}
</script>

View File

@ -163,6 +163,20 @@ const driver = {
return res;
},
async exportKeys(pool, options) {
const dump = new RedisDump({ client: pool });
return new Promise((resolve, reject) => {
dump.export({
type: 'redis',
keyPrefix: options.keyPrefix,
callback: (err, data) => {
if (err) reject(err);
else resolve(data);
},
});
});
},
async getKeys(pool, keyQuery = '*') {
const res = [];
let cursor = 0;