From acafcf91b4a40e8c3aa8af7d79e58ddbd93424ae Mon Sep 17 00:00:00 2001 From: catcherwong Date: Tue, 19 Nov 2019 08:45:41 +0800 Subject: [PATCH 1/3] :loud_sound: add code-of-conduct.md --- code-of-conduct.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 code-of-conduct.md diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 00000000..8c5b86f2 --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,45 @@ +# MEMBER CODE OF CONDUCT + +The .NET Core Community (NCC) was created to doster an open, innovative, inclusive and welcoming community around open source .NET/.NET Core. To clarify expected behaviour in our communities we have adopted the [Contributor Covenant](contributor-covenant.org). This code of conduct has been adopted by [many other open source communities](contributor-covenant.org/adopters) and we feel it expresses our values well. + +### Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +### Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others’ private information, such as a physical or electronic address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +### Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +### Scope + +This Code of Conduct applies within all project spaces, and it also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +### Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [dotnet-community@outlook.com](dotnet-community@outlook.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership. + +### Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file From 8beaac3a9415172dc5075dc227389f46299f4a68 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Tue, 26 Nov 2019 10:09:02 +0800 Subject: [PATCH 2/3] :sparkles: redis provider support Hyperloglog --- build/releasenotes.props | 10 +- build/version.props | 4 +- ...faultCSRedisCachingProvider.Hyperloglog.cs | 79 +++++++++++++ src/EasyCaching.Core/IRedisCachingProvider.cs | 48 +++++++- ...DefaultRedisCachingProvider.Hyperloglog.cs | 110 ++++++++++++++++++ .../BaseRedisFeatureCachingProviderTest.cs | 85 ++++++++++++++ 6 files changed, 325 insertions(+), 11 deletions(-) create mode 100644 src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Hyperloglog.cs create mode 100644 src/EasyCaching.Redis/DefaultRedisCachingProvider.Hyperloglog.cs diff --git a/build/releasenotes.props b/build/releasenotes.props index fa198d35..d52a27f9 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -19,13 +19,7 @@ 7. Modify some extension methods' namespace. - 1. Make Interceptors and response caching Support .netcore3.0. - 2. Remove WithServices method to support console apps. - 3. Improve RabbitMQ bus. - 4. Add deep clone for memory cache provider. - 5. Support multi instances of hybrid provider. - 6. Upgrading dependencies. - 7. Modify some extension methods' namespace. + 1. Support Hyperloglog. 1. Make Interceptors and response caching Support .netcore3.0. @@ -91,7 +85,7 @@ 7. Modify some extension methods' namespace. - 1. Support sentinel mode. + 1. Support Hyperloglog. 1. Support sentinel mode. diff --git a/build/version.props b/build/version.props index 99edd7d9..5c51b303 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 0.8.0 0.8.0 - 0.8.0 + 0.8.2 0.8.0 0.8.0 0.8.1 @@ -12,7 +12,7 @@ 0.8.1 0.8.1 0.8.0 - 0.8.1 + 0.8.2 0.8.0 0.8.1 0.8.0 diff --git a/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Hyperloglog.cs b/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Hyperloglog.cs new file mode 100644 index 00000000..aa3798e9 --- /dev/null +++ b/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Hyperloglog.cs @@ -0,0 +1,79 @@ +namespace EasyCaching.CSRedis +{ + using EasyCaching.Core; + using System.Collections.Generic; + using System.Threading.Tasks; + + public partial class DefaultCSRedisCachingProvider : IRedisCachingProvider + { + public bool PfAdd(string cacheKey, List values) + { + ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); + ArgumentCheck.NotNullAndCountGTZero(values, nameof(values)); + + var list = new List(); + + foreach (var item in values) + { + list.Add(_serializer.Serialize(item)); + } + + var res = _cache.PfAdd(cacheKey, list.ToArray()); + return res; + } + + public async Task PfAddAsync(string cacheKey, List values) + { + ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); + ArgumentCheck.NotNullAndCountGTZero(values, nameof(values)); + + var list = new List(); + + foreach (var item in values) + { + list.Add(_serializer.Serialize(item)); + } + + var res = await _cache.PfAddAsync(cacheKey, list.ToArray()); + return res; + } + + [System.Obsolete()] + public long PfCount(List cacheKeys) + { + ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); + + var res = _cache.PfCount(cacheKeys.ToArray()); + return res; + } + + [System.Obsolete()] + public async Task PfCountAsync(List cacheKeys) + { + ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); + + var res = await _cache.PfCountAsync(cacheKeys.ToArray()); + return res; + } + + [System.Obsolete()] + public bool PfMerge(string destKey, List sourceKeys) + { + ArgumentCheck.NotNullOrWhiteSpace(destKey, nameof(destKey)); + ArgumentCheck.NotNullAndCountGTZero(sourceKeys, nameof(sourceKeys)); + + var res = _cache.PfMerge(destKey, sourceKeys.ToArray()); + return res; + } + + [System.Obsolete()] + public async Task PfMergeAsync(string destKey, List sourceKeys) + { + ArgumentCheck.NotNullOrWhiteSpace(destKey, nameof(destKey)); + ArgumentCheck.NotNullAndCountGTZero(sourceKeys, nameof(sourceKeys)); + + var res = await _cache.PfMergeAsync(destKey, sourceKeys.ToArray()); + return res; + } + } +} diff --git a/src/EasyCaching.Core/IRedisCachingProvider.cs b/src/EasyCaching.Core/IRedisCachingProvider.cs index f59077de..451d6ec1 100644 --- a/src/EasyCaching.Core/IRedisCachingProvider.cs +++ b/src/EasyCaching.Core/IRedisCachingProvider.cs @@ -789,7 +789,53 @@ public interface IRedisCachingProvider /// /// /// - Task ZScoreAsync(string cacheKey, T cacheValue); + Task ZScoreAsync(string cacheKey, T cacheValue); + #endregion + + + #region Hyperloglog + /// + /// https://redis.io/commands/pfadd + /// + /// + /// + /// + /// + bool PfAdd(string cacheKey, List values); + /// + /// https://redis.io/commands/pfadd + /// + /// + /// + /// + /// + Task PfAddAsync(string cacheKey, List values); + /// + /// https://redis.io/commands/pfcount + /// + /// + /// + long PfCount(List cacheKeys); + /// + /// https://redis.io/commands/pfcount + /// + /// + /// + Task PfCountAsync(List cacheKeys); + /// + /// https://redis.io/commands/pfmerge + /// + /// + /// + /// + bool PfMerge(string destKey, List sourceKeys); + /// + /// https://redis.io/commands/pfmerge + /// + /// + /// + /// + Task PfMergeAsync(string destKey, List sourceKeys); #endregion } } diff --git a/src/EasyCaching.Redis/DefaultRedisCachingProvider.Hyperloglog.cs b/src/EasyCaching.Redis/DefaultRedisCachingProvider.Hyperloglog.cs new file mode 100644 index 00000000..1e060c93 --- /dev/null +++ b/src/EasyCaching.Redis/DefaultRedisCachingProvider.Hyperloglog.cs @@ -0,0 +1,110 @@ +namespace EasyCaching.Redis +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using EasyCaching.Core; + using EasyCaching.Core.Internal; + using StackExchange.Redis; + + /// + /// Default redis caching provider. + /// + public partial class DefaultRedisCachingProvider : IRedisCachingProvider + { + public bool PfAdd(string cacheKey, List values) + { + ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); + ArgumentCheck.NotNullAndCountGTZero(values, nameof(values)); + + var list = new List(); + + foreach (var item in values) + { + list.Add(_serializer.Serialize(item)); + } + + var res = _cache.HyperLogLogAdd(cacheKey, list.ToArray()); + return res; + } + + public async Task PfAddAsync(string cacheKey, List values) + { + ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); + ArgumentCheck.NotNullAndCountGTZero(values, nameof(values)); + + var list = new List(); + + foreach (var item in values) + { + list.Add(_serializer.Serialize(item)); + } + + var res = await _cache.HyperLogLogAddAsync(cacheKey, list.ToArray()); + return res; + } + + public long PfCount(List cacheKeys) + { + ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); + + var list = new List(); + + foreach (var item in cacheKeys) + { + list.Add(item); + } + + var res = _cache.HyperLogLogLength(list.ToArray()); + return res; + } + + public async Task PfCountAsync(List cacheKeys) + { + ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); + + var list = new List(); + + foreach (var item in cacheKeys) + { + list.Add(item); + } + + var res = await _cache.HyperLogLogLengthAsync(list.ToArray()); + return res; + } + + public bool PfMerge(string destKey, List sourceKeys) + { + ArgumentCheck.NotNullOrWhiteSpace(destKey, nameof(destKey)); + ArgumentCheck.NotNullAndCountGTZero(sourceKeys, nameof(sourceKeys)); + + var list = new List(); + + foreach (var item in sourceKeys) + { + list.Add(item); + } + + _cache.HyperLogLogMerge(destKey, list.ToArray()); + return true; + } + + public async Task PfMergeAsync(string destKey, List sourceKeys) + { + ArgumentCheck.NotNullOrWhiteSpace(destKey, nameof(destKey)); + ArgumentCheck.NotNullAndCountGTZero(sourceKeys, nameof(sourceKeys)); + + var list = new List(); + + foreach (var item in sourceKeys) + { + list.Add(item); + } + + await _cache.HyperLogLogMergeAsync(destKey, list.ToArray()); + return true; + } + } +} diff --git a/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs index 27916dd2..2e6f1b18 100644 --- a/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs @@ -1550,5 +1550,90 @@ protected virtual async Task SRandMemberAsync_With_Exist_Should_Succeed() await _baseProvider.RemoveAsync(cacheKey); } #endregion + + #region Hyperloglog + [Fact] + protected virtual void PfAdd_Should_Succeed() + { + var cacheKey = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + + var res1 = _provider.PfAdd(cacheKey, new List { "foo", "bar", "zap" }); + var res2 = _provider.PfAdd(cacheKey, new List { "zap", "zap", "zap" }); + Assert.True(res1); + Assert.True(res2); + + var count = _provider.PfCount(new List { cacheKey }); + + Assert.Equal(3, count); + _provider.KeyDel(cacheKey); + } + + [Fact] + protected virtual async Task PfAddAsync_Should_Succeed() + { + var cacheKey = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + + var res1 = await _provider.PfAddAsync(cacheKey, new List { "foo", "bar", "zap" }); + var res2 = await _provider.PfAddAsync(cacheKey, new List { "zap", "zap", "zap" }); + Assert.True(res1); + Assert.True(res2); + + var count = await _provider.PfCountAsync(new List { cacheKey }); + + Assert.Equal(3, count); + + await _provider.KeyDelAsync(cacheKey); + } + + [Fact] + protected virtual void PfMerge_Should_Succeed() + { + var cacheKey0 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey1 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey2 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + + var res1 = _provider.PfAdd(cacheKey1, new List { "foo", "bar", "zap", "a" }); + var res2 = _provider.PfAdd(cacheKey2, new List { "a", "b", "c", "foo" }); + Assert.True(res1); + Assert.True(res2); + + + var flag = _provider.PfMerge(cacheKey0, new List { cacheKey1, cacheKey2 }); + Assert.True(flag); + + var count = _provider.PfCount(new List { cacheKey0 }); + + Assert.Equal(6, count); + + _provider.KeyDel(cacheKey0); + _provider.KeyDel(cacheKey1); + _provider.KeyDel(cacheKey2); + } + + [Fact] + protected virtual async Task PfMergeAsync_Should_Succeed() + { + var cacheKey0 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey1 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey2 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + + var res1 = await _provider.PfAddAsync(cacheKey1, new List { "foo", "bar", "zap", "a" }); + var res2 = await _provider.PfAddAsync(cacheKey2, new List { "a", "b", "c", "foo" }); + Assert.True(res1); + Assert.True(res2); + + + var flag = await _provider.PfMergeAsync(cacheKey0, new List { cacheKey1, cacheKey2 }); + Assert.True(flag); + + var count = await _provider.PfCountAsync(new List { cacheKey0 }); + + Assert.Equal(6, count); + + await _provider.KeyDelAsync(cacheKey0); + await _provider.KeyDelAsync(cacheKey1); + await _provider.KeyDelAsync(cacheKey2); + } + #endregion } } From 81c537d64529405bb24ae6594717d568584bda6e Mon Sep 17 00:00:00 2001 From: catcherwong Date: Tue, 26 Nov 2019 10:26:52 +0800 Subject: [PATCH 3/3] :green_heart: fixed unit tests --- .../BaseRedisFeatureCachingProviderTest.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs index 2e6f1b18..cbaea1a6 100644 --- a/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/BaseRedisFeatureCachingProviderTest.cs @@ -1555,12 +1555,12 @@ protected virtual async Task SRandMemberAsync_With_Exist_Should_Succeed() [Fact] protected virtual void PfAdd_Should_Succeed() { - var cacheKey = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey = $"{_nameSpace}-pfadd-{Guid.NewGuid().ToString()}"; var res1 = _provider.PfAdd(cacheKey, new List { "foo", "bar", "zap" }); var res2 = _provider.PfAdd(cacheKey, new List { "zap", "zap", "zap" }); Assert.True(res1); - Assert.True(res2); + Assert.False(res2); var count = _provider.PfCount(new List { cacheKey }); @@ -1571,12 +1571,12 @@ protected virtual void PfAdd_Should_Succeed() [Fact] protected virtual async Task PfAddAsync_Should_Succeed() { - var cacheKey = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey = $"{_nameSpace}-pfaddasync-{Guid.NewGuid().ToString()}"; var res1 = await _provider.PfAddAsync(cacheKey, new List { "foo", "bar", "zap" }); var res2 = await _provider.PfAddAsync(cacheKey, new List { "zap", "zap", "zap" }); Assert.True(res1); - Assert.True(res2); + Assert.False(res2); var count = await _provider.PfCountAsync(new List { cacheKey }); @@ -1588,9 +1588,9 @@ protected virtual async Task PfAddAsync_Should_Succeed() [Fact] protected virtual void PfMerge_Should_Succeed() { - var cacheKey0 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; - var cacheKey1 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; - var cacheKey2 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey0 = $"{_nameSpace}-pfmerge-{Guid.NewGuid().ToString()}"; + var cacheKey1 = $"{_nameSpace}-pfmerge-{Guid.NewGuid().ToString()}"; + var cacheKey2 = $"{_nameSpace}-pfmerge-{Guid.NewGuid().ToString()}"; var res1 = _provider.PfAdd(cacheKey1, new List { "foo", "bar", "zap", "a" }); var res2 = _provider.PfAdd(cacheKey2, new List { "a", "b", "c", "foo" }); @@ -1613,9 +1613,9 @@ protected virtual void PfMerge_Should_Succeed() [Fact] protected virtual async Task PfMergeAsync_Should_Succeed() { - var cacheKey0 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; - var cacheKey1 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; - var cacheKey2 = $"{_nameSpace}-{Guid.NewGuid().ToString()}"; + var cacheKey0 = $"{_nameSpace}-pfmergeasync-{Guid.NewGuid().ToString()}"; + var cacheKey1 = $"{_nameSpace}-pfmergeasync-{Guid.NewGuid().ToString()}"; + var cacheKey2 = $"{_nameSpace}-pfmergeasync-{Guid.NewGuid().ToString()}"; var res1 = await _provider.PfAddAsync(cacheKey1, new List { "foo", "bar", "zap", "a" }); var res2 = await _provider.PfAddAsync(cacheKey2, new List { "a", "b", "c", "foo" });