Detailed description of using the Redis database in. NET,. netredis

Source: Internet
Author: User
Tags download redis

Detailed description of using the Redis database in. NET,. netredis

Redis is a widely used Key/Value memory database. It is used as a cache for large applications such as Sina Weibo, Github, and StackOverflow. The official Redis website is http://redis.io /.

Redis needs to be used in recent projects. Here we will briefly record the installation of Redis and how to use Redis in. NET.

Install and start Redis

1. Download Redis

Redis itself does not provide the Windows version, and it is not stable on Windows. Generally, it is deployed in a Linux environment. Redis can be downloaded from its official website. MSOpenTech provides the Windows version, to learn how to install this version.

Click to go to Github and click Zip to download. After the download, select 32-bit or 64-bit for installation based on your computer version. I decompress the 64-bit package and put it in the D: \ Redis folder. At the same time, I copied the redis. conf in the folder to this directory. This is the redis configuration information:

2. Start Redis

Enable Redis in Windows is the same as starting MogoDB. You need to use the command line to start Redis. First, locate the Directory and run the following command:

D:\Redis>redis-server.exe redis.conf

Because it is running on the local machine, pay attention to the port number and do not close the port.

Of course, you can also enable Redis in the background as a Windows service.

3. Use

Now open another console application to connect to the previously started Redis, as shown below:

D:\Redis>redis-cli.exe -h 172.16.147.121 -p 6379

Here,-h is followed by the local IP address, followed by the port.

Then, you can run set to assign values to the city key:

redis 172.16.147.121:6379> set city Shanghai

Get can be used to obtain the value of the specified key as city.

redis 172.16.147.121:6379> get city

At the same time, when we write data to redis, The Redis service will also regularly write data to the file.

Here only a brief introduction to the get and set commands, more commands can view the http://redis.io/commands

. Explore Redis

Download ServiceStack. Redis

Like MongoDB, using Redis in. NET also uses a third-party driver. The official website recommends using ServiceStack. Redis to download and decompress the following dll.

Use Redis in. NET Projects

Create a Console program and reference the four dll files extracted in the previous step.

Let's take a simple example to get the previously set city Value in. NET.

Class Program {static RedisClient redisClient = new RedisClient ("172.16.147.121", 6379); // redis service IP address and port static void Main (string [] args) {Console. writeLine (redisClient. get <string> ("city"); Console. readKey ();}}

First, use static RedisClient redisClient = new RedisClient ("172.16.147.121", 6379 );

Establish a connection, and then you can directly use the Get method in the redisClient to obtain the value of key as city.

In the previous command line, we saved Shanghai in the network city. Now we get this value.

ServerStack has many methods that can be called in. NET. Its class structure is as follows:

Summary

This article briefly introduces how to install Redis and Redis in Windows, and how to install Redis in Windows.. NET. NET. NET Redis reads and writes complex objects. We also hope that you can support the customer's home.

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.