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

@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"github.com/echovault/echovault/src/aof"
"github.com/echovault/echovault/src/eviction"
"github.com/echovault/echovault/src/memberlist"
"github.com/echovault/echovault/src/raft"
"github.com/echovault/echovault/src/snapshot"
@@ -28,6 +29,9 @@ type Server struct {
store map[string]interface{}
keyLocks map[string]*sync.RWMutex
keyCreationLock *sync.Mutex
keyExpiry map[string]time.Time
lfuCache *eviction.CacheLFU
lruCache *eviction.CacheLRU
Commands []utils.Command
@@ -66,6 +70,7 @@ func NewServer(opts Opts) *Server {
store: make(map[string]interface{}),
keyLocks: make(map[string]*sync.RWMutex),
keyCreationLock: &sync.Mutex{},
keyExpiry: make(map[string]time.Time),
}
if server.IsInCluster() {
server.raft = raft.NewRaft(raft.Opts{
@@ -117,6 +122,11 @@ func NewServer(opts Opts) *Server {
}),
)
}
// Set up lfu and lru caches
server.lfuCache = eviction.NewCacheLFU()
server.lruCache = eviction.NewCacheLRU()
return server
}