Removed etc and get modules and replaced them with generic module. Implemented functions to set and remove the expiry of a key. Implemented LRU and LFU caches using heap.

This commit is contained in:
Kelvin Clement Mwinuka
2024-03-03 16:21:12 +08:00
parent e569bf6837
commit 28f97656c4
22 changed files with 797 additions and 544 deletions

View File

@@ -0,0 +1,40 @@
package generic
import (
"errors"
"github.com/echovault/echovault/src/utils"
)
func setKeyFunc(cmd []string) ([]string, error) {
if len(cmd) < 3 || len(cmd) > 7 {
return nil, errors.New(utils.WrongArgsResponse)
}
return []string{cmd[1]}, nil
}
func msetKeyFunc(cmd []string) ([]string, error) {
if len(cmd[1:])%2 != 0 {
return nil, errors.New("each key must be paired with a value")
}
var keys []string
for i, key := range cmd[1:] {
if i%2 == 0 {
keys = append(keys, key)
}
}
return keys, nil
}
func getKeyFunc(cmd []string) ([]string, error) {
if len(cmd) != 2 {
return nil, errors.New(utils.WrongArgsResponse)
}
return []string{cmd[1]}, nil
}
func mgetKeyFunc(cmd []string) ([]string, error) {
if len(cmd) < 2 {
return nil, errors.New(utils.WrongArgsResponse)
}
return cmd[1:], nil
}