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


C# RedisClient.As方法代码示例

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


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

示例1: 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.As<int>();

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

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

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

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

示例4: Can_Retrieve_DomainEvents

        public void Can_Retrieve_DomainEvents()
        {
            var userId = Guid.NewGuid();
            var client = new RedisClient(TestConfig.SingleHost);
            client.FlushAll();

            client.As<DomainEvent>().Lists["urn:domainevents-" + userId].Add(new UserPromotedEvent { UserId = userId });


            var users = client.As<DomainEvent>().Lists["urn:domainevents-" + userId];

            Assert.That(users.Count, Is.EqualTo(1));

            var userPromoEvent = (UserPromotedEvent)users[0];
            Assert.That(userPromoEvent.UserId, Is.EqualTo(userId));
        }
开发者ID:Eddie0330,项目名称:ServiceStack.Redis,代码行数:16,代码来源:DomainEventsTests.cs

示例5: Allows_access_of_more_than_21_types

        public void Allows_access_of_more_than_21_types()
        {
            using (var client = new RedisClient(TestConfig.SingleHost))
            {
                Access20Types();
                Access20Types();

                client.As<T21>();
                Assert.Pass();

                client.As<T22>();
                Assert.Pass();

                client.As<T23>();
                Assert.Pass();

                client.As<T24>();
                Assert.Pass();
            }
        }
开发者ID:darting,项目名称:FreeStack.Redis,代码行数:20,代码来源:LicenseUsageTests.cs

示例6: Receive

 public TransportMessage Receive()
 {
     using (var redisClient = new RedisClient())
     {
        
             var redis = redisClient.As<TransportMessage>();
             var message = redis.GetValue(string.Format("{0}:{1}", _address.Machine, _address.Queue));
             return message;
         
     }
 }
开发者ID:kstenson,项目名称:NServicebus.Redis,代码行数:11,代码来源:RedisQueue.cs

示例7: Throws_on_access_of_21_types

        public void Throws_on_access_of_21_types()
        {
            using (var client = new RedisClient(TestConfig.SingleHost))
            {
                Access20Types();
                Access20Types();

                Assert.Throws<LicenseException>(() =>
                    client.As<T21>());
            }
        }
开发者ID:CatomStudio,项目名称:ServiceStack.Redis,代码行数:11,代码来源:LicenseUsageTests.cs

示例8: Allows_access_of_21_types

        public void Allows_access_of_21_types()
        {
            Licensing.RegisterLicense(new AppSettings().GetString("servicestack:license"));

            using (var client = new RedisClient(TestConfig.SingleHost))
            {
                Access20Types();
                Access20Types();

                client.As<T21>();
            }
        }
开发者ID:CatomStudio,项目名称:ServiceStack.Redis,代码行数:12,代码来源:LicenseUsageTests.cs

示例9: SetUp

        public void SetUp()
        {
            if (client != null)
            {
                client.Dispose();
                client = null;
            }
            client = new RedisClient(TestConfig.SingleHost);
            client.FlushAll();

            redis = client.As<CustomType>();

            List = redis.Lists[ListId];
            List2 = redis.Lists[ListId2];
        }
开发者ID:JackBao,项目名称:ServiceStack.Redis,代码行数:15,代码来源:RedisClientListTestExtra.cs

示例10: Can_from_Retrieve_DomainEvents_list

        public void Can_from_Retrieve_DomainEvents_list()
        {
            var client = new RedisClient(TestConfig.SingleHost);
            var users = client.As<AggregateEvents>();

            var userId = Guid.NewGuid();

            var eventsForUser = new AggregateEvents
            {
                Id = userId,
                Events = new List<DomainEvent>()
            };

            eventsForUser.Events.Add(new UserPromotedEvent { UserId = userId });

            users.Store(eventsForUser);

            var all = users.GetAll(); 
        }
开发者ID:Eddie0330,项目名称:ServiceStack.Redis,代码行数:19,代码来源:DomainEventsTests.cs

