Redis simple local test

Source: Internet
Author: User
Tags redis version

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 );
}

 

 

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.