当前位置: 首页>>代码示例>>C#>>正文


C# RedisClient.Auth方法代码示例

本文整理汇总了C#中RedisClient.Auth方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Auth方法的具体用法?C# RedisClient.Auth怎么用?C# RedisClient.Auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedisClient的用法示例。


在下文中一共展示了RedisClient.Auth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        private void Initialize()
        {
            try
            {
                // create the connection
                Client = new RedisClient(_config.Host, _config.Port)
                {
                    ReconnectAttempts = 3,
                    ReconnectTimeout = 200
                };

                // select the database
                Client.Select(_config.DatabaseId);

                // authenticate if needed.
                if (!string.IsNullOrEmpty(_config.Password))
                    Client.Auth(_config.Password);

                // check the version
                var version = GetVersion();
                if (version < _requiredMinimumVersion)
                    throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));

                _logger.Information("Redis storage initialized: {0:l}:{1}, v{2:l}.", _config.Host, _config.Port, version);
            }
            catch (Exception e)
            {
                _logger.Error("Redis storage initialization failed: {0:l}:{1} - {2:l}", _config.Host, _config.Port, e.Message);
            }
        }
开发者ID:carloslozano,项目名称:CoiniumServ,代码行数:30,代码来源:RedisProvider.cs

示例2: TestAuth

 public void TestAuth()
 {
     using (var redis = new RedisClient(Host, Port, 0))
     {
         Assert.AreEqual("OK", redis.Auth(Password));
     }
 }
开发者ID:richard-green,项目名称:csredis,代码行数:7,代码来源:RedisConnectionTests.cs

示例3: TestUnwatch

 public void TestUnwatch()
 {
     using (new RedisTestKeys(Redis, "test1"))
     {
         Redis.Watch("test1");
         Assert.AreEqual("OK", Redis.Unwatch());
         Redis.Multi();
         using (var otherClient = new RedisClient(Host, Port, 0))
         {
             otherClient.Auth(Password);
             otherClient.Set("test1", "other");
         }
         Redis.Set("test1", "multi");
         Assert.IsNotNull(Redis.Exec());
     }
 }
开发者ID:richard-green,项目名称:csredis,代码行数:16,代码来源:RedisTransactionTests.cs

示例4: TestSubscribe

        public void TestSubscribe()
        {
            int change_count = 0;
            int message_count = 0;
            string last_message = String.Empty;

            using (var redisConsumer = new RedisClient(Host, Port, 0))
            using (var redisPublisher = new RedisClient(Host, Port, 0))
            {
                redisConsumer.Auth(Password);
                redisPublisher.Auth(Password);

                redisConsumer.SubscriptionReceived += (o, e) =>
                {
                    message_count++;
                    last_message = e.Message.Body;
                };
                redisConsumer.SubscriptionChanged += (o, e) =>
                {
                    change_count++;
                };
                Task consumer_task = Task.Factory.StartNew(() =>
                {
                    redisConsumer.Subscribe("test");
                });
                while (change_count != 1) // wait for subscribe
                    Thread.Sleep(10);

                Assert.AreEqual(1, redisPublisher.Publish("test", "hello world"), "First publish");
                Assert.AreEqual(0, redisPublisher.Publish("junk", "nothing"), "Junk publish");
                Assert.AreEqual(1, redisPublisher.Publish("test", "hello again"), "Second publish");
                redisConsumer.Subscribe("test2");
                while (change_count != 2) // wait for subscribe
                    Thread.Sleep(10);
                Assert.AreEqual(1, redisPublisher.Publish("test2", "a new channel"), "New channel publish");

                redisConsumer.Unsubscribe("test");
                redisConsumer.Unsubscribe();
                consumer_task.Wait();

                Assert.AreEqual(3, message_count);
                Assert.AreEqual(4, change_count);
                Assert.AreEqual("a new channel", last_message);
            }
        }
开发者ID:richard-green,项目名称:csredis,代码行数:45,代码来源:RedisPubSubTests.cs

示例5: Initialize

        public void Initialize()
        {
            Host = ConfigurationManager.AppSettings["host"];
            Port = Int32.Parse(ConfigurationManager.AppSettings["port"]);
            Password = ConfigurationManager.AppSettings["password"];

            _redis = new Lazy<RedisClient>(() =>
            {
                RedisClient redis = new RedisClient(Host, Port, 0);
                redis.Auth(Password);
                return redis;
            });

            _async = new Lazy<RedisClientAsync>(() =>
            {
                RedisClientAsync async = new RedisClientAsync(Host, Port, 0);
                async.Auth(Password).Wait();
                return async;
            });
        }
开发者ID:richard-green,项目名称:csredis,代码行数:20,代码来源:RedisTestBase.cs


注:本文中的RedisClient.Auth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。