I searched a circle and found that I didn't fully and briefly describe how to use redis in the C # project. Most of them were fragmented articles and I organized them a little, I hope it will be helpful to anyone who wants to use redis.
Prerequisites
1. redis is an open source, BSD licensed, advanced key-Value Store, simply put, used to cache data, more information refer to the official website http://redis.io/, many large sites are using this, refer to the http://redis.io/topics/whos-using-redis.
2. redis is not directly supported on windows, so the Microsoft Open Tech team developed redis on windows, the latest version 2.8.9 can be used on the official website (the previous version may not be so stable ).
3. if you want to use in the C # project, you must also use the C # Write class library as the client, used to read and write data from redis, you can refer to the http://redis.io/clients, the components written by C # client are listed here. I chose the recommended servicestack. redis, which can be downloaded from the https://github.com/ServiceStack/ServiceStack.Redis or installed directly into your project via nuget, nuget command: Install-package servicestack. redis.
STEP (Assume that you have downloaded redis on Windows and installed the servicestack. redis component through nuget.)
1. In the downloaded redis on Windows project, find the bin directory, which contains redis-2.8.9.zip, and decompress it to a certain place.
2. Use Windows Command to enter the decompressed directory and runRedis-server -- service-installInstall the redis server as a window service to run the service. The default listening port of this service is 6379, and then start the service. (The simpler method is to directly open this directory and run redis-server.exe)
3. I used the console app for testing, so I have installed the servicestack. redis component for this console app through nuget. below is all the code.
using ServiceStack.Redis;
namespace ConsoleApplication1{ class Program { static void Main(string[] args) { var manage = new BasicRedisClientManager("localhost"); var client = manage.GetCacheClient(); client.Add("name", "dragon"); Console.WriteLine(client.Get<string>("name")); Console.Read(); } }}
Localhost indicates the address of the cache server you want to operate on. The default port is 6379. If you want to modify the port, you can modify it when installing redis service. command:Redis-server -- service-install -- Port 1001If you modify the port, change the localhost parameter to localhost: 1001 to display the specified port.
Redis supports multiple servers for Distributed caching.
Here is just a simple example. If you need to use it in a project, you need to have a deep understanding of many parameters and configurations.