kvLibrary

package
v1.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

key value map高并发读写库

使用示例

不分片 少量数据使用

package main
func main() {
	iKv := kvLibrary.NewKVMap[int, int](0)
	iKv.Set(1, 1)
	fmt.Println(iKv.Get(1))
}

分片调用

package main

//自定义string类型 实现String方法
type tStr string
func (t tStr) String() string {
	return string(t)
}

func main() {
	kv := kvLibrary.NewShardKV[tStr, int](0, 0)
	kv.Set("1", 1)

	fmt.Println(kv.Get("1"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KVMap

type KVMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewKVMap

func NewKVMap[K comparable, V any](cap int) *KVMap[K, V]

func (*KVMap[K, V]) Clear

func (m *KVMap[K, V]) Clear()

func (*KVMap[K, V]) Del

func (m *KVMap[K, V]) Del(k K)

func (*KVMap[K, V]) Get

func (m *KVMap[K, V]) Get(k K) (V, bool)

func (*KVMap[K, V]) Items

func (m *KVMap[K, V]) Items() map[K]V

Items 获取所有数据 复制后返回

func (*KVMap[K, V]) Len

func (m *KVMap[K, V]) Len() int

func (*KVMap[K, V]) Set

func (m *KVMap[K, V]) Set(k K, v V)

func (*KVMap[K, V]) SetOnce

func (m *KVMap[K, V]) SetOnce(k K, v V) bool

SetOnce 仅允许单次写入

type ShardKV

type ShardKV[K ShardKey, V any] struct {
	// contains filtered or unexported fields
}

func NewShardKV

func NewShardKV[K ShardKey, V any](shardNum int, perCap int) *ShardKV[K, V]

NewShardKV 创建分片kv shardNum 分片数 perCap 每个分片容量

func (*ShardKV[K, V]) Clear

func (s *ShardKV[K, V]) Clear()

func (*ShardKV[K, V]) Del

func (s *ShardKV[K, V]) Del(key K)

func (*ShardKV[K, V]) Get

func (s *ShardKV[K, V]) Get(key K) (V, bool)

func (*ShardKV[K, V]) Items

func (s *ShardKV[K, V]) Items() map[K]V

func (*ShardKV[K, V]) Len

func (s *ShardKV[K, V]) Len() int

func (*ShardKV[K, V]) Set

func (s *ShardKV[K, V]) Set(key K, value V)

type ShardKey

type ShardKey interface {
	String() string
	comparable
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL