forked from dotnetcore/EasyCaching
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dotnetcore#317 from dotnetcore/dev
v1.4.0
- Loading branch information
Showing
52 changed files
with
1,516 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<EasyCachingCorePackageVersion>1.3.0</EasyCachingCorePackageVersion> | ||
<EasyCachingMemcachedPackageVersion>1.3.0</EasyCachingMemcachedPackageVersion> | ||
<EasyCachingRedisPackageVersion>1.3.0</EasyCachingRedisPackageVersion> | ||
<EasyCachingSQLitePackageVersion>1.3.0</EasyCachingSQLitePackageVersion> | ||
<EasyCachingInMemoryPackageVersion>1.3.0</EasyCachingInMemoryPackageVersion> | ||
<EasyCachingHybridPackageVersion>1.3.0</EasyCachingHybridPackageVersion> | ||
<EasyCachingAspectCorePackageVersion>1.3.0</EasyCachingAspectCorePackageVersion> | ||
<EasyCachingCastlePackageVersion>1.3.0</EasyCachingCastlePackageVersion> | ||
<EasyCachingResponseCachingPackageVersion>1.3.0</EasyCachingResponseCachingPackageVersion> | ||
<EasyCachingJsonPackageVersion>1.3.0</EasyCachingJsonPackageVersion> | ||
<EasyCachingMessagePackPackageVersion>1.3.0</EasyCachingMessagePackPackageVersion> | ||
<EasyCachingProtobufPackageVersion>1.3.0</EasyCachingProtobufPackageVersion> | ||
<EasyCachingCSRedisPackageVersion>1.3.0</EasyCachingCSRedisPackageVersion> | ||
<EasyCachingRedisBusPackageVersion>1.3.0</EasyCachingRedisBusPackageVersion> | ||
<EasyCachingCSRedisBusPackageVersion>1.3.0</EasyCachingCSRedisBusPackageVersion> | ||
<EasyCachingRabbitBusPackageVersion>1.3.0</EasyCachingRabbitBusPackageVersion> | ||
<EasyCachingDiskPackageVersion>1.3.0</EasyCachingDiskPackageVersion> | ||
<EasyCachingMsExtPackageVersion>1.3.0</EasyCachingMsExtPackageVersion> | ||
<EasyCachingLiteDBPackageVersion>1.3.0</EasyCachingLiteDBPackageVersion> | ||
<EasyCachingSTJsonPackageVersion>1.3.0</EasyCachingSTJsonPackageVersion> | ||
<EasyCachingCorePackageVersion>1.4.0</EasyCachingCorePackageVersion> | ||
<EasyCachingMemcachedPackageVersion>1.4.0</EasyCachingMemcachedPackageVersion> | ||
<EasyCachingRedisPackageVersion>1.4.0</EasyCachingRedisPackageVersion> | ||
<EasyCachingSQLitePackageVersion>1.4.0</EasyCachingSQLitePackageVersion> | ||
<EasyCachingInMemoryPackageVersion>1.4.0</EasyCachingInMemoryPackageVersion> | ||
<EasyCachingHybridPackageVersion>1.4.0</EasyCachingHybridPackageVersion> | ||
<EasyCachingAspectCorePackageVersion>1.4.0</EasyCachingAspectCorePackageVersion> | ||
<EasyCachingCastlePackageVersion>1.4.0</EasyCachingCastlePackageVersion> | ||
<EasyCachingResponseCachingPackageVersion>1.4.0</EasyCachingResponseCachingPackageVersion> | ||
<EasyCachingJsonPackageVersion>1.4.0</EasyCachingJsonPackageVersion> | ||
<EasyCachingMessagePackPackageVersion>1.4.0</EasyCachingMessagePackPackageVersion> | ||
<EasyCachingProtobufPackageVersion>1.4.0</EasyCachingProtobufPackageVersion> | ||
<EasyCachingCSRedisPackageVersion>1.4.0</EasyCachingCSRedisPackageVersion> | ||
<EasyCachingRedisBusPackageVersion>1.4.0</EasyCachingRedisBusPackageVersion> | ||
<EasyCachingCSRedisBusPackageVersion>1.4.0</EasyCachingCSRedisBusPackageVersion> | ||
<EasyCachingRabbitBusPackageVersion>1.4.0</EasyCachingRabbitBusPackageVersion> | ||
<EasyCachingDiskPackageVersion>1.4.0</EasyCachingDiskPackageVersion> | ||
<EasyCachingMsExtPackageVersion>1.4.0</EasyCachingMsExtPackageVersion> | ||
<EasyCachingLiteDBPackageVersion>1.4.0</EasyCachingLiteDBPackageVersion> | ||
<EasyCachingSTJsonPackageVersion>1.4.0</EasyCachingSTJsonPackageVersion> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/EasyCaching.CSRedis/DistributedLock/CSRedisLockFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using EasyCaching.Core.DistributedLock; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EasyCaching.CSRedis.DistributedLock | ||
{ | ||
public class CSRedisLockFactory : DistributedLockFactory | ||
{ | ||
private readonly IEnumerable<EasyCachingCSRedisClient> _clients; | ||
|
||
public CSRedisLockFactory(IEnumerable<EasyCachingCSRedisClient> clients, | ||
IOptionsMonitor<RedisOptions> optionsMonitor, | ||
ILoggerFactory loggerFactory = null) | ||
: base(name => DistributedLockOptions.FromProviderOptions(optionsMonitor.Get(name)), loggerFactory) => | ||
_clients = clients; | ||
|
||
protected override IDistributedLockProvider GetLockProvider(string name) => | ||
new CSRedisLockProvider(name, _clients.Single(x => x.Name.Equals(name))); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/EasyCaching.CSRedis/DistributedLock/CSRedisLockProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using CSRedis; | ||
using EasyCaching.Core.DistributedLock; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyCaching.CSRedis.DistributedLock | ||
{ | ||
public class CSRedisLockProvider : IDistributedLockProvider | ||
{ | ||
private readonly string _name; | ||
private readonly EasyCachingCSRedisClient _database; | ||
|
||
public CSRedisLockProvider(string name, EasyCachingCSRedisClient database) | ||
{ | ||
_name = name; | ||
_database = database; | ||
} | ||
|
||
public Task<bool> SetAsync(string key, byte[] value, int ttlMs) => | ||
_database.SetAsync($"{_name}/{key}", value, TimeSpan.FromMilliseconds(ttlMs)); | ||
|
||
public bool Add(string key, byte[] value, int ttlMs) => | ||
_database.Set($"{_name}/{key}", value, TimeSpan.FromMilliseconds(ttlMs), RedisExistence.Nx); | ||
|
||
public Task<bool> AddAsync(string key, byte[] value, int ttlMs) => | ||
_database.SetAsync($"{_name}/{key}", value, TimeSpan.FromMilliseconds(ttlMs), RedisExistence.Nx); | ||
|
||
public bool Delete(string key, byte[] value) => | ||
(long)_database.Eval(@"if redis.call('GET', KEYS[1]) == ARGV[1] then | ||
return redis.call('DEL', KEYS[1]); | ||
end | ||
return -1;", $"{_name}/{key}", value) >= 0; | ||
|
||
public async Task<bool> DeleteAsync(string key, byte[] value) => | ||
(long)await _database.EvalAsync(@"if redis.call('GET', KEYS[1]) == ARGV[1] then | ||
return redis.call('DEL', KEYS[1]); | ||
end | ||
return -1;", $"{_name}/{key}", value) >= 0; | ||
|
||
public bool CanRetry(Exception ex) => ex is RedisClientException; | ||
} | ||
} |
Oops, something went wrong.