Download the Windows version of redis, which contains 32-bit and 64-bit folders and other files. copy the files in the directory of 32-bit or 64-bit to D: \ redisfolder according to the system. Then, run the command to access the file and execute redis-server.exe redis. conf starts the server.
If the following content appears, and the server starts successfully: (Note that the CMD window of the server cannot be closed. Once the service is closed, it stops)
D: \ redis> redis-server.exe redis. conf
[9340] 09 Dec 22:13:37 * server started, redis version 2.4.2
[9340] 09 Dec 22:13:37 * dB loaded from disk: 0 seconds
[9340] 09 Dec 22:13:37 * the server is now ready to accept connections on port 6
379
Start the client in the CMD command window.
D: \ redis> redis-cli.exe-H 127.0.0.1-P 6379
Redis 127.0.0.1: 6379> set PWD 123456
OK
Redis 127.0.0.1: 6379> get PWD
"123456"
Redis 127.0.0.1: 6379>
Installation is successful everywhere.
Then, download the client and reference the four DLL files to the project.
Servicestack. Text. dll/servicestack. redis. dll/servicestack. interfaces/servicestack. Common. dll
Add a namespace in the project to reference using servicestack. redis;
You can use redis in the project.
Use 1
Redisclient redis = new redisclient ("127.0.0.1", 6379); // connect to the server
Userinfo user = new userinfo {username = "why", age = 111, id = 222 };
Redis. Set <userinfo> ("test", user); // sets the cache
Userinfo getu = redis. Get <userinfo> ("test"); // obtain the cache.
Use 2
Public static pooledredisclientmanager createmanager (string [] readwritehosts, string [] readonlyhosts)
{< br> // supports read/write splitting, load Balancing
return New pooledredisclientmanager (readwritehosts, readonlyhosts, new redisclientmanagerconfig
{< br> maxwritepoolsize = 5, // number of "write" link pool Links
maxreadpoolsize = 5, // number of "write" link pool Links
autostart = true,
});
}
// Read/write Splitting:
Pooledredisclientmanager prcm = createmanager (New String [] {"127.0.0.1: 6379"}, new string [] {"127.0.0.1: 6379 "});
Using (iredisclient redis2 = prcm. getclient ())
{
Redis2.set ("userinfolist", userinfolist );
List <userinfo> userlist = redis2.get <list <userinfo> ("userinfolist ");
Response. Write (userlist [1]. username +
Userlist [0]. username );
}