Skip to content

Conversation

pengweiqhca
Copy link
Contributor

Local lock: MemoryLock
Distributed Lock: CSRedisLock, MemcachedLock, RedisLock

@pengweiqhca
Copy link
Contributor Author

Interceptor_Should_Recognize_Subclass_Of_EasyCachingAble_Attribute test fail.

Copy link
Member

@catcherwong catcherwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

(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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about move the lua script to a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@catcherwong
Copy link
Member

Interceptor_Should_Recognize_Subclass_Of_EasyCachingAble_Attribute

This unit test is a bit unstable. I'll fix it later.

@catcherwong
Copy link
Member

Please change the target branch from master to dev.

@pengweiqhca pengweiqhca changed the base branch from master to dev July 17, 2021 12:54
Comment on lines +18 to +48
public async Task Concurrency_Test()
{
ThreadPool.SetMinThreads(1000, 1000);

var random = new Random();
var key = Guid.NewGuid().ToString("N");
var counter = 0;

using var @lock = Factory.CreateLock("test", Guid.NewGuid().ToString());

await Task.WhenAll(Enumerable.Range(0, 100)
.Select(_ => Task.Run(async () =>
{
for (var index = 0; index < 1000; index++)
{
var value = Interlocked.Increment(ref counter);

try
{
Assert.True(await @lock.LockAsync(15000, CancellationToken.None), value.ToString());

await Task.Delay(random.Next(0, 10));

await @lock.ReleaseAsync().ConfigureAwait(false);
}
catch (DistributedLockException)
{
}
}
})));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except repeat lock, all case should be success.

Copy link
Member

@LabelZhou LabelZhou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

{
return BaseGet(cacheKey, dataRetriever, expiration);
{
if (_lockFactory == null) return BaseGet<T>(cacheKey, dataRetriever, expiration);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also calls to the BaseGet() at the EasyCaching.LiteDB.DefaultLiteDBCachingProvider.BaseGetAsync()

var item = dataRetriever();
if (item != null || _options.CacheNulls)
{
BaseSet(cacheKey, item, expiration);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more appropriate to call Set() here to record the diagnostic log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseGet have no diagnostic log

/// </summary>
/// <param name="services">Services.</param>
public void AddServices(IServiceCollection services) =>
services.Replace(ServiceDescriptor.Singleton<IDistributedLockFactory, CSRedisLockFactory>(x =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more appropriate to use AddSingleton here, and configure DistributedLockName for each cache using option? (similar to SerializerName)

services.AddEasyCaching(x =>
                x.UseCSRedis(options =>
                {
                    options.DBConfig = new CSRedisDBOptions
                    {
                        ConnectionStrings = new System.Collections.Generic.List<string>
                        {
                            "127.0.0.1:6388,defaultDatabase=13,poolsize=10"
                        }
                    };



options.DistributedLockName = "dlf";
                }).WithCSRedisLock("dlf"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fix this issure

@catcherwong catcherwong merged commit ed4d79b into dotnetcore:dev Jul 18, 2021
@pengweiqhca pengweiqhca deleted the lock branch July 18, 2021 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants