Simple use of the Redis client ServiceStack. Redis,

Source: Internet
Author: User

Simple use of the Redis client ServiceStack. Redis,

Download ServiceStack. Redis in nuget, but a problem occurs after running:

Exception: An Exception is thrown when the "Com. JinYiWei. Cache. RedisHelper" type initial value is set.
System. TypeInitializationException: "Com. JinYiWei. Cache. RedisHelper" type Initial Value Setting item causes an exception. ---> System. typeLoadException: assembly "ServiceStack. redis, Version = 3.9.71.0, Culture = neutral, PublicKeyToken = null "type" ServiceStack. redis. the RedisNativeClient method "get_Db" is not implemented.

I checked the original version. My solution is as follows:
Modify the versions of several important dll files:
<Package id = "ServiceStack. Common" version = "3.9.71" targetFramework = "net45"/>
<Package id = "ServiceStack. Redis" version = "3.9.71" targetFramework = "net45"/>
<Package id = "ServiceStack. Text" version = "3.9.11" targetFramework = "net45"/>

If it is not easy to download, use the nuget command:
Install-Package ServiceStack. Common-Version 3.9.71

The code is as follows:

Using (RedisClient redisClient = new RedisClient ("123.207.96.138", 6379) {string str = "second"; bool IsSet = false; if (IsSet = redisClient. set <string> ("second", "www.cjjjs.com") {string getMessage = redisClient. get <string> (str); Console. writeLine (getMessage);} else {Console. writeLine ("redis failed to type the key value... ");} Console. read ();}

However, you must note that when using the Set function, you can use Get <string> to obtain the function, and Set <string> to Set the function, I have started to use Set, so that I cannot get the value. This is worth noting.

I tried to deploy two websites on two different sites and use redis to store data. This is indeed a bit like using a database for storage, however, nosql databases such as redis are more efficient. I originally used redis to store sessions, but it failed in cross-domain aspect !!! If you try either of the two implementations, refer to the following:
[Beginner's note] Using Redis as a cache service in the. Net Project

Session final in Distributed Redis
And my blog:
Asp.net distributed discussion on Session sharing

Well, for future research, the opposite is that cross-origin is a failure.

Ah, the dormitory is very annoying and noisy. I have no idea how to write code or write a blog. The Library has no electricity !!! This is worse than the school, without the campus network, and the library has no electricity from time to time.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.