Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ async function call(query, body) {
const results = [];
for (let i = 0; i < lines.length; i++) {
try {
results.push(await redis.call(...lines[i]));
results.push({error: false, result: await redis.call(...lines[i])});
} catch (e) {
results.push(`${e.message}`);
results.push({error: true, message: `${e.message}`});
}
}
return results;
Expand Down
20 changes: 12 additions & 8 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,20 @@ export class AppComponent implements OnInit {
*/
onNewValue(newValue) {
this.redisService.call(newValue.id, [newValue.rawLine]).subscribe(ret => {
if (newValue.from === 'root') {
this.onRefresh();
}
if (newValue.onSuccess) {
newValue.onSuccess(newValue);
if (!ret[0].error) {
if (newValue.from === 'root') {
this.onRefresh();
}
if (newValue.onSuccess) {
newValue.onSuccess(newValue);
}
this.util.showMessage(newValue.edit ? 'Updated successfully.' : 'Added successfully.');
} else {
this.util.showMessage('Failed to add the value: ' + ret[0].message);
}
this.util.showMessage(newValue.edit ? 'Updated successfully.' : 'Added successfully.');
}, e => {
console.error(e.error.message);
this.util.showMessage('Fail to add the value: ' + this.util.getErrorMessage(e));
this.util.showMessage('Failed to add the value: ' + this.util.getErrorMessage(e));
this._store.dispatch(new RedisConnectFailed({id: this.pageData.id}))
});
}

Expand Down
16 changes: 2 additions & 14 deletions src/app/components/add-value-dialog/add-value-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,6 @@ export class AddValueDialogComponent implements OnInit {
}
}

/**
* remove exist key
* @param ret the ret include id and key
* @param cb the callback
*/
removeExistKey(ret, cb) {
this.redisService.call(ret.id, [['DEL', ret.key]]).subscribe(() => {
cb();
}, err => {
this.util.showMessage('Delete is failed: ' + this.util.getErrorMessage(err));
});
}

/**
* check is exist
Expand All @@ -193,15 +181,15 @@ export class AddValueDialogComponent implements OnInit {
*/
checkIsExist(ret, cb) {
this.redisService.call(ret.id, [['EXISTS', ret.key]]).subscribe((r) => {
if (r && r.length > 0 && r[0] > 0) { // exist
if (!r[0].error && r[0].result > 0) { // exist
this.dialogService.open(ConfirmDialogComponent, {
width: '360px', data: {
title: `Key "${ret.key}" Already Exists`,
message: `Are you sure you want to replace the original key?`
}
}).afterClosed().subscribe(cr => {
if (cr) {
this.removeExistKey(ret, cb);
cb();
}
});
} else {
Expand Down
31 changes: 18 additions & 13 deletions src/app/components/data-viewer/data-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import _ from 'lodash';
import {UtilService} from '../../services/util.service';
import {Observable} from 'rxjs';
import {Store} from '@ngrx/store';
import {ReqFetchTree} from '../../ngrx/actions/redis-actions';
import {ReqFetchTree, RedisConnectFailed} from '../../ngrx/actions/redis-actions';

/**
* the backend type to frontend type map
Expand Down Expand Up @@ -124,7 +124,10 @@ export class DataViewerComponent implements OnInit, OnChanges {
this.fetchData();
this.util.showMessage('Deleted successfully.');
if (cb) { cb(); }
}, () => this.util.showMessage('Delete is failed.'));
}, () => {
this.util.showMessage('Deleted Failed.');
this._store.dispatch(new RedisConnectFailed({id: this.pageData.id}))
}
}
});
}
Expand Down Expand Up @@ -180,7 +183,7 @@ export class DataViewerComponent implements OnInit, OnChanges {
this.loadingPageData = true;
this.redisService.call(instanceId, [['LRANGE', key, start, end], ['LLEN', key]]).subscribe(ret => {
this.page.totalSize = ret[1];
this.data = injectValuesToArray(ret[0]);
this.data = injectValuesToArray(ret[0].result);
this.showPagination = true;
this.loadingPageData = false;
}
Expand All @@ -189,12 +192,13 @@ export class DataViewerComponent implements OnInit, OnChanges {
this.loadingPageData = true;
this.redisService.call(instanceId, [['ZRANGE', key, start, end, 'withscores'], ['ZCARD', key]]).subscribe(ret => {
this.page.totalSize = ret[1];
const { result } = ret[0];
this.data = [];
for (let i = 0; i < ret[0].length;) {
for (let i = 0; i < result.length;) {
this.data.push({
index: this.page.pageIndex * this.page.pageSize + (i / 2),
score: parseFloat(ret[0][i + 1]),
value: ret[0][i],
score: parseFloat(result[i + 1]),
value: result[i],
});
i += 2;
}
Expand All @@ -206,7 +210,7 @@ export class DataViewerComponent implements OnInit, OnChanges {
if (!this.setCachedData) {
this.loadingPageData = true;
this.redisService.call(instanceId, [['SMEMBERS', key]]).subscribe(ret => {
this.setCachedData = injectValuesToArray(ret[0]);
this.setCachedData = injectValuesToArray(ret[0].result);
this.page.totalSize = this.setCachedData.length;
this.data = this.setCachedData.slice(start, end + 1);
this.loadingPageData = false;
Expand All @@ -222,10 +226,11 @@ export class DataViewerComponent implements OnInit, OnChanges {
this.loadingPageData = true;
this.redisService.call(instanceId, [['HGETALL', key]]).subscribe(ret => {
this.hashCachedData = [];
for (let i = 0; i < ret[0].length;) {
const { result } = ret[0];
for (let i = 0; i < result.length;) {
this.hashCachedData.push({
key: ret[0][i],
value: ret[0][i + 1],
key: result[i],
value: result[i + 1],
});
i += 2;
}
Expand All @@ -244,7 +249,7 @@ export class DataViewerComponent implements OnInit, OnChanges {
this.loadingPageData = true;
this.redisService.call(instanceId, [['GET', key]]).subscribe(ret => {
this.loadingPageData = false;
this.stringValue = ret[0];
this.stringValue = ret[0].result;
});
}
}
Expand Down Expand Up @@ -358,8 +363,8 @@ export class DataViewerComponent implements OnInit, OnChanges {
this.onDeleteValue.emit();
this._store.dispatch(new ReqFetchTree({id: this.pageData.id}));
}, e => {
this.util.showMessage('Delete is failed.');
console.error(e);
this.util.showMessage('Delete Failed.');
this._store.dispatch(new RedisConnectFailed({id: this.pageData.id}))
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ export class ImportDataDialogComponent implements OnInit {
});

const totalRow = this.flushDB ? commands.length - 1 : commands.length;
this.redisService.call(this.instanceId, commands).subscribe((rsp) => {
this.redisService.call(this.instanceId, commands).subscribe((results) => {
let numberOfSucceed = 0;
_.each(rsp, v => {
numberOfSucceed += (!!v && v.toString().toLowerCase().indexOf('err') < 0) ? 1 : 0;
_.each(results, v => {
numberOfSucceed += v.error ? 0 : 1;
});
numberOfSucceed -= this.flushDB ? 1 : 0;
const numberOfFailed = totalRow - numberOfSucceed;
Expand Down
10 changes: 7 additions & 3 deletions src/app/ngrx/effects/cli-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export class CliEffect {
action['payload'].redisId,
[action['payload'].command]).pipe(
map(ret => {
const { error } = ret[0];
const result = error ? ret[0].message : ret[0].result;

if (action['payload'].cb) {
action['payload'].cb(false);
action['payload'].cb(error);
}

return new CommandRunFinished({
result: ret[0],
result,
id: action['payload'].id,
error: !(ret[0] && ret[0].toString() && ret[0].toString().toLowerCase().indexOf('err') < 0),
error,
});
}),
catchError((e) => {
Expand Down
42 changes: 23 additions & 19 deletions src/app/ngrx/effects/page-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,30 @@ export class PageEffect {
action['payload'].id,
[['info']]).pipe(
map(ret => {
const rawInfo = ret[0];
const result = [];
rawInfo.split('\n').forEach(line => {
if (line.indexOf('#') === 0) {
return;
}
if (line.trim() === '') {
return;
}
const parts = line.split(':');
result.push({
key: parts[0].split('_').join(' '),
value: parts[1],
if (!ret[0].error) {
const rawInfo = ret[0].result;
const result = [];
rawInfo.split('\n').forEach(line => {
if (line.indexOf('#') === 0) {
return;
}
if (line.trim() === '') {
return;
}
const parts = line.split(':');
result.push({
key: parts[0].split('_').join(' '),
value: parts[1],
});
});
});
return new LoadedPage({
item: result,
requestId: action['payload'].requestId,
id: action['payload'].id
});
return new LoadedPage({
item: result,
requestId: action['payload'].requestId,
id: action['payload'].id
});
} else {
this.util.showMessage('Failed to load instance.');
}
}),
catchError(() => {
const id = action['payload'].id;
Expand Down