A Brief Introduction to using redis in the C # project

Source: Internet
Author: User
Tags redis server value store

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.

 

 

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.