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.