In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge of this article "how to use Redis String", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can gain something after reading this article. Let's take a look at this "how to use Redis String" article.
1. Basically use set key value [EX seconds] [PX milliseconds] [NX | XX]
1. Set is the syntax, key is the specified name, and value is the value to be stored
2. EX specifies the second time to expire, and PX specifies the millisecond time to expire.
3. NX: the configuration is successful only if key does not exist.
4. XX: the configuration is successful only if key exists.
Summary: 5.0 supports set command to specify expiration time and set successfully when it does not exist, that is, the function of distributed lock locking can be realized with one command. The previous version setting key and setting expiration time need to be divided into two commands, which makes it more difficult to guarantee atomicity.
Second, use the scene
1. Hot spot data caching, distributed session
2. Setnx distributed lock
3. Incr counter
4. Incr global id
5. Incr current restriction
6. Bit operation, bitmap function, online user statistics 0Universe 1 mark
Data types that are supported for storage
Integer, character, float (single floating point)
4. Different coding types
Fifth, String storage principle
In Redis, data is stored in a RedisObject class
Typedef struct redisObject {/ / this type can be string, hash,zset, etc. Unsigned type:4; unsigned encoding:4; / / record the access time and frequency unsigned lru:LRU_BITS that the lru,lfu phase-out algorithm depends on / * LRU time (relative to global lru_clock) or * LFU data (least significant 8 bits frequency * and most significant 16 bits access time). * / / reference counter int refcount; / / points to the real data structure object void * ptr;} robj
For String,Redis, a simple dynamic string data structure is customized to store the number of strings.
Source code implementation: a variety of data structures that can store strings of different lengths.
Through source code analysis, the expansion strategy is to double the expansion space before the length of the string is less than SDS_MAX_PREALLOC, that is, to retain 100% redundant space. When the length exceeds SDS_MAX_PREALLOC, in order to avoid the waste caused by excessive redundant space after doubling, each expansion will only allocate more redundant space the size of SDS_MAX_PREALLOC.
On the release of inert space
Lazy space releases string shortening operations used to optimize SDS: when SDS's API needs to shorten strings saved by SDS, the program does not immediately use memory redistribution to recycle the shortened extra bytes, but uses the free property to record the number of these bytes and wait for future use.
/ / only set the length, not really clear the data void sdsclear (sdss) {/ / simply set the length to 0 sdssetlen (s, 0); / / the first character is set to the Terminator s [0] ='\ 0mm;}
Really clear the space.
Sds sdsRemoveFreeSpace (sds s) {struct sdshdr * sh; sh = (void*) (s-(sizeof (struct sdshdr); / / memory reallocation so that buf is only long enough to hold string contents sh = zrealloc (sh, sizeof (struct sdshdr) + sh- > len+1); / / Free space is 0 sh- > free = 0; return sh- > buf } the above is about the content of this article on "how to use Redis String". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.