public void Can_The_Batch_Result()
        {
            var    operate = new RedisBitOperate(ConfigurationOptions.Parse("localhost"));
            string key     = "RB:Batch";

            operate.Clear(key);

            var positions = new int[] { 5, 6, 7, 8, 9, 10, 11, 12 };

            var results = operate.Set(key, positions, true);

            Assert.False(results.All(r => r));

            results = operate.Set(key, positions, true);
            Assert.True(results.All(r => r));

            results = operate.Get(key, positions);
            Assert.True(results.All(r => r));

            operate.Clear(key);
            results = operate.Get(key, positions);
            Assert.False(results.All(r => r));

            operate.Dispose();
        }
        public async Task NormalTestAsync()
        {
            var operate = new RedisBitOperate("localhost");
            await operate.SetAsync("RB-NormalTestAsync", 0, true);

            Assert.True(await operate.GetAsync("RB-NormalTestAsync", 0));
            operate.Dispose();
        }
        public void NormalTest()
        {
            var operate = new RedisBitOperate("localhost");

            operate.Set("RB-NormalTest", 0, true);
            Assert.True(operate.Get("RB-NormalTest", 0));
            operate.Dispose();
        }
        public async Task Can_Close_With_New_ConnectionAsync()
        {
            var conn = ConnectionMultiplexer.Connect("localhost");

            Assert.True(conn.IsConnected);
            conn.Dispose();
            Assert.False(conn.IsConnected);

            var operate = new RedisBitOperate(conn);
            await operate.SetAsync("Can_Close_With_New_ConnectionAsync", 2, true);

            Assert.True(await operate.GetAsync("Can_Close_With_New_ConnectionAsync", 2));
            operate.Dispose();
        }
        public void Can_Close_With_New_Connection()
        {
            var conn = ConnectionMultiplexer.Connect("localhost");

            Assert.True(conn.IsConnected);
            conn.Dispose();
            Assert.False(conn.IsConnected);

            var operate = new RedisBitOperate(conn);

            operate.Set("Can_Close_With_New_Connection", 2, true);
            Assert.True(operate.Get("Can_Close_With_New_Connection", 2));
            operate.Dispose();
        }
        public async Task Can_Connection_Has_Not_CloseAsync()
        {
            var conn = ConnectionMultiplexer.Connect("localhost");

            Assert.True(conn.IsConnected);

            var operate = new RedisBitOperate(conn);
            await operate.SetAsync("Can_Connection_Has_Not_CloseAsync", 1, true);

            Assert.True(await operate.GetAsync("Can_Connection_Has_Not_CloseAsync", 1));
            operate.Dispose();

            Assert.True(conn.IsConnected);
        }
        public void Can_Connection_Has_Not_Close()
        {
            var conn = ConnectionMultiplexer.Connect("localhost");

            Assert.True(conn.IsConnected);

            var operate = new RedisBitOperate(conn);

            operate.Set("Can_Connection_Has_Not_Close", 1, true);
            Assert.True(operate.Get("Can_Connection_Has_Not_Close", 1));
            operate.Dispose();

            Assert.True(conn.IsConnected);
        }
