MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / acquireLock

Method acquireLock

internal/repository/cache/lotteryDraw.go:303–311  ·  view source on GitHub ↗

acquireLock 尝试获取分布式锁

(ctx context.Context, lockKey, lockValue string, ttl time.Duration)

Source from the content-addressed store, hash-verified

301
302// acquireLock 尝试获取分布式锁
303func (c *lotteryDrawCache) acquireLock(ctx context.Context, lockKey, lockValue string, ttl time.Duration) (bool, error) {
304 // 使用 SET 命令获取锁
305 ok, err := c.client.SetNX(ctx, lockKey, lockValue, ttl).Result()
306 if err != nil {
307 return false, err
308 }
309
310 return ok, nil
311}
312
313// releaseLock 释放分布式锁,使用 Lua 脚本确保操作的原子性
314func (c *lotteryDrawCache) releaseLock(ctx context.Context, lockKey, lockValue string) error {

Callers 2

Calls 1

SetNXMethod · 0.65

Tested by

no test coverage detected