refactor: persist add Serializer

This commit is contained in:
weloe
2023-08-10 18:33:48 +08:00
parent 5f31fdee04
commit 097d1b9445
7 changed files with 85 additions and 75 deletions

View File

@@ -1,5 +1,7 @@
package persist
import "reflect"
type Adapter interface {
// GetStr string operate string value
@@ -15,8 +17,9 @@ type Adapter interface {
// UpdateStrTimeout update expire time
UpdateStrTimeout(key string, timeout int64) error
// Get get interface{}
Get(key string) interface{}
// Get returns interface{}
// If serializer != nil, need to input reflect.Type, used to serializer to deserialize
Get(key string, t ...reflect.Type) interface{}
// Set store interface{}
Set(key string, value interface{}, timeout int64) error
// Update only update interface{} value
@@ -27,4 +30,8 @@ type Adapter interface {
GetTimeout(key string) int64
// UpdateTimeout update timeout
UpdateTimeout(key string, timeout int64) error
// SetSerializer used to serialize and deserialize
// Serialize when call Set() or Update(), deserialize when call Get(key,t)
SetSerializer(serializer Serializer)
}