コード例 #1
0
        public async void TestBloomFilter()
        {
            var cacheKey = nameof(TestBloomFilter).ToLower();

            await _redisProvider.KeyDelAsync(cacheKey);

            await _redisProvider.BloomReserveAsync(cacheKey, 0.001, 10000000);

            var initValues = new List <string>();

            for (int index = 0; index < 100000; index++)
            {
                initValues.Add($"adnc{index}");
            }
            await _redisProvider.BloomAddAsync(cacheKey, initValues);

            var trueResult = await _redisProvider.BloomExistsAsync(cacheKey, "adnc100");

            Assert.True(trueResult);

            var falseResult = await _redisProvider.BloomExistsAsync(cacheKey, "adnc");

            Assert.False(falseResult);

            var values = new List <string>()
            {
                "adnc88888", "adnc78888", "adnc68888", "adnc58888"
            };
            var results = await _redisProvider.BloomExistsAsync(cacheKey, values);

            var trueLength = results.Where(x => x == true).Count();

            Assert.Equal(values.Count, trueLength);

            values = new List <string>()
            {
                "danc888889", "danc888888", "danc8888888", "danc8888889"
            };
            results = await _redisProvider.BloomExistsAsync(cacheKey, values);

            var falseLength = results.Where(x => x == false).Count();

            Assert.Equal(values.Count, falseLength);
        }