mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-06 16:36:54 +08:00
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:
40
src/modules/generic/key_funcs.go
Normal file
40
src/modules/generic/key_funcs.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user