diff --git a/src/components/ConnectionMenu.vue b/src/components/ConnectionMenu.vue index 5ec5478..6a05959 100644 --- a/src/components/ConnectionMenu.vue +++ b/src/components/ConnectionMenu.vue @@ -60,7 +60,10 @@  {{ $t('message.slow_log') }} -  {{ $t('message.import') }}Key +  {{ $t('message.import') }} Key + + +  {{ $t('message.import') }} CMD  {{ $t('message.flushdb') }} @@ -87,6 +90,7 @@ import storage from '@/storage.js'; import { remote } from 'electron'; import NewConnectionDialog from '@/components/NewConnectionDialog'; +import splitargs from '@qii404/redis-splitargs'; export default { data() { @@ -276,11 +280,9 @@ export default { this.client.callBuffer('RESTORE', key, ttl, content, 'REPLACE').then((reply) => { // reply == 'OK' succ.push(key); - this.$set(this.$refs.importKeysNotify, - 'innerHTML', - `Succ: ${succ.length}, Fail: ${fail.length}`); }).catch((e) => { fail.push(key); + }).finally(() => { this.$set(this.$refs.importKeysNotify, 'innerHTML', `Succ: ${succ.length}, Fail: ${fail.length}`); @@ -302,6 +304,66 @@ export default { }); }); }, + execFileCMDS() { + remote.dialog.showOpenDialog(remote.getCurrentWindow(), { + properties: ['openFile'], + }).then((reply) => { + if (reply.canceled) { + return; + } + + const succ = []; + const fail = []; + let count = 0; + + const rl = require('readline').createInterface({ + input: require('fs').createReadStream(reply.filePaths[0]), + }); + + rl.on('line', (line) => { + const paramsArr = splitargs(line, true); + + if (!paramsArr || !paramsArr.length) { + return; + } + + count++; + + // show notify in first time + if (count === 1) { + this.$notify.success({ + message: this.$createElement('p', { ref: 'importCMDNotify' }, ''), + duration: 0, + }); + } + + this.client.callBuffer(...paramsArr).then((reply) => { + succ.push(line); + }).catch((e) => { + fail.push(line); + }).finally(() => { + this.$set(this.$refs.importCMDNotify, + 'innerHTML', + `Succ: ${succ.length}, Fail: ${fail.length}` + ); + }); + }); + + rl.on('close', () => { + if (count === 0) { + return this.$message.error('File parse failed.'); + } + + (count > 10000) && this.$message.success({ + message: this.$t('message.import_success'), + duration: 800, + }); + + // refresh key list + this.$bus.$emit('refreshKeyList', this.client); + }); + }); + }, flushDB() { if (!this.client) { return;