Пример #8
0
        public void AddServices(IServiceCollection services)
        {
            services.TryAddSingleton <IBloomFilterFactory, DefaultBloomFilterFactory>();

            services.AddSingleton <IBloomFilter, FilterRedis>(x =>
            {
                IRedisBitOperate redisBitOperate;

                if (_options.Connection != null)
                {
                    redisBitOperate = new RedisBitOperate(_options.Connection);
                }
                else if (!string.IsNullOrWhiteSpace(_options.Configuration))
                {
                    redisBitOperate = new RedisBitOperate(_options.Configuration);
                }
                else
                {
                    var configurationOptions = new ConfigurationOptions
                    {
                        ConnectTimeout     = _options.ConnectionTimeout,
                        User               = _options.Username,
                        Password           = _options.Password,
                        Ssl                = _options.IsSsl,
                        SslHost            = _options.SslHost,
                        AllowAdmin         = _options.AllowAdmin,
                        DefaultDatabase    = _options.Database,
                        AbortOnConnectFail = _options.AbortOnConnectFail,
                    };

                    foreach (var endpoint in _options.Endpoints)
                    {
                        configurationOptions.EndPoints.Add(endpoint);
                    }

                    redisBitOperate = new RedisBitOperate(configurationOptions);
                }

                return(new FilterRedis(
                           _options.Name,
                           redisBitOperate,
                           _options.RedisKey,
                           _options.ExpectedElements,
                           _options.ErrorRate,
                           HashFunction.Functions[_options.Method]));
            });
        }
        public void BuildTest()
        {
            var hashFun = new HashAlgorithms.HashCryptoMD5();
            var config  = ConfigurationOptions.Parse("localhost");
            var conn    = ConnectionMultiplexer.Connect(config);
            var operate = new RedisBitOperate(conn);

            buildTest(FilterRedisBuilder.Build <string>(config, "BuildTest", 10000));
            buildTest(FilterRedisBuilder.Build <string>(config, "BuildTest", 10000, hashFun));
            buildTest(FilterRedisBuilder.Build <string>(config, "BuildTest", 10000, HashMethod.Adler32));
            buildTest(FilterRedisBuilder.Build <string>(config, "BuildTest", 10000, 0.01));
            buildTest(FilterRedisBuilder.Build <string>(config, "BuildTest", 10000, 0.01, hashFun));
            buildTest(FilterRedisBuilder.Build <string>(config, "BuildTest", 10000, 0.01, HashMethod.Adler32));

            buildTest(FilterRedisBuilder.Build <string>("localhost", "BuildTest", 10000));
            buildTest(FilterRedisBuilder.Build <string>("localhost", "BuildTest", 10000, hashFun));
            buildTest(FilterRedisBuilder.Build <string>("localhost", "BuildTest", 10000, HashMethod.Adler32));
            buildTest(FilterRedisBuilder.Build <string>("localhost", "BuildTest", 10000, 0.01));
            buildTest(FilterRedisBuilder.Build <string>("localhost", "BuildTest", 10000, 0.01, hashFun));
            buildTest(FilterRedisBuilder.Build <string>("localhost", "BuildTest", 10000, 0.01, HashMethod.Adler32));

            buildTest(FilterRedisBuilder.Build <string>(conn, "BuildTest", 10000));
            buildTest(FilterRedisBuilder.Build <string>(conn, "BuildTest", 10000, hashFun));
            buildTest(FilterRedisBuilder.Build <string>(conn, "BuildTest", 10000, HashMethod.Adler32));
            buildTest(FilterRedisBuilder.Build <string>(conn, "BuildTest", 10000, 0.01));
            buildTest(FilterRedisBuilder.Build <string>(conn, "BuildTest", 10000, 0.01, hashFun));
            buildTest(FilterRedisBuilder.Build <string>(conn, "BuildTest", 10000, 0.01, HashMethod.Adler32));

            buildTest(FilterRedisBuilder.Build <string>(operate, "BuildTest", 10000));
            buildTest(FilterRedisBuilder.Build <string>(operate, "BuildTest", 10000, hashFun));
            buildTest(FilterRedisBuilder.Build <string>(operate, "BuildTest", 10000, HashMethod.Adler32));
            buildTest(FilterRedisBuilder.Build <string>(operate, "BuildTest", 10000, 0.01));
            buildTest(FilterRedisBuilder.Build <string>(operate, "BuildTest", 10000, 0.01, hashFun));
            buildTest(FilterRedisBuilder.Build <string>(operate, "BuildTest", 10000, 0.01, HashMethod.Adler32));


            conn.Dispose();
        }
        public async Task BuildTestAsync()
        {
            var hashFun = new HashAlgorithms.HashCryptoSHA256();
            var config  = ConfigurationOptions.Parse("localhost");
            var conn    = ConnectionMultiplexer.Connect(config);
            var operate = new RedisBitOperate(conn);

            await buildTestAsync(FilterRedisBuilder.Build(config, "BuildTest", 10000));
            await buildTestAsync(FilterRedisBuilder.Build(config, "BuildTest", 10000, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build(config, "BuildTest", 10000, HashMethod.Adler32));
            await buildTestAsync(FilterRedisBuilder.Build(config, "BuildTest", 10000, 0.01));
            await buildTestAsync(FilterRedisBuilder.Build(config, "BuildTest", 10000, 0.01, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build(config, "BuildTest", 10000, 0.01, HashMethod.Adler32));

            await buildTestAsync(FilterRedisBuilder.Build("localhost", "BuildTest", 10000));
            await buildTestAsync(FilterRedisBuilder.Build("localhost", "BuildTest", 10000, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build("localhost", "BuildTest", 10000, HashMethod.Adler32));
            await buildTestAsync(FilterRedisBuilder.Build("localhost", "BuildTest", 10000, 0.01));
            await buildTestAsync(FilterRedisBuilder.Build("localhost", "BuildTest", 10000, 0.01, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build("localhost", "BuildTest", 10000, 0.01, HashMethod.Adler32));

            await buildTestAsync(FilterRedisBuilder.Build(conn, "BuildTest", 10000));
            await buildTestAsync(FilterRedisBuilder.Build(conn, "BuildTest", 10000, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build(conn, "BuildTest", 10000, HashMethod.Adler32));
            await buildTestAsync(FilterRedisBuilder.Build(conn, "BuildTest", 10000, 0.01));
            await buildTestAsync(FilterRedisBuilder.Build(conn, "BuildTest", 10000, 0.01, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build(conn, "BuildTest", 10000, 0.01, HashMethod.Adler32));

            await buildTestAsync(FilterRedisBuilder.Build(operate, "BuildTest", 10000));
            await buildTestAsync(FilterRedisBuilder.Build(operate, "BuildTest", 10000, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build(operate, "BuildTest", 10000, HashMethod.Adler32));
            await buildTestAsync(FilterRedisBuilder.Build(operate, "BuildTest", 10000, 0.01));
            await buildTestAsync(FilterRedisBuilder.Build(operate, "BuildTest", 10000, 0.01, hashFun));
            await buildTestAsync(FilterRedisBuilder.Build(operate, "BuildTest", 10000, 0.01, HashMethod.Adler32));


            conn.Dispose();
        }