Skip to content

Commit 398d5d3

Browse files
committed
Feature(RDB): add support to RDB, Generate RDB by SAVE command is ready, refactor in the methods of the SharedStorage, add Thread workers for RDB lifeCycle
1 parent 7d03ce5 commit 398d5d3

File tree

23 files changed

+258
-44
lines changed

23 files changed

+258
-44
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
.idea/
2+
.idea/
3+
dumps/

app/commands/dataManipulation/COPY.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ const COPY = (data: IRESP[]): ICommand => {
1010
const destination = data[2].data.toString();
1111
const replaceFlag = data[3] ? /REPLACE/gim.test(data[3].data.toString()) : false;
1212

13-
const isDestinationExists = SharedStorage.find(destination);
14-
const value = SharedStorage.get(source);
13+
const isDestinationExists = SharedStorage.findKey(destination);
14+
const value = SharedStorage.getKey(source);
1515

1616
if ((isDestinationExists && !replaceFlag) || !value)
1717
return <ICommand>{
1818
type: 'integer',
1919
data: 0
2020
};
2121

22-
SharedStorage.set(destination, value);
22+
SharedStorage.setKey(destination, value);
2323

2424
return <ICommand>{
2525
type: 'integer',

app/commands/dataManipulation/DEL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const DEL = (data: IRESP[]): ICommand => {
1010
let deleted = 0;
1111

1212
keys.map(key => {
13-
if (SharedStorage.delete(key))
13+
if (SharedStorage.deleteKey(key))
1414
deleted++;
1515
});
1616

app/commands/dataManipulation/EXISTS.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const EXISTS = (data: IRESP[]): ICommand => {
1010
let exists = 0;
1111

1212
keys.map(key => {
13-
if (SharedStorage.find(key))
13+
if (SharedStorage.findKey(key))
1414
exists++;
1515
});
1616

app/commands/dataManipulation/GET.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const GET = (data: IRESP[]): ICommand => {
77
if (data.length !== 2)
88
return NUMBER_ARGS(data);
99

10-
const value = SharedStorage.get(data[1].data.toString());
10+
const value = SharedStorage.getKey(data[1].data.toString());
1111

1212
if (!value) return <ICommand>{
1313
type: 'bulk',

app/commands/dataManipulation/RENAME.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const RENAME = (data: IRESP[]): ICommand => {
99
const key = data[1].data.toString();
1010
const newKey = data[2].data.toString();
1111

12-
if (!SharedStorage.find(key)) {
12+
if (!SharedStorage.findKey(key)) {
1313
return <ICommand>{
1414
type: 'error',
1515
data: 'ERR'
1616
}
1717
}
1818

19-
SharedStorage.set(newKey, SharedStorage.get(key));
20-
SharedStorage.delete(key);
19+
SharedStorage.setKey(newKey, SharedStorage.getKey(key));
20+
SharedStorage.deleteKey(key);
2121

2222
return <ICommand>{
2323
type: 'string',

app/commands/dataManipulation/RENAMENX.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ const RENAMENX = (data: IRESP[]): ICommand => {
99
const key = data[1].data.toString();
1010
const newKey = data[2].data.toString();
1111

12-
if (!SharedStorage.find(key)) {
12+
if (!SharedStorage.findKey(key)) {
1313
return <ICommand>{
1414
type: 'error',
1515
data: 'ERR'
1616
}
1717
}
1818

19-
if (SharedStorage.find(newKey))
19+
if (SharedStorage.findKey(newKey))
2020
return <ICommand>{
2121
type: 'integer',
2222
data: 0
2323
}
2424

25-
SharedStorage.set(newKey, SharedStorage.get(key));
26-
SharedStorage.delete(key);
25+
SharedStorage.setKey(newKey, SharedStorage.getKey(key));
26+
SharedStorage.deleteKey(key);
2727

2828
return <ICommand>{
2929
type: 'integer',

app/commands/dataManipulation/SET.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const SET = (data: IRESP[]): ICommand => {
2525
data: 'ERR'
2626
};
2727

28-
SharedStorage.set(key, value, duration);
28+
SharedStorage.setKey(key, value, duration);
2929

3030
return <ICommand>{
3131
type: 'string',

app/commands/presistence/SAVE.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import ICommand from "../../interfaces/command.interface";
2+
import SharedStorage from "../../storage/SharedStorage";
3+
import {subject} from "../../workers/worker.observer";
4+
5+
const SAVE = (): ICommand => {
6+
subject.send('RDB.SAVE', SharedStorage.copyAll());
7+
8+
return <ICommand>{
9+
type: 'string',
10+
data: 'OK'
11+
}
12+
};
13+
14+
export default SAVE;

app/config/_setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './worker.config';
2+
export * from './args.config';

0 commit comments

Comments
 (0)