• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# RedisClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: ValidateTransfer

        public string ValidateTransfer(string sourceAppId, string userId, string transferId, string transferToken)
        {
            var red = new RedisClient<string>();
            var result = red.Get("transfertoken:" + transferId);
            if (!string.IsNullOrEmpty(result))
            {
                var redResult = red.Del("transfertoken:" + transferId);

                var redapp = new RedisClient<AppRegistry>();
                redapp.Select(1);
                var app = redapp.Get(HttpContext.Current.Items["AppId"] as string);

                var str = "UserId=" + userId + "&TransferId=" + transferId + "&Salt=" + app.AppSecret ;
                str = Hash.GetHash(str, Hash.HashType.SHA256);

                if (transferToken != str)
                {
                    throw new FaultException<UnauthorizedAccessException>(new UnauthorizedAccessException("token yanlış"));
                }

                string sessionguid = Guid.NewGuid().ToString();
                var redis = new RedisClient<Common.SessionRegistry>();
                var appId = HttpContext.Current.Items["AppId"] as string;
                redis.Set(sessionguid, new SessionRegistry() { SessionCookie = sessionguid, AppId = appId, UserId = userId });
                return sessionguid;
            }
            return null;
        }
开发者ID:endulus,项目名称:oynamalar,代码行数:28,代码来源:AuthService.svc.cs


示例3: OnTestFixtureSetUp

		public void OnTestFixtureSetUp()
		{
			using (var redisClient = new RedisClient(TestConfig.SingleHost))
			{
				redisClient.FlushAll();
			}
		}
开发者ID:modulexcite,项目名称:ServiceStack.Redis,代码行数:7,代码来源:SimpleLocks.cs


示例4: Does_retry_failed_commands_auth

        public void Does_retry_failed_commands_auth()
        {
            // -> Redis must have "requirepass testpassword" in config
            var connstr = "[email protected]";
            RedisStats.Reset();

            var redisCtrl = new RedisClient(connstr); //RedisConfig.DefaultHost
            redisCtrl.FlushAll();
            redisCtrl.SetClient("redisCtrl");

            var redis = new RedisClient(connstr);
            redis.SetClient("redisRetry");

            var clientInfo = redisCtrl.GetClientsInfo();
            var redisId = clientInfo.First(m => m["name"] == "redisRetry")["id"];
            Assert.That(redisId.Length, Is.GreaterThan(0));

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

            redis.OnBeforeFlush = () =>
            {
                redisCtrl.KillClients(withId: redisId);
            };

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(2));
            Assert.That(redis.Get<int>("retryCounter"), Is.EqualTo(2));

            Assert.That(RedisStats.TotalRetryCount, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(0));
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Redis,代码行数:31,代码来源:AuthIssue.cs


示例5: Working_with_int_values

		public void Working_with_int_values()
		{
			const string intKey = "intkey";
			const int intValue = 1;

			//STORING AN INT USING THE BASIC CLIENT
			using (var redisClient = new RedisClient(TestConfig.SingleHost))
			{
				redisClient.SetEntry(intKey, intValue.ToString());
				string strGetIntValue = redisClient.GetValue(intKey);
				int toIntValue = int.Parse(strGetIntValue);

				Assert.That(toIntValue, Is.EqualTo(intValue));
			}

			//STORING AN INT USING THE GENERIC CLIENT
			using (var redisClient = new RedisClient(TestConfig.SingleHost))
			{
				//Create a generic client that treats all values as ints:
				IRedisTypedClient<int> intRedis = redisClient.GetTypedClient<int>();

				intRedis.SetEntry(intKey, intValue);
				var toIntValue = intRedis.GetValue(intKey);

				Assert.That(toIntValue, Is.EqualTo(intValue));
			}
		}
开发者ID:nataren,项目名称:NServiceKit.Redis,代码行数:27,代码来源:ValueTypeExamples.cs


示例6: OnBeforeEachTest

		public virtual void OnBeforeEachTest()
		{
			if (Redis != null) Redis.Dispose();
			Redis = new RedisClient(TestConfig.SingleHost);
			Redis.FlushDb();
			RedisTyped = Redis.As<CacheRecord>();
		}
开发者ID:Chevkio,项目名称:ServiceStack.Redis,代码行数:7,代码来源:RedisTypedClientTests.cs


示例7: Send

 public void Send(TransportMessage message, Address address)
 {
    using(var redisClient = new RedisClient())
    {
        redisClient.Add(string.Format("{0}:{1}", address.Machine, address.Queue), message);
    }
 }
开发者ID:kstenson,项目名称:NServicebus.Redis,代码行数:7,代码来源:RedisQueue.cs


示例8: UseClient

		private static void UseClient(RedisClient client, int clientNo)
		{
			var host = "";

			try
			{
				host = client.Host;

				Log("Client '{0}' is using '{1}'", clientNo, client.Host);

				var testClientKey = "test:" + host + ":" + clientNo;
				client.SetEntry(testClientKey, testData);
				var result = client.GetValue(testClientKey) ?? "";

				Log("\t{0} => {1} len {2} {3} len", testClientKey,
					testData.Length, testData.Length == result.Length ? "==" : "!=", result.Length);

			}
			catch (NullReferenceException ex)
			{
				Console.WriteLine("NullReferenceException StackTrace: \n" + ex.StackTrace);
			}
			catch (Exception ex)
			{
				Console.WriteLine("\t[[email protected]{0}]: {1} => {2}",
					host, ex.GetType().Name, ex.Message);
			}
		}
开发者ID:nuxleus,项目名称:ServiceStack.Redis,代码行数:28,代码来源:MultiThreadedRedisClientIntegrationTests.cs


示例9: Can_support_64_threads_using_the_client_simultaneously

        public void Can_support_64_threads_using_the_client_simultaneously()
        {
            var before = Stopwatch.GetTimestamp();

            const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64

#if NETCORE
            List<Task> tasks = new List<Task>();
#else
            var clientAsyncResults = new List<IAsyncResult>();
#endif             
            using (var redisClient = new RedisClient(TestConfig.SingleHost))
            {
                for (var i = 0; i < noOfConcurrentClients; i++)
                {
                    var clientNo = i;
                    var action = (Action)(() => UseClientAsync(redisClient, clientNo));
#if NETCORE
                    tasks.Add(Task.Run(action));
#else                                       
                    clientAsyncResults.Add(action.BeginInvoke(null, null));
#endif
                }
            }
#if NETCORE
            Task.WaitAll(tasks.ToArray());
#else            
            WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());
#endif
            Debug.WriteLine(String.Format("Time Taken: {0}", (Stopwatch.GetTimestamp() - before) / 1000));
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Redis,代码行数:31,代码来源:MultiThreadedRedisClientIntegrationTests.cs


示例10: CreateClient

 private IRedisClient CreateClient(bool flushAll = true)
 {
     var client = new RedisClient(6379);
     if(flushAll)
         client.FlushAll();
     return client;
 }
开发者ID:glorylee,项目名称:Aoite,代码行数:7,代码来源:RedisStreamTests.cs


示例11: Connect

 public void Connect()
 {
     // note: defaults to 127.0.0.1:6379
     using(dynamic client = new RedisClient())
     {
     }
 }
开发者ID:DovydasNavickas,项目名称:simple-redis,代码行数:7,代码来源:BasicTests.cs


示例12: Allows_access_of_6000_operations

 public void Allows_access_of_6000_operations()
 {
     using (var client = new RedisClient(TestConfig.SingleHost))
     {
         6000.Times(() => client.Get("any key"));
     }
 }
开发者ID:CatomStudio,项目名称:ServiceStack.Redis,代码行数:7,代码来源:LicenseUsageTests.cs


示例13: Save

 public void Save(EngineInfo info)
 {
     var client = new RedisClient();
     var key = new EngineKeys ().GetInfoKey (info.Id);
     var json = info.ToJson ();
     client.Set(key, json);
 }
开发者ID:CompulsiveCoder,项目名称:TileSim,代码行数:7,代码来源:EngineInfoSaver.cs


示例14: RedisCacheService

        static RedisCacheService()
        {
            Redis = new RedisClient("localhost");
            string ping = Redis.Ping();

            JsConfig.DateHandler = DateHandler.ISO8601;
        }
开发者ID:pavelsavara,项目名称:marias,代码行数:7,代码来源:RedisCacheService.cs


示例15: CreateServer

        RedisMqServer CreateServer()
        {
            using (var redis = new RedisClient())
                redis.FlushAll();

            var mqServer = new RedisMqServer(new BasicRedisClientManager());
            mqServer.RegisterHandler<Spin0>(m => new Spin0 { Id = counter.Spin0++ });

            mqServer.RegisterHandler<Spin10>(m => {
                var sw = Stopwatch.StartNew();
                while (sw.ElapsedMilliseconds < 10) Thread.SpinWait(100000);
                return new Spin10 { Id = counter.Spin10++ };
            });
            mqServer.RegisterHandler<Spin100>(m => {
                var sw = Stopwatch.StartNew();
                while (sw.ElapsedMilliseconds < 100) Thread.SpinWait(100000);
                return new Spin100 { Id = counter.Spin100++ };
            });
            mqServer.RegisterHandler<Spin1000>(m => {
                var sw = Stopwatch.StartNew();
                while (sw.ElapsedMilliseconds < 1000) Thread.SpinWait(100000);
                return new Spin1000 { Id = counter.Spin1000++ };
            });


            return mqServer;
        }
开发者ID:adam-26,项目名称:ServiceStack.Redis,代码行数:27,代码来源:RedisMqServerSpinServerTests.cs


示例16: UseClientAsync

 private void UseClientAsync(RedisClient client, int clientNo)
 {
     lock (this)
     {
         UseClient(client, clientNo);
     }
 }
开发者ID:ServiceStack,项目名称:ServiceStack.Redis,代码行数:7,代码来源:MultiThreadedRedisClientIntegrationTests.cs


示例17: Run

        public override void Run()
        {
            var client = new RedisClient<int>(RedisSettings.Default);

              // NOTE: This is for demonstartion purpose only
              //       real-world code should just use MGet and MSet which are made
              //       specifically for tasks like this

              // initialize 1000 counters with a number
              var success = client
            .Pipeline(c =>
            {
              var rand = new Random();
              for (var i = 0; i < CounterAmount; i++)
            c.Set("counter" + i.ToString(), rand.Next(100, 999));
            })
            .Cast<bool>()
            .All(b => b);

              WriteLine(success ?
            "All counters set to [100,999]." :
            "Unable to set some counters");

              var verified = client
            .Pipeline(c => Enumerable
              .Range(0, 1000)
              .Select(n => c.Get("counter" + n.ToString()))
              .AsEnumerable())
            .Cast<int>()
            .All(n => n >= 100 && n < 1000);

              WriteLine(verified ?
            "Counter values verified." :
            "Some counters are invalid.");
        }
开发者ID:johanhelsing,项目名称:sider,代码行数:35,代码来源:LinqPipelineSample.cs


示例18: TestSendAndReceive

        public async void TestSendAndReceive()
        {
            var resolver = new DependencyResolver();

            using (var server = new RedisServer(new RedisConnection(RedisHost, RedisPort, RedisPassword), ServerQueue, new ServiceFactory(resolver)))
            {
                server.Listen();

                using (var client = new RedisClient(new RedisConnection(RedisHost, RedisPort, RedisPassword), ClientQueue, ServerQueue))
                {
                    var clientFactory = new ServiceProxy.ServiceClientFactory(client);

                    var serviceClient = clientFactory.CreateServiceClient<ITestService2>();

                    Assert.That(serviceClient.GetPerson(1), Is.Not.Null);

                    var persons = await serviceClient.ListPersonsAsync(5);
                    Assert.That(persons, Is.Not.Null);
                    Assert.AreEqual(5, persons.Count());

                    var nullCollection = await serviceClient.ListPersonsAsync(-1);
                    Assert.IsNull(nullCollection);

                    var nullObject = serviceClient.GetPerson(-1);
                    Assert.IsNull(nullObject);
                }
            }
        }
开发者ID:yonglehou,项目名称:ServiceProxy,代码行数:28,代码来源:RedisClientAndServerTests.cs


示例19: OnBeforeEachTest

		public virtual void OnBeforeEachTest()
		{
			if (Redis != null) Redis.Dispose();
			Redis = new RedisClient(TestConfig.SingleHost);
		    Redis.NamespacePrefix = "RedisTypedClientTests:";
			RedisTyped = Redis.As<CacheRecord>();
		}
开发者ID:nprasad,项目名称:ServiceStack.Redis,代码行数:7,代码来源:RedisTypedClientTests.cs


示例20: ClientKillTest

        public void ClientKillTest()
        {
            var reply1 = "+OK\r\n";
            var reply2 = ":1\r\n";
            using (var mock = new FakeRedisSocket(reply1, reply2, reply2, reply2, reply2, reply2))
            using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
            {
                Assert.AreEqual("OK", redis.ClientKill("1.1.1.1", 9999));
                Assert.AreEqual("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$7\r\n1.1.1.1\r\n$4\r\n9999\r\n", mock.GetMessage());

                Assert.AreEqual(1, redis.ClientKill(addr: "1.1.1.1:9999"));
                Assert.AreEqual("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$4\r\nADDR\r\n$12\r\n1.1.1.1:9999\r\n", mock.GetMessage());

                Assert.AreEqual(1, redis.ClientKill(id: "123"));
                Assert.AreEqual("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$2\r\nID\r\n$3\r\n123\r\n", mock.GetMessage());

                Assert.AreEqual(1, redis.ClientKill(type: "normal"));
                Assert.AreEqual("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$4\r\nTYPE\r\n$6\r\nnormal\r\n", mock.GetMessage());

                Assert.AreEqual(1, redis.ClientKill(skipMe: true));
                Assert.AreEqual("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$6\r\nSKIPME\r\n$3\r\nyes\r\n", mock.GetMessage());

                Assert.AreEqual(1, redis.ClientKill(skipMe: false));
                Assert.AreEqual("*4\r\n$6\r\nCLIENT\r\n$4\r\nKILL\r\n$6\r\nSKIPME\r\n$2\r\nno\r\n", mock.GetMessage());
            }
        }
开发者ID:DTBruce,项目名称:csredis,代码行数:26,代码来源:ServerTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RedisKey类代码示例发布时间:2022-05-24
下一篇:
C# Reddit类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap