Application scenarios of several Redis data structures and redis data structure scenariosString[Html]View plaincopy
1. String
Common commands:
In addition to get, set, incr, decr mget, and other operations, Redis also provides
bottleneck. (such as bottlenecks may be in the network card)
memory usage Efficiency: using simple key-value storage, memcached memory utilization is higher, and if Redis uses hash structure to do key-value storage, because of its combined compression, Its memory utilization is higher than memcached. Of course, this is related to your application scenario and data characteristics.
Below is a translation of the Redis Official document "A fifteen minute introduction to Redis data Types", as its title suggests, The purpose of this article is to allow a beginner to understand the data structure of Redis with a simple 15-minute learning.
assignment, find a key already exists, all transactions regression, do not do assignment processing operationRedis 127.0.0.1:6379>mset name ZLH Age---Return value: OK, this sets the value of key to name and age respectively to zlh,30Redis 127.0.0.1:6379>mget name ZLH---return value: 1>zlh 2>30.Redis 127.0.0.1:6379>msetnx name Jim address China---return value is: 0, no modification is made because key is already present.Redis 127.0.0.1:6379>mget Name
iv. Jumping Table
Keywords: layer height random
The jump table supports the average O (logn), the worst O (N) Complexity of node lookups, and the sequential operation to batch nodes.In most cases, the efficiency of the jump table can be comparable to the balance tree, because the implementation of the jumping table is more simple than the balance tree, so many programs use the Jumping table instead of the balance tree.Redis uses a jumping table as one of the underlying implementati
memory storage, disk storage, and log files, which are configured with three parameters in the configuration file.The Save seconds Updates,save configuration, indicating how many times the update operation is synchronized to the data file. This can be a combination of multiple conditions, such as the default configuration file settings, set three conditions.AppendOnly yes/no, appendonly configuration, indicates whether logging occurs after each updat
First, REDIS data structure usage scene
Originally read Redisbook This book, the basic functions of redis are already familiar with, starting from last week to see the source of Redis. The current goal is to thoroughly redis the data
implement an ordered set key. There is also an internal data structure used in the cluster node.Redis's jump table implementation consists of zskiplist and zskiplistnode two structures, in which zskiplist is used to hold the information of the jumping table (such as the table Head node, footer node, length). The Zskiplistnode is used to represent the jumping table node.Integer collectionAn integer collecti
rehash to ht[1], and when the rehash work is complete, The program increases the value of the Rehashidx property by one.
With the continuous execution of the dictionary operation, all key-value pairs of ht[0] will be rehash to ht[1] at a certain point in time, which is a program that sets the value of the Rehashidx property to 1, indicating that the rehash operation is complete
The progressive rehash takes a divide-and-conquer approach, dividing the rehash key value pairs into each add
Data structures for Redis:
Redis is a data structure for key-value, and each data is a key-value pair
The type of the key is a string
Note: Keys cannot be duplicated
The value of
N-Modify operation is performed.4) Lazy Space release: Optimize the string to shorten the operation, the program will not immediately reallocate memory recovery after shortening the extra bytes, but use the free property to record, waiting for future use, if there is a growth operation can be used directly. Of course, SDS also provides an API to release SDS unused space, so there's no need to worry about memory waste caused by lazy releases.4.4 Binary Security C string must conform to a certain
SSDBA high-performance NoSQL database that supports rich data structures to replace Redis.Characteristics
100 times times the capacity of Redis instead of Redis database
LevelDB network support, using C + + development
Redis API compatible, support for
, so a progressive rehash is used in Redis. How to play it? The key is to dict->rehashidx this counter play a role. 1. Allocate space for ht[1], this dict has both ht[0] and ht[1] two hash tables; 2. When making a hash, set the REHASHIDX to the index of the hash being flushed; 3. The key value on ht[0] is hedged on the hash to ht[1], and when the hash is complete, the REHASHIDX is set to-1; Therefore, all operations are directed at two hash tables dur
The Redis database is a non-relational database, based on key/value pairs, loaded into memory at runtime, supports virtual memory for value, supports multiple data structures, supports persistence, is known for performance, and can be used for storage, caching, Message Queuing and other scenarios. The data structure ma
Redis supports V data types: string (string), hash (hash), list, set (set), and Zset (sortedset: Ordered collection).
Redis defines a rich primitive command that can interact directly with a Redis server. In practice, we do not use these primitive commands directly, and Redis
currently traversing ht[1], then the iterator iterates through the elements of the number 4th bucket of ht[1] (original ht[0]), and the traversal process ends, while there are actually some elements that are not traversed.As you can see from the above discussion, rehash cannot be allowed during traversal.As you can see from the above discussion, using a security iterator, as long as there is no action to delete the element, the traversal process is basically no problem, and the elements that al
each string that is contained is unique. Adds, gets, removes a single element, checks whether an element exists in the collection, computes the intersection, sets the difference, and randomly gets the element from the collection.Collection command:①sadd, adding the given element to the collection②smembers, returns all elements contained in the collection③sismember, checks whether the specified element exists in the collection④srem, checks whether the specified element exists in the collection,
Redis Hash store is equivalent to one record of a relational databasesuch as storing an article key for meaningful unique primary key if you want to sort the key can be given a key to a value to the Zset by zset some functions can sort Zrange zrevrange sort and pass in subscript can be paged If you want to load the IP or other fields can be placed in the Set Table association sort Zinterstore can be set and Zset set intersection [can specify the sort]
added successfully returns 1, otherwise 0, the added element is not added, will return 0 Sadd Set-key item2 Smembers displays all the elements in the collection, if the elements are very slow, so don't mess with Smembers Set-key Sismember finds whether the specified element exists in the collection, or returns 0 if there is a return of 1 Sismember Set-key Item Srem removes the specified element from the collection Srem Set-key Item 4. Hash (hash) Hset setting key-value pairs Hset Hash-key su
Note: This blog is my understanding of the data structure, many local understanding may not be appropriate, but also ask the reader to learn dialecticallyUnderstanding data structures from the macro levelMany times we have been working hard, but don't know why ...After a year of work, re-think of the university's data
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.