mirror of
				https://github.com/EchoVault/SugarDB.git
				synced 2025-10-31 19:32:59 +08:00 
			
		
		
		
	Created IsMaxMemoryExceeded utility function that is used to check whether the server has exceeded the max memory.
Check whether max memory is exceeded before setting value or creating new key. Return error from SetValue function when max memory is exceeded. This change has been propagated to the aof and snapshot engines as well. Snapshot engine now only accepts SetValue option. No longer does it neet to use CreateKeyAndLock & KeyUnlock functions itself.
This commit is contained in:
		| @@ -26,7 +26,7 @@ type Engine struct { | ||||
| 	startRewrite  func() | ||||
| 	finishRewrite func() | ||||
| 	getState      func() map[string]interface{} | ||||
| 	setValue      func(key string, value interface{}) | ||||
| 	setValue      func(key string, value interface{}) error | ||||
| 	handleCommand func(command []byte) | ||||
| } | ||||
|  | ||||
| @@ -60,7 +60,7 @@ func WithGetStateFunc(f func() map[string]interface{}) func(engine *Engine) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func WithSetValueFunc(f func(key string, value interface{})) func(engine *Engine) { | ||||
| func WithSetValueFunc(f func(key string, value interface{}) error) func(engine *Engine) { | ||||
| 	return func(engine *Engine) { | ||||
| 		engine.setValue = f | ||||
| 	} | ||||
| @@ -94,7 +94,10 @@ func NewAOFEngine(options ...func(engine *Engine)) *Engine { | ||||
| 		startRewrite:  func() {}, | ||||
| 		finishRewrite: func() {}, | ||||
| 		getState:      func() map[string]interface{} { return nil }, | ||||
| 		setValue:      func(key string, value interface{}) {}, | ||||
| 		setValue: func(key string, value interface{}) error { | ||||
| 			// No-Op by default | ||||
| 			return nil | ||||
| 		}, | ||||
| 		handleCommand: func(command []byte) {}, | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kelvin Mwinuka
					Kelvin Mwinuka