Redis storage system

12. Redis storage system

1. What is Redis?

Remote Dictionary Server (Redis) is an open source log-type, Key-Value database written in ANSI C language, supports network, can be memory-based and persistent, and provides APIs in multiple languages. It is often referred to as a data structure server because values ​​can be of types such as String, Hash (Map), list (list), sets (sets) and sorted sets (sorted sets).

2. What are the characteristics of Redis?

a. Support a variety of data structures, such as string (string), list (doubly linked list), dict (hash table), set (collection), zset (sort set), hyperloglog (cardinality estimation)
b. Support persistent operations, Aof and rdb data can be persisted to disk, so as to perform data backup or data recovery operations, which is a better means to prevent data loss.
c. Support data replication through Replication. Through the master-slave mechanism, synchronous replication of data can be performed in real time, and multi-level replication and incremental replication are supported. The master-slave mechanism is an important means for Redis to perform HA.
d. For single-process requests, all commands are executed serially, and there is no need to consider data consistency in concurrent cases.

3. What are the Redis data types?

a, String (string) b, Hash (hash table) c, List (linked list)
d, Set (collection)
e, SortedSet (ordered collection zset)

4. What are the configurations and persistence schemes of Redis?

a, RDB mode b, AOF mode

5. What are the common commands in Redis?

a, hset stores a set of hash key-value pairs
b, hget gets the value of a hash key c, hdel deletes one or more fields
d, hgetall obtains a hash is a set of key-value pairs
e, lpush key value to Add f and rpush key value on the left side of the linked list to the right side of the linked list

g, lpop key removes an element
h from the left, rpop key removes an element from the right
i, keys * returns all keys, you can add * wildcard
j, exists key to determine whether a key of string type exists, if it exists, return 1, otherwise return 0

6. What physical resources does Redis mainly consume?

RAM

7. What kinds of data elimination strategies does Redis have?

1. noeviction: returns an error when the memory limit is reached and the client tries to execute a command that would make more memory used.
2. allkeys-lru: Attempt to recycle the least used key (LRU) to make room for newly added data.
3, volatile-lru: Attempt to reclaim the least used key (LRU), but only the keys in the expired set, so that the newly added data has space to store.
4. allkeys-random: Recycle random keys so that the newly added data has space to store.
5. volatile-random: Recycling random keys makes room for newly added data to be stored, but only for keys in expired sets.
6. volatile-ttl: Reclaim keys in expired sets, and give priority to keys with shorter time-to-live (TTL), so that newly added data has space to store.

8. Why doesn't Redis officially provide a Windows version?

Because the current Linux version is quite stable, and the number of users is large, there is no need to develop the windows version, but it will bring problems such as compatibility.

9. Why does Redis need to put all data in memory?

In order to achieve the fastest read and write speed, Redis reads data into memory and writes data to disk asynchronously. Therefore, redis has the characteristics of fast speed and data persistence. If the data is not placed in memory, the disk I/O speed will seriously affect the performance of redis. Today, when memory is getting cheaper and cheaper, redis will become more and more popular
. If the maximum used memory is set, new values ​​cannot be inserted after the number of existing data records reaches the memory limit.

10. What are the suitable scenarios for Redis?

1. Session Cache: One of the most commonly used scenarios for using Redis is session cache. The advantage of using Redis to cache sessions over other storage (such as Memcached) is that Redis provides persistence. When maintaining a cache that does not strictly require consistency, most people will be unhappy if all the user's shopping cart information is lost. Now, will they still do this? Fortunately, as Redis has improved over the years, it's easy to find documentation on how to properly use Redis to cache sessions. Even the well-known commercial platform Magento offers plugins for Redis.
2. Full Page Cache (FPC): In addition to the basic session token, Redis also provides a very simple FPC platform. Back to the consistency issue, even if the Redis instance is restarted, users will not see a drop in page loading speed because of disk persistence. This is a great improvement, similar to PHP's local FPC. Taking Magento as an example again, Magento provides a plugin to use Redis as a full page cache backend. Also, for WordPress users, Pantheon has a very good plugin wp-redis that helps you load the pages you've ever viewed as quickly as possible.
3. Queue: One of the advantages of Reids in the field of memory storage engines is that it provides list and set operations, which makes Redis a good message queue platform to use. The operation used by Redis as a queue is similar to the push/pop operation of a list in a native programming language (such as Python). If you do a quick Google search for "Redis queues", you'll immediately find a plethora of open source projects that aim to use Redis to create great backend tools for various queueing needs. For example, Celery has a backend that uses Redis as a broker, you can check it out here.
4. Leaderboard/Counter: Redis does a very good job of incrementing or decrementing numbers in memory. Sets and SortedSets also make it very simple for us to perform these operations. Redis just provides these two data structures.
5. Publish/Subscribe: Last (but certainly not least) is the Publish/Subscribe feature of Redis. There are really many use cases for publish/subscribe. I've seen people use it in social networking connections, as triggers for pub/sub based scripts, and even building chat systems with Redis' pub/sub functionality!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325027941&siteId=291194637