keylock

package module
v0.0.0-...-ce2f896 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 2 Imported by: 0

README


KeyLock

English 中文

KeyLock is a high-performance and scalable key-value lock library that supports concurrent lock operations for different types of keys. This library provides a key-based locking mechanism, allowing lock operations using key types such as strings and integers, suitable for scenarios that require high concurrency and fine-grained lock control.

Features

  • High Performance: Uses a pre-allocated array of locks to reduce lock contention.
  • Generic Support: Introduces generic features to implement lock support for different types of keys.
  • Scalability: Easy to add support for other types of keys.
  • Easy to Use: Provides a unified interface for easy use and integration.

Getting KeyLock

Download and install KeyLock using the go get command:

go get github.com/lyonnee/keylock

Usage

Here is a simple example of how to use KeyLock.

String Lock
func main() {
    // Create a string key-value lock
    textLocker := keylock.NewTextLocker[string](10)

    // Lock a string key
    l := textLocker.Lock("exampleKey")
    defer l.Unlock("exampleKey")
}
Numeric Lock
func main() {
    // Create an integer key-value lock
    numLocker := keylock.NewNumberLocker[int](512)

    // Lock a numeric key
    l := numLocker.Lock(123)
    defer l.Unlock(123)
}

Questions?

If you have any questions or suggestions, please feel free to submit an issue. We appreciate any feedback and improvement suggestions.

License

This project follows the MIT license. Please refer to the LICENSE file for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyLocker

type KeyLocker[T KeyType] interface {
	Lock(key T) *sync.Mutex
	Unlock(key T)
}

func NewNumberLocker

func NewNumberLocker[T NumberType](n int) KeyLocker[T]

func NewTextLocker

func NewTextLocker[T TextType](n int) KeyLocker[T]

type KeyType

type KeyType interface {
	TextType | NumberType
}

type NumberType

type NumberType interface {
	~int | ~uint
}

type TextType

type TextType interface {
	~[]byte | ~string
}

Jump to

Keyboard shortcuts

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