mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
Merge branch 'feat/raft'
# Conflicts: # cluster/cluster.go # cluster/router.go # config/config.go # database/database.go # database/server.go
This commit is contained in:
@@ -34,6 +34,10 @@ type Server struct {
|
||||
role int32
|
||||
slaveStatus *slaveStatus
|
||||
masterStatus *masterStatus
|
||||
|
||||
// hooks
|
||||
insertCallback database.KeyEventCallback
|
||||
deleteCallback database.KeyEventCallback
|
||||
}
|
||||
|
||||
func fileExists(filename string) bool {
|
||||
@@ -286,6 +290,20 @@ func (server *Server) ForEach(dbIndex int, cb func(key string, data *database.Da
|
||||
server.mustSelectDB(dbIndex).ForEach(cb)
|
||||
}
|
||||
|
||||
// GetEntity returns the data entity to the given key
|
||||
func (server *Server) GetEntity(dbIndex int, key string) (*database.DataEntity, bool) {
|
||||
return server.mustSelectDB(dbIndex).GetEntity(key)
|
||||
}
|
||||
|
||||
func (server *Server) GetExpiration(dbIndex int, key string) *time.Time {
|
||||
raw, ok := server.mustSelectDB(dbIndex).ttlMap.Get(key)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
expireTime, _ := raw.(time.Time)
|
||||
return &expireTime
|
||||
}
|
||||
|
||||
// ExecMulti executes multi commands transaction Atomically and Isolated
|
||||
func (server *Server) ExecMulti(conn redis.Connection, watching map[string]uint32, cmdLines []CmdLine) redis.Reply {
|
||||
selectedDB, errReply := server.selectDB(conn.GetDBIndex())
|
||||
@@ -408,3 +426,20 @@ func (server *Server) GetAvgTTL(dbIndex, randomKeyCount int) int64 {
|
||||
}
|
||||
return ttlCount / int64(len(keys))
|
||||
}
|
||||
|
||||
func (server *Server) SetKeyInsertedCallback(cb database.KeyEventCallback) {
|
||||
server.insertCallback = cb
|
||||
for i := range server.dbSet {
|
||||
db := server.mustSelectDB(i)
|
||||
db.insertCallback = cb
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (server *Server) SetKeyDeletedCallback(cb database.KeyEventCallback) {
|
||||
server.deleteCallback = cb
|
||||
for i := range server.dbSet {
|
||||
db := server.mustSelectDB(i)
|
||||
db.deleteCallback = cb
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user