github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/lib/kv/map_intf.go (about)

     1  package kv
     2  
     3  import "io"
     4  
     5  type SafeStoreKeyFilterFunc[K comparable] func(key K) bool
     6  
     7  func defaultAllKeysFilter[K comparable](key K) bool {
     8  	return true
     9  }
    10  
    11  type Closable interface {
    12  	io.Closer
    13  }
    14  
    15  type ThreadSafeStorer[K comparable, V any] interface {
    16  	Purge() error
    17  	AddOrUpdate(key K, obj V) error
    18  	Get(key K) (item V, exists bool)
    19  	Delete(key K) (V, error)
    20  	Replace(items map[K]V) error
    21  	ListKeys(filters ...SafeStoreKeyFilterFunc[K]) []K
    22  	ListValues(keys ...K) (items []V)
    23  }
    24  
    25  type Map[K comparable, V any] interface {
    26  	Put(key K, val V) error
    27  	Get(key K) (item V, exists bool)
    28  	Delete(key K) (V, error)
    29  	Foreach(action func(i uint64, key K, val V) (_continue bool))
    30  	MigrateFrom(m map[K]V) error
    31  	Clear()
    32  	Len() int64
    33  }