memory_storage

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Memory Storage

一、这是什么?

基于内存实现的Storage,相当于是把锁存放在内存中。

二、安装

go get -u github.com/storage-lock/go-memory-storage

三、API示例

package main

import (
	"fmt"
	memory_storage "github.com/storage-lock/go-memory-storage"
)

func main() {

	// 直接创建就可以使用了
	storage := memory_storage.NewMemoryStorage()
	fmt.Println(storage.GetName())

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

MemoryStorage 把锁存储在内存中,可以借助这个实现进程级别的锁,算是对内部的锁的一个扩展,但是似乎作用不是很大,仅仅是为了丰富实现... 也可以认为这个Storage是一个实现的样例,其它的存储引擎的实现可以参考此实现的逻辑

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

func (*MemoryStorage) Capabilities

func (x *MemoryStorage) Capabilities() []storage.StorageCapability

Capabilities 声明内存存储支持的能力 内存存储通过 sync.RWMutex 保护的原子操作支持 CAS, 使用本地 time.Now() 作为时间源(单进程内时间天然一致,但不适用于跨进程场景)

func (*MemoryStorage) Close

func (x *MemoryStorage) Close(ctx context.Context) error

func (*MemoryStorage) CompareAndSwapBatch added in v0.1.0

func (x *MemoryStorage) CompareAndSwapBatch(ctx context.Context, ops []storage.CASOp) error

CompareAndSwapBatch 在同一把互斥锁里检查并写入全部 key。 先完整检查,再写入;任一条件失败时 map 保持调用前的内容。

func (*MemoryStorage) CreateWithVersion

func (x *MemoryStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, lockInformation *storage.LockInformation) error

func (*MemoryStorage) DeleteWithVersion

func (x *MemoryStorage) DeleteWithVersion(ctx context.Context, lockId string, exceptedVersion storage.Version, lockInformation *storage.LockInformation) error

func (*MemoryStorage) Get

func (x *MemoryStorage) Get(ctx context.Context, lockId string) (string, error)

func (*MemoryStorage) GetName

func (x *MemoryStorage) GetName() string

func (*MemoryStorage) GetTime

func (x *MemoryStorage) GetTime(ctx context.Context) (time.Time, error)

func (*MemoryStorage) Init

func (x *MemoryStorage) Init(ctx context.Context) error

func (*MemoryStorage) List

func (*MemoryStorage) UpdateWithVersion

func (x *MemoryStorage) UpdateWithVersion(ctx context.Context, lockId string, exceptedVersion, newVersion storage.Version, lockInformation *storage.LockInformation) error

func (*MemoryStorage) Watch

func (x *MemoryStorage) Watch(ctx context.Context, lockId string) (<-chan *storage.LockInformation, error)

type MemoryStorageValue

type MemoryStorageValue struct {

	// 存储的是哪个锁的信息
	LockId string

	// 锁的版本号是多少
	Version storage.Version

	// 锁的信息序列化为JSON字符串存储在这个字段
	LockInformationJsonString string
}

MemoryStorageValue 锁在内存中的实际存储结构

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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