// Delete the key func (c *DeleteCommand) Apply(server raft.Server) (interface{}, error) { s, _ := server.StateMachine().(store.Store) e, err := s.Delete(c.Key, c.Recursive) if err != nil { log.Debug(err) return nil, err } return e, nil }
// Set the key-value pair if the current value of the key equals to the given prevValue func (c *CompareAndDeleteCommand) Apply(server raft.Server) (interface{}, error) { s, _ := server.StateMachine().(store.Store) e, err := s.CompareAndDelete(c.Key, c.PrevValue, c.PrevIndex) if err != nil { log.Debug(err) return nil, err } return e, nil }
// Create node func (c *CreateCommand) Apply(server raft.Server) (interface{}, error) { s, _ := server.StateMachine().(store.Store) e, err := s.Create(c.Key, c.Dir, c.Value, c.Unique, c.ExpireTime) if err != nil { log.Debug(err) return nil, err } return e, nil }
// Create node func (c *SetCommand) Apply(server raft.Server) (interface{}, error) { s, _ := server.StateMachine().(store.Store) // create a new node or replace the old node. e, err := s.Set(c.Key, c.Value, c.ExpireTime) if err != nil { log.Debug(err) return nil, err } return e, nil }
func (c SyncCommand) Apply(server raft.Server) (interface{}, error) { s, _ := server.StateMachine().(store.Store) s.DeleteExpiredKeys(c.Time) return nil, nil }