The so-called distributed redis

Source: Internet
Author: User
Tags download redis

 

During daily development, there will always be some interesting things, such as redis. When it comes to redis, someone may have compared it with memcache,

Memcache can only be said to be a simple kv memory data structure, while redis supports a wide range of data types, of course, SortedSet is the most eye-catching.

With it, we can play with some "greedy" problems, such as priority queues suitable for "greedy". When it comes to priority queues, we previously implemented only in the memory format,

Well, the memory is memory after all. When there is a large amount of data, it is better to serialize it to the hard disk... This is exactly what redis can do in this scenario...

I. Quick Building

Well, we know what redis is suitable for. Now we can build it quickly.

Step 1: Download redis-2.0.2.zip (32 bit ). Then change the name to redis and put it on disk D.

 

The most important thing is the following two:

Redis-server.exe: This is the redis server program.

Redis-cli.exe: After the server is turned on, our client can enter a variety of commands to test.

We can see two points:

①: Config file is not specified.

It turns out that we recommend that you create a configuration file for redis, so I will implement Segment configuration.

Daemonize: whether to enable daemonize in daemonize mode. When daemonize A daemonize process, it is not affected by the console.

Logfile: Location of the log file.

Database: Number of enabled databases.

Dbfilename: Data snapshot file name.

Save **: the snapshot retention frequency. The first is the time, and the second is the write operation.

After configuring these settings, let's take a look:

②: We can see that the default open port of redis is 6379.

 

Ii. Install the driver

Now that redis has been set up, we need to use C # To operate redis. This is also my favorite function. queue-first ~, Download the C # driver first,

You can see the following three dll files.

Finally, let's perform a small test:

1 class Program 2 {3 static void Main (string [] args) 4 {5 var client = new RedisClient ("Wagner. 0.0.1", 6379 ); 6 7 // The last parameter is based on 8 var s = client. addItemToSortedSet ("12", "Baidu", 400); 9 10 client. addItemToSortedSet ("12", "Google", 300); 11 client. addItemToSortedSet ("12", "Alibaba", 200); 12 client. addItemToSortedSet ("12", "Sina", 100); 13 client. addItemToSortedSet ("12", "everybody", 500); 14 15 // obtain the most value in ascending order: "Sina" 16 var list = client. getRangeFromSortedSet ("12", 0, 0); 17 18 foreach (var item in list) 19 {20 Console. writeLine (item); 21} 22 23 // get the most value in descending order: "Renren" 24 list = client. getRangeFromSortedSetDesc ("12", 0, 0); 25 26 foreach (var item in list) 27 {28 Console. writeLine (item); 29} 30 31 Console. read (); 32} 33}

AddItemToSortedSet: The third parameter is the basis for sorting. This is also very suitable for topK problems ~

 

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.