One. NET using Redis
Like MongoDB, using Redis in. NET is actually using a third-party driver, and the official website recommends using Servicestack.redis (Https://github.com/ServiceStack/ServiceStack.Redis)
Click Download package, unzip Servicestack.redis-master.zip\servicestack.redis-master\build\release\monodevelop The ServiceStack.Redis.zip compressed package will have 4 DLLs, we can add references directly in the project!
Ii. Redis Data types
Redis currently offers five types of data: string (String), list (linked list), hash (hash), set (set), and Zset (sorted set) (ordered collection).
1. String type
String is the most common type of data, and normal Key/value storage can be categorized as such. A key corresponding to a value,string type is binary safe. A Redis string can contain any data, such as a JPG image (which generates binary) or a serialized object.
2. Hash type
Hash is a string-type field and value mapping table. Hash is particularly suitable for storing objects. Relative to Gencun each word of an object into a single string type. An object stored in a hash type consumes less memory and makes it easier to access the entire object. The reason for saving memory is that when a new hash object is created, it is stored with Zipmap (also known as small hash). This zipmap is not actually hash table, but zipmap compared to the normal hash implementation can save a lot of the hash itself needs some metadata storage overhead. Although Zipmap's additions, deletions, and lookups are all O (n), there are not too many field numbers for general objects. So the use of Zipmap is also very fast, that is, add delete average or O (1). If the size of field or value exceeds a certain limit, Redis automatically replaces the zipmap with the normal hash implementation internally. This restriction can be specified in the configuration file.
Such as. Redis's hash is actually the internal storage of value for a hashmap, this HashMap key is a member of the property name, value is the property value, so that the data modification and access can be directly through its internal HashMap key ( Redis is called the internal HashMap key is field), that is, through the key (user ID) + field (attribute tag) can manipulate the corresponding attribute data.
3. List Type
List is a linked list structure, the main function is Push,pop, get all the values of a range, etc., the operation of key is understood as the list name. The Redis list type is actually a doubly linked list in which each child element is a string type. We can add delete elements from the head or tail of the list through the Push,pop operation, so that the list can be both a stack and a queue.
The implementation of Redis list is a doubly linked list, which can support reverse lookup and traversal, but it is more convenient to operate, but it brings some additional memory overhead, and many implementations within Redis, including sending buffer queues, are also used in this data structure.
4. Set type
In Redis, we can see the set type as an unordered character set, and as with the list type, we can also perform operations such as adding, deleting, or judging whether an element exists on the data value of that type. It should be stated that the time complexity of these operations is O (1), which is the completion of the operation within a constant time. The maximum number of elements that a set can contain is 4294967295.
Unlike the list type, duplicate elements are not allowed in the set collection, which is identical to the set container in the C + + standard library. In other words, if you add the same element more than once, only one copy of the element will be preserved in set. The set type has a functionally important feature in comparison to the list type, which is to perform aggregate compute operations between multiple sets on the server side, such as unions, intersections, and differences. Because these operations are done on the server side, they are highly efficient and also save a lot of network IO overhead.
5. Sorted set Type
Sorted set is an upgraded version of Set, which adds a sequential property to the set based on the addition of modifications. The element can be specified, and each time it is specified, Zset (representing an ordered collection) automatically re-adjusts the order of the new values. It can be understood as a table with columns, a column of value, and a list of stored orders. Key in operation is understood as the name of Zset.
Application Scenarios:
The usage scenario for Redis sorted set is similar to set, except that the set is not automatically ordered, and the sorted set can be ordered by the user with an additional priority (score) parameter, and is inserted in an orderly, automatic sort. When you need a list of ordered and non-repeating collections, you can choose the sorted set data structure.
About Redis Four