-
Notifications
You must be signed in to change notification settings - Fork 576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support LRU and LFU eviction #167
Conversation
database/database.go
Outdated
|
||
//RandomDistinctKeysForEviction random get keys for eviction | ||
func (db *DB) RandomDistinctKeysForEviction(limit int) []string { | ||
if db.evictionPolicy.IsAllKeys() == false { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通常写作 if !db.evictionPolicy.IsAllKeys()
database/database.go
Outdated
if db.evictionPolicy.IsAllKeys() == false { | ||
keys := make([]string, limit) | ||
i := 0 | ||
db.data.ForEach(func(key string, val interface{}) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ttlMap 也有RandomDistinctKeys方法的
database/database.go
Outdated
} | ||
|
||
//RandomDistinctKeysForEviction random get keys for eviction | ||
func (db *DB) RandomDistinctKeysForEviction(limit int) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码只会调用一次,不需要抽象成函数
eviction/lfu.go
Outdated
return key | ||
} | ||
|
||
func GetLFUCounter(lfu int32) uint8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此函数不需要公开,应为私有
eviction/lfu.go
Outdated
} | ||
|
||
// LFULogIncr counter increase | ||
func LFULogIncr(counter uint8) uint8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此函数应私有
eviction/lfu.go
Outdated
} | ||
|
||
//LFUDecrAndReturn counter decr | ||
func LFUDecrAndReturn(lfu int32) int32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此函数应私有
eviction/lfu.go
Outdated
} | ||
|
||
// LFUTimeElapsed Obtaining the time difference from the last time | ||
func LFUTimeElapsed(ldt int32) int32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此函数应私有
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface/eviction, eviction/lru, eviction/lfu 放入 database 包内即可,不需要公开到整个项目。
以及文件名拼错了 enviction_policy.go
database/database.go
Outdated
} | ||
|
||
//MakeEviction make a new mark about a key | ||
func (db *DB) MakeEviction(keys []string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MakeEviction 函数应私有,作为 MakeXXX 却无返回值就很别扭。可以改为 initEvitionMark
database/database.go
Outdated
} | ||
|
||
//UpdateMark update mark about eviction | ||
func (db *DB) UpdateMark(keys []string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 函数应私有
- 这是 DB 的函数不是 evictionPolicy 的函数,函数名中带上 eviction 否则不知道更新的是什么 Mark.
UpdateMark -> updateEvictionMark
|
可以使用 |
有几个问题, |
evitction 应该写入 aof 并传播到 slave |
redis 在达到 maxmemory 时不会只淘汰一个 key, 参考 getMaxmemoryState 计算 mem_tofree |
请阅读 #146 |
因为config中没有内存设置,所以逐出方法没有使用