示例11: Working_with_int_list_values

        public void Working_with_int_list_values()
        {
            const string intListKey = "intListKey";
            var intValues = new List<int> { 2, 4, 6, 8 };

            //STORING INTS INTO A LIST USING THE BASIC CLIENT
            using (var redisClient = new RedisClient(TestConfig.SingleHost))
            {
                IList<string> strList = redisClient.Lists[intListKey];

                //storing all int values in the redis list 'intListKey' as strings
                intValues.ForEach(x => strList.Add(x.ToString()));

                //retrieve all values again as strings
                List<string> strListValues = strList.ToList();

                //convert back to list of ints
                List<int> toIntValues = strListValues.ConvertAll(x => int.Parse(x));

                Assert.That(toIntValues, Is.EqualTo(intValues));

                //delete all items in the list
                strList.Clear();
            }

            //STORING INTS INTO A LIST 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.As<int>();

                IRedisList<int> intList = intRedis.Lists[intListKey];

                //storing all int values in the redis list 'intListKey' as ints
                intValues.ForEach(x => intList.Add(x));

                List<int> toIntListValues = intList.ToList();

                Assert.That(toIntListValues, Is.EqualTo(intValues));
            }
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Redis,代码行数:41,代码来源:ValueTypeExamples.cs

示例12: Access20Types

 protected void Access20Types()
 {
     using (var client = new RedisClient(TestConfig.SingleHost))
     {
         client.As<T01>();
         client.As<T02>();
         client.As<T03>();
         client.As<T04>();
         client.As<T05>();
         client.As<T06>();
         client.As<T07>();
         client.As<T08>();
         client.As<T09>();
         client.As<T10>();
         client.As<T11>();
         client.As<T12>();
         client.As<T13>();
         client.As<T14>();
         client.As<T15>();
         client.As<T16>();
         client.As<T17>();
         client.As<T18>();
         client.As<T19>();
         client.As<T20>();
     }
 }
开发者ID:darting,项目名称:FreeStack.Redis,代码行数:26,代码来源:LicenseUsageTests.cs

示例13: Working_with_Generic_types

        public void Working_with_Generic_types()
        {
            using (var redisClient = new RedisClient(TestConfig.SingleHost))
            {
                //Create a typed Redis client that treats all values as IntAndString:
                var typedRedis = redisClient.As<IntAndString>();

                var pocoValue = new IntAndString { Id = 1, Letter = "A" };
                typedRedis.SetEntry("pocoKey", pocoValue);
                IntAndString toPocoValue = typedRedis.GetValue("pocoKey");

                Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
                Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));

                var pocoListValues = new List<IntAndString> {
                    new IntAndString {Id = 2, Letter = "B"},
                    new IntAndString {Id = 3, Letter = "C"},
                    new IntAndString {Id = 4, Letter = "D"},
                    new IntAndString {Id = 5, Letter = "E"},
                };

                IRedisList<IntAndString> pocoList = typedRedis.Lists["pocoListKey"];

                //Adding all IntAndString objects into the redis list 'pocoListKey'
                pocoListValues.ForEach(x => pocoList.Add(x));

                List<IntAndString> toPocoListValues = pocoList.ToList();

                for (var i = 0; i < pocoListValues.Count; i++)
                {
                    pocoValue = pocoListValues[i];
                    toPocoValue = toPocoListValues[i];
                    Assert.That(toPocoValue.Id, Is.EqualTo(pocoValue.Id));
                    Assert.That(toPocoValue.Letter, Is.EqualTo(pocoValue.Letter));
                }
            }
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Redis,代码行数:37,代码来源:ValueTypeExamples.cs

示例14: Allows_access_of_21_types

        public void Allows_access_of_21_types()
        {
#if NETCORE
            Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");
#else
            Licensing.RegisterLicense(new AppSettings().GetString("servicestack:license"));
#endif

            using (var client = new RedisClient(TestConfig.SingleHost))
            {
                Access20Types();
                Access20Types();

                client.As<T21>();
            }
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Redis,代码行数:16,代码来源:LicenseUsageTests.cs


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