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


C# RedisClient类代码示例

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


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


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