Skip to content

Commit d6058cd

Browse files
authored
Merge pull request #16 from PandaTechAM/development
minor optimization in lock service
2 parents 58fc937 + 9d51823 commit d6058cd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/DistributedCache/DistributedCache.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>4.0.6</Version>
11+
<Version>4.0.7</Version>
1212
<PackageId>Pandatech.DistributedCache</PackageId>
1313
<Title>Pandatech Distributed Cache</Title>
1414
<PackageTags>pandatech;cache;hybrid-cache;distributed-cahce;message-pack;rate-limiting;redis-lock;redis;fusion-cache</PackageTags>
1515
<Description>Pandatech.DistributedCache is a lightweight .NET library that extends the new HybridCache abstraction for seamless distributed caching on top of Redis. It provides strongly typed caching with MessagePack serialization, distributed locking, rate limiting, and stampede protection. With fewer than 500 lines of code, it is both easy to understand and simple to adopt, while still offering robust features for production environments.</Description>
1616
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-distributed-cache</RepositoryUrl>
17-
<PackageReleaseNotes>Nuget updates</PackageReleaseNotes>
17+
<PackageReleaseNotes>Minor optimization in lock service</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

src/DistributedCache/Services/Implementations/RedisLockService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ internal sealed class RedisLockService(IRedisClient redisClient, IOptions<CacheC
1616
private readonly IRedisDatabase _redisDatabase = redisClient.GetDefaultDatabase();
1717
private readonly TimeSpan _timeout = 2 * options.Value.DistributedLockMaxDuration;
1818

19-
public async Task<bool> AcquireLockAsync(string key, string lockValue)
19+
public Task<bool> AcquireLockAsync(string key, string lockValue)
2020
{
2121
var lockKey = CacheKeyFormatter.BuildLockKey(key);
22-
return await _redisDatabase.Database.StringSetAsync(lockKey, lockValue, _lockExpiry, When.NotExists);
22+
return _redisDatabase.Database.StringSetAsync(lockKey, lockValue, _lockExpiry, When.NotExists);
2323
}
2424

25-
public async Task<bool> HasLockAsync(string key)
25+
public Task<bool> HasLockAsync(string key)
2626
{
2727
var lockKey = CacheKeyFormatter.BuildLockKey(key);
2828

29-
return await _redisDatabase.Database.KeyExistsAsync(lockKey);
29+
return _redisDatabase.Database.KeyExistsAsync(lockKey);
3030
}
3131

3232
public async Task WaitUntilLockIsReleasedAsync(string key, CancellationToken token)
@@ -47,7 +47,7 @@ public async Task WaitUntilLockIsReleasedAsync(string key, CancellationToken tok
4747
}
4848
}
4949

50-
public async Task ReleaseLockAsync(string key, string lockValue)
50+
public Task ReleaseLockAsync(string key, string lockValue)
5151
{
5252
var lockKey = CacheKeyFormatter.BuildLockKey(key);
5353
const string script = @"
@@ -57,6 +57,6 @@ public async Task ReleaseLockAsync(string key, string lockValue)
5757
return 0
5858
end";
5959

60-
await _redisDatabase.Database.ScriptEvaluateAsync(script, [lockKey], [lockValue]);
60+
return _redisDatabase.Database.ScriptEvaluateAsync(script, [lockKey], [lockValue]);
6161
}
6262
}

0 commit comments

Comments
 (0)