Redis notes 02

Source: Internet
Author: User

Object

1. The key and value of each key-value pair in the Redis database is an object.

2. Redis has a string, list, hash, collection, ordered collection of five types of objects, each type of object has at least two or more encoding, different encoding can be used in different scenarios to optimize the use of the object's efficiency.

3. Before executing certain commands, the server checks whether the type of the given key can execute the specified command, while checking the type of a key is the type of the value object that checks the key.

4. The Redis object system has a memory-recycling mechanism that implements reference counting, and when an object is no longer in use, the memory consumed by the object is automatically freed.

5. Redis will share string objects with values from 0 to 9999. Redis shares only String objects that contain integer values.

6. The object will record its last accessed time, which can be used to calculate the idle time of the object to determine the recovery memory.

1. Each time we create a new key-value pair in the Redis database, we create at least two objects, one object as the key (key) object for the key-value pair, and the other as the value of the key-value pair (the value object)

2. Each object in Redis is represented by a redisobject structure in which the three properties associated with saving data are the Type property, the Encoding property, and the PTR property.

3. For a key-value pair saved by a Redis database, the key is always a string object, while the value can be either a string object, a list object, a hash object, a collection object, or one of the ordered collection objects.

4. Type key command returns the type of the value object that the key corresponds to, not the type of the key object. The return value of type: String,list,hash,set,zset

5. The object's PTR pointer points to the underlying implementation data structure of the object, which is determined by the object's Encoding property. The Encoding property records the encoding used by the object, that is, what data structures the object uses

(dictionary, linked list, etc.) as the underlying implementation of an object.

6. Each type of object uses at least two different encodings. Redis can optimize the efficiency of an object in a scene by setting different encodings for an object based on different usage scenarios.

7. Use the object Encoding command to view the encoding of a database's value object.

8. The encoding of the string can be Int,raw or embstr. In the case where the condition is met, int and embstr are converted to raw encoded string objects.

9. String Common commands:

Set, GET, Appedn, incrbyfloat (floating-point addition), Incrby (integer addition), Decrby (integer subtraction), STRLEN (returns the length of the string), SETRANGE (setting the value of a specific index), GETRANGE ( Gets the value of a specific index)

10. The encoding of the list object can be Ziplist or LinkedList.

11. List Common commands:

Lpush (The new element is added to the header), Rpush (The new element is added to the footer), Lpop (Gets and drops the header node), Rpop (Gets and deletes the footer node), LINDEX (Gets the element of the specified index), Llen (Gets the list length),

Linsert (Inserts an element at the specified position in the list), Lrem (deletes a node that is not in the specified index range), LSET (Updates the node at the specified location)

12. The hash object can be encoded as ziplist or Hashtable.

13. Hash object Common commands:

Hset (Add new node), Hget (gets the corresponding value), hexists (determines whether the specified key exists), Hdel (deletes the specified node), Hlen (returns the number of key-value pairs), Hgetall (returns all key-value pairs)

14. The encoding of the collection object can be Intset or hashtable

15. Common Commands for collection objects:

Sadd,scard (Gets the number of elements), Sismember (determines whether an element exists), smembers (returns all key values), Srandmember (which returns an element), SPOP (gets and removes the element), Srem (removes all given elements)

16. Ordered collection object, encoding can be ziplist or skiplist

17. Common commands for ordered collection objects:

Zadd,zcar (Gets the number of collection elements), Zcount (Gets the number of nodes in a given range), Zrang (from the header to the footer, returns all elements in the given index range), Zrevrange (from the end of the table to the header, returning all the elements in the given index range),

Zrank (from table header to footer, return node rank), Zrevrank (from footer to table header, return node rank), Zrem (delete), Zscore (Get Score)

There are basically two types of commands for operating keys in Redis:

1). You can execute on any type of key, such as the Del Command, the expire command, the Rename command, the type command, the Object command, and so on.

2). Can only be performed on a specific type of key:

Commands such as Set,get,append,strlen can only be executed on string keys;

Hdel,hset,hget,hlen and other commands can only be executed on the hash key;

Rpush,lpop,linsert,llen and other commands can only be performed on the list key;

Sadd,spop,sinter,scard and other commands can only be executed on the collection key;

Commands such as Zadd,zcard,zrank,zscore can only be executed on an ordered set key.

In addition to determining whether a key is capable of executing a specified command based on the type of the value object, Redis chooses the correct command implementation code to execute the command based on the encoding of the value object and the function that determines which structure is called.

20. Memory Reclamation: When the reference count value of an object becomes 0 o'clock, the memory occupied by the object is freed.

Redis notes 02

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.