In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the common interview questions and answers about redis. The content of the article is of high quality, so I will share it with you for reference. I hope you can get something after reading this article.
1. What is redis?
Redis is a memory-based high-performance key-value database.
2. The characteristics of Reids
Redis is essentially an in-memory database of Key-Value type, much like memcached, the whole database is loaded and operated in memory, and the database data is saved to the hard disk by asynchronous operation periodically. Because of its pure memory operation, Redis has excellent performance, which can handle more than 100000 read and write operations per second, making it the fastest Key-Value DB known.
The excellence of Redis is not only its performance, but the greatest charm of Redis is that it supports the preservation of multiple data structures. in addition, the maximum limitation of a single value is 1GB, unlike memcached, which can only save 1MB data, so Redis can be used to achieve many useful functions, such as using its List to do a FIFO two-way linked list to achieve a lightweight high performance cancellation.
Information queuing service, using his Set can do high-performance tag system and so on. In addition, Redis can also set the expire time for the stored Key-Value, so it can also be used as an enhanced version of memcached.
The main disadvantage of Redis is that the database capacity is limited by physical memory and can not be used for high-performance read and write of massive data, so the suitable scenarios of Redis are mainly limited to high-performance operations and operations with a small amount of data.
3. What are the benefits of using redis?
(1) it is fast, because the data is stored in memory, and the advantage similar to HashMap,HashMap is that the time complexity of search and operation is O (1).
(2) supports rich data types and string,list,set,sorted set,hash
(3) transactions are supported, and all operations are atomic. the so-called atomicity means that changes to the data are either performed or not performed at all.
(4) rich features: can be used for caching, messages, set expiration time by key, and will be deleted automatically after expiration
4. What are the advantages of redis over memcached?
(1) all values of memcached are simple strings, and redis, as its replacement, supports richer data types.
(2) redis is much faster than memcached.
(3) redis can persist its data
5. What are the differences between Memcache and Redis?
1) Storage method Memecache stores all the data in memory, and will hang up when the power is off, and the data cannot exceed the memory size. Some of the Redis is stored on the hard disk, which ensures the persistence of the data.
2) data support type Memcache is relatively simple to support data types. Redis has complex data types.
3) using the underlying model, the underlying implementation between them and the application protocol for communicating with the client are different. Redis directly builds its own VM mechanism, because the general system calls system functions, it will waste a certain amount of time to move and request.
6. Common performance problems and solutions of redis:
1) .Master writes memory snapshots, and the save command dispatches the rdbSave function, which will block the work of the main thread. When the snapshot is relatively large, it will have a great impact on performance and will intermittently suspend the service. Therefore, it is best not to write memory snapshots for Master.
2). Master AOF persistence, if you do not rewrite AOF files, this persistence method will have the least impact on performance, but AOF files will continue to grow, and excessive AOF files will affect the recovery speed of Master restart. It is best for Master not to do any persistence work, including memory snapshots and AOF log files. In particular, do not enable memory snapshots for persistence. If the data is critical, a Slave enables AOF to back up data. The policy is to synchronize once per second.
3) when the .Master calls BGREWRITEAOF to rewrite the AOF file, AOF will take up a lot of CPU and memory resources when rewriting, resulting in high service load and temporary service suspension.
4), the performance problem of Redis master-slave replication. For the speed of master-slave replication and the stability of connection, Slave and Master should be in the same local area network.
7. There are 2000w data in mySQL and only 20w data in redis. How to ensure that the data in redis are hot data.
Related knowledge: when the redis in-memory dataset size rises to a certain size, the data phase-out strategy (recovery strategy) will be implemented. Redis provides 6 data elimination strategies:
Volatile-lru: select the least recently used data elimination from the dataset with an expiration time set (server. DB [I]. Obsolete).
Volatile-ttl: select the expired data from the dataset (server. DB [I]. Expires) that will expire.
Volatile-random: arbitrarily select data elimination from a dataset with an expiration time set (server. DB [I]. Expires).
Allkeys-lru: select the least recently used data elimination from the dataset (server. DB [I]. Dict).
Allkeys-random: data elimination from any selection of the dataset (server. DB [I]. Dict)
No-enviction (expulsion): prohibition of eviction data
8. Please implement a malicious login protection code in Redis and any language, limiting each user's Id to a maximum of 5 logins in an hour. Specific login functions or functions can be used with empty functions, and do not need to be written out in detail.
List implementation: each element in the list represents the landing time, as long as the last fifth login time and the current time difference is not more than 1 hour. The code written in Python is as follows:
#! / usr/bin/env python3import redis import sys import time r = redis.StrictRedis (host='127.0.0.1', port=6379, db=0) try: id = sys.argv [1] except: print ('input argument error') sys.exit (0) if r.llen (id) > = 5 and time.time ()-float (r.lindex (id, 4))
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.