Skip to content

KeyLock是一个高效可扩展的键值锁库,支持字符串和整数等类型的并发锁操作,适用于高并发场景下的细粒度锁控制需求。(KeyLock is an efficient and scalable key-value lock library, supporting concurrent lock operations for types such as strings and integers, suitable for fine-grained lock control needs in high-concurrency scenarios.)

License

Notifications You must be signed in to change notification settings

lyonnee/keylock

Repository files navigation


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.

About

KeyLock是一个高效可扩展的键值锁库,支持字符串和整数等类型的并发锁操作,适用于高并发场景下的细粒度锁控制需求。(KeyLock is an efficient and scalable key-value lock library, supporting concurrent lock operations for types such as strings and integers, suitable for fine-grained lock control needs in high-concurrency scenarios.)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages