First contact with Redis database under. NET

Source: Internet
Author: User
Tags redis server

About Redis

1. Introduction

Redis is a well-known nosql (not just SQL) database and is a key-value pair structure. (I've only used the key-value pair structure)

He has optimized storage key-value pairs and is widely used in large web sites. Redis provides automatic expiration of data and supports clustering.

Suitable for temporary storage of data, and storage of some discrete data.

2. Use

Redis can store some temporary data. You can store data that is meaningful at some point, but not worth storing in a database.

At the same time, for data statistics, the user's one click, one login, it is meaningful. But these large numbers of discrete, individual data that are meaningless, are obviously not suitable for storing in relational databases. Redis provides a solution to this problem.

3. Environment

Description: redis server has Linux, Windows edition, Linux version of the performance is good for production environment, on their own Windows computer only to learn. Don't take it too seriously.

1) Installation of Redis server under Windows: Unzip redisbin_x32.zip to hard disk;


2) Install Rediswatcher (Redis Run as system service, if there is a problem with the installation process, the direct execution of Redis-server can also),


3) then configure watcher.conf in the Rediswatcher installation directory to point to the Redis-server path, and then start Rediswatch in the Windows service. Note watcher.conf can only be opened with an advanced text editor.



4) referencing in the project

If you want to use a Redis database, you need to add four references as above in your project.

OK, ready to work here, all done. We started using the demo.

Use

1. The class that corresponds to the configuration file.

public class Redismanager

{

Note that the notation for this property is {get; private set;} External non-writable.

public static Pooledredisclientmanager Clientmanager {get; private set;}

Static Redismanager ()

{

Redisclientmanagerconfig redisconfig = new Redisclientmanagerconfig ();

redisconfig.maxwritepoolsize = 128;

redisconfig.maxreadpoolsize = 128;

/* Read and write separation. Multiple Redis Components cluster

Note that the first two parameters, parameter 1, read and write Redis server address, as a string array, support multiple addresses, that is, support cluster.

Parameter 2 means that the server that reads Redis also supports clustering.

*/

Clientmanager = new Pooledredisclientmanager (new string[] {"127.0.0.1"},

New string[] {"127.0.0.1"}, Redisconfig);

}

}

2. Save and read

static void Main (string[] args)

{

using (iredisclient client = RedisManager.ClientManager.GetClient ())

{

1. Set the Read int object

Client. Set<int> ("Age", 18);  

              &NBSP; Span style= "font-family:; Color:; line-height:1.5 ">   client. Get<int> ("Age");

               // 2. Set read Sting object

Client. Set<string> ("Name", "Jim");

String name = client. Get<string> ("name");

3. Set Read Dictionary object

dictionary<string, string> dict = new dictionary<string, string> ();

Dict. ADD ("AAA", "BBB");

Client. Set<dictionary<string, string>> ("Dict", dict);

Client. Get<dictionary<string,string>> (DICT);

4. Set the expiration time when assigning values.

Client. Set<string> ("name", "Rupeng", DateTime.Now.AddSeconds (30))

}

}


First contact with Redis database under. NET

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.