memory_storage

package module
v0.0.0-...-4e2a1ca Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: MIT Imports: 7 Imported by: 1

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) Close

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

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

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