C #-based MongoDB database development and application (4)-Redis installation and use,

Source: Internet
Author: User

C #-based MongoDB database development and application (4)-Redis installation and use,

I have introduced three articles about MongoDB database development and usage. Strictly speaking, this article cannot be classified into MongoDB database development. However, Redis is closely related to MongoDB databases, they are very similar to each other. Redis is mainly a NoSQL database in the memory to improve performance. MongoDB databases are NoSQL databases in files for storing data serial numbers, they are closely related and different. This article describes how to install and use apsaradb for Redis, laying the foundation for the joint use of apsaradb for Redis and apsaradb for MongoDB.

1. Redis basics and Installation

Redis is an open-source log-type and Key-Value database written in ansi c language that supports the network and can be persistent based on memory. It is similar to Memcached, it supports more storage value types, including string, list, set, and zset) and hash (hash type ). On this basis, redis supports sorting in different ways. Like memcached, data is cached in the memory to ensure efficiency. The difference is that redis periodically writes the updated data to the disk or writes the modification operation to the append record file, and on this basis implements master-slave (master-slave) synchronization.

Redis Code follows the ANSI-C and can be written in all POSIX systems (such as Linux,*BSD, Mac OS X, Solaris, etc. In addition, Redis does not rely on any non-standard library, nor does it need to add compilation parameters.

1) Redis supports two persistence methods:

(1): snapshotting (snapshot) is also the default method (to back up data and store data to files)

(2) Append-only file (aof) Method

Snapshots are the default persistence method. In this way, data in the memory is written to binary files as snapshots. The default file name is dump. rdb. you can configure and set Automatic snapshot persistence. We can configure redis to automatically create snapshots if more than m key keys are modified in n seconds.

Aof method: Because the snapshot method is performed once at a certain interval, if Redis accidentally goes down, all modifications after the last snapshot will be lost. Aof is more persistent than snapshot, because when aof is used, redis will append every write command received to the file through the write function, when redis is restarted, it re-executes the write commands saved in the file to recreate the entire database content in the memory.

2) Redis Data Structure

Redis author antirez once called it a Data Structure server (Data structures server), This is a very accurate expression. All Redis functions are to save data in several inherent structures and provide users with interfaces to operate these structures. We can imagine the inherent data types and their operations in various languages.

Redis currently provides four data types:String,List,SetAndZset(Sorted set) andHash.

  • StringIs the simplest type. You can understand it as a Type modeled by Memcached. A key corresponds to a value, and the operations supported on it are similar to those of Memcached. However, it provides more functions.
  • ListIs a linked list structure, the main function is to push, pop, get all values of a range, and so on. In the operation, the key is interpreted as the name of the linked list.
  • SetIs a set. Similar to the set concept in our mathematics, we add and delete elements to the set operations, and perform operations such as intersection of multiple sets. The key in the operation is interpreted as the name of the set.
  • ZsetIs an upgraded version of set. It adds an ordered Attribute Based on set. This attribute can be specified when adding and modifying elements. After each attribute is specified, zset automatically re-adjusts the order according to the new value. It can be understood that there are two columns of mysql tables, one column stores value and one column stores order. In the operation, the key is interpreted as the zset name.
  • HashThe data type allows users to use Redis to store object types. An important advantage of the Hash data type is that when there are only a few key values in the data object you store, the memory consumption of the data storage will be very small.
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.