Added config flags max-memory and eviction-policy to manage memory usage. Created ParseMemory utility function to parse max-memory value into bytes. Created LFU cache to be used with heap data structure for managing LFU cache.

This commit is contained in:
Kelvin Clement Mwinuka
2024-03-01 16:25:04 +08:00
parent 97b41da729
commit e569bf6837
30 changed files with 364 additions and 228 deletions

View File

@@ -95,13 +95,13 @@ func Test_HandleSetRange(t *testing.T) {
preset: false,
command: []string{"SETRANGE", "key"},
expectedResponse: 0,
expectedError: errors.New(utils.WRONG_ARGS_RESPONSE),
expectedError: errors.New(utils.WrongArgsResponse),
},
{ // Command too long
preset: false,
command: []string{"SETRANGE", "key", "offset", "value", "value1"},
expectedResponse: 0,
expectedError: errors.New(utils.WRONG_ARGS_RESPONSE),
expectedError: errors.New(utils.WrongArgsResponse),
},
}
@@ -182,7 +182,7 @@ func Test_HandleStrLen(t *testing.T) {
presetValue: "",
command: []string{"STRLEN"},
expectedResponse: 0,
expectedError: errors.New(utils.WRONG_ARGS_RESPONSE),
expectedError: errors.New(utils.WrongArgsResponse),
},
{ // Too many args
preset: false,
@@ -190,7 +190,7 @@ func Test_HandleStrLen(t *testing.T) {
presetValue: "",
command: []string{"STRLEN", "test4", "test5"},
expectedResponse: 0,
expectedError: errors.New(utils.WRONG_ARGS_RESPONSE),
expectedError: errors.New(utils.WrongArgsResponse),
},
}
@@ -286,12 +286,12 @@ func Test_HandleSubStr(t *testing.T) {
},
{ // Command too short
command: []string{"SUBSTR", "key", "10"},
expectedError: errors.New(utils.WRONG_ARGS_RESPONSE),
expectedError: errors.New(utils.WrongArgsResponse),
},
{
// Command too long
command: []string{"SUBSTR", "key", "10", "15", "20"},
expectedError: errors.New(utils.WRONG_ARGS_RESPONSE),
expectedError: errors.New(utils.WrongArgsResponse),
},
{ // Start index is not an integer
command: []string{"SUBSTR", "key", "start", "10"},