Description: string is the most basic type of redis, and you can understand it as exactly the same type as Memcached, with one key corresponding to one value. The value is not only a string, but also a number. String types are binary-safe. A string indicating that redis can contain any data. Such as jpg pictures or serialized objects. String type is the most basic data type of Redis, and the value of string type can be stored at most 5 12MB.
Common commands: get, set, incr, decr, mget, etc.
Application scenario: specify the key value cache application. Total count: like it, fans.
Description: hash is a set of key value (key => value) pairs. Redihash is a mapping table of fields and values of string type, and hash is especially suitable for storing objects.
Common commands: hget, hset, hgetall, etc.
Application scenario: store some change data, such as commodity information.
Description: list list is a simple list of strings, sorted by insertion order. You can add elements to the head (left) or tail (right) of the list. Lists can store up to 232- 1 elements (4294967295, each list can store more than 4 billion).
Common commands: lpush (add left element), rpush, lpop (remove the first element on the left), rpop, LRANGE (get list fragment, lrange key start stop), etc.
Application scenarios: message queue, attention list, fan list, etc. Can be achieved through the list structure of Redis.
Description: set is an unordered collection of type string. Set is realized by hashtable, and the concept is basically similar to the set in mathematics, which can intersect, merge, differ and so on. The elements in the collection are out of order. So the complexity of adding, deleting and searching is O( 1).
Common commands: sadd, spop, sembers, sunion, etc.
Application scenarios: intersection, union and difference (in Weibo, all followers of a user can be stored in one collection, and all fans can be stored in one collection. Redis also provides operations such as intersection, union and difference set for the set, which can easily realize functions such as * * * same concern, * * same preference and two friends. For all the above collection operations, you can also use different commands to choose whether to return the results to the client or save them in a new collection. )
Description: zset, like set, is a collection of elements of type string, and duplicate members are not allowed. The difference is that you can grade (sort)
Common commands: zadd, zrange, zrem, zcard, etc.
Application scenario: leaderboards, weighted message queues.
Description: Bitmap, a "data structure", can realize the operation of counterpoint. Data structures are referenced mainly because:
Bitmaps itself is not a data structure, in fact, it is a string, but it can manipulate the bits of the string.
Bitmaps provide a set of independent commands, so using bitmaps in Redis is different from using strings. Bitmaps can be thought of as an array of bits. Each cell of the array can only store 0 and 1, and the subscript of the array is called offset in the bitmap. In fact, most application scenarios of bitmap can be realized by other data types, and bitmap mainly occupies less storage space.
Common commands: getbit key offset; ; Setbit key offset value
Application scenario: statistics of users' visits and statistics of movie play on a certain day.
Description: Redis added HyperLogLog structure in version 2.8.9. Redis HyperLogLog is a cardinal statistical algorithm. The advantage of HyperLogLog is that when the number or volume of input elements is very large, the space required for radix calculation is always fixed and very small. In Redis, each HyperLogLog key only needs to spend 12 KB of memory to calculate the cardinality of nearly 2 64 different elements. This is in sharp contrast to the set that consumes more memory when calculating cardinality. However, because HyperLogLog only calculates the cardinality according to the input elements and does not store the input elements themselves, HyperLogLog cannot return the input elements like a collection. The basic idea of this data structure is to use statistical probability algorithm to save memory space and improve the performance of related operations at the expense of data accuracy.
Common commands: pfadd, pfcount, pfmerge.
Application scenario: statistical website daily UV.
Description: The geo function is provided in Redis3.2, which supports the storage of geographical location information, and realizes the functions that depend on geographical location information, such as locating nearby and shaking. GEO's data type is zset.
Common commands: geoadd, geopos, geodist.
Application scenario: nearby position, shaking
Reference list:
Redis five data types and application scenarios