What 179.redis that? What are the usage scenarios?
Redis is an open source written in C, support network, based on the persistence of memory can log type, key-value database, and provides multi-lingual API.
Redis usage scenarios:
the data of high concurrent read and write
mass data write
high requirements for data expansion
180.redis What are the features?
Data caching functionality
distributed lock function
support data persistence
transactional
support message queues
181.redis and memecache What is the difference?
memcached all values are simple strings, redis support richer data type
speed memcached much faster than redis
redis be persistent data
182.redis Why is single-threaded?
Because the CPU is not the bottleneck of redis, redis bottlenecks are most likely to be the machine's memory or network bandwidth, since it is easy to achieve single-threaded, cpu and will not become a bottleneck, it is logical to adopt a single-threaded program. Single-threaded does not mean that a slow, nginx and nodejs also on behalf of high-performance single-threaded.
183. What is the cache penetrate? How to deal with it?
Cache penetration: refers to a certain query data does not exist, because the cache is needed from the database query is not hit, can not find the data cache is not written, it will lead to a time that does not exist in the data request should go to the database query, resulting in cache penetrate
solution: empty the cache data, BloomFilter all key, which is stored in the database currently exists, when the business system query request, first to BoolmFilter query key exists.
184.redis supported data types are there?
string, list, hash, set, zset
185.redis support java client has what?
Redisson, Jedis, lettuce and so on, the official recommended Redisson.
186.jedis and redisson What are the differences?
Jedis Redis is a java implementation of the client, its API provides more comprehensive support for Redis commands
Redisson a distributed and scalable java data structures, and Jedis compared to function is relatively simple and does not support string operations are not supported Redis characteristics ordering, transaction, plumbing, zoning and so on. Rdeisson aim is to promote the separation of Redis of interest to the user, so that users can managers focus more on business logic.
187. how to ensure the consistency of the data cache and the database?
Set reasonable cache expiration time
synchronization update when Redis add, change, delete database operations, you can use transactional mechanism to ensure data consistency
188.redis persistence There are several ways?
Redis persistence in two ways:
RDB (Redis Database): specified time interval can store a snapshot of your data
AOF (Append Only File): each write command received are appended to the file by the write function
189.redis how to achieve distributed lock?
Use setnx implement a distributed lock, setnx is set to the value of the key value, if and only if the key does not exist. If a given key exists, setnx do nothing.
Returns 1, indicating that the process to obtain a lock, setnx the value to the key lock was lock.id timeout, the current time + plus effective time lock
returns -1, indicating that the lock has been obtained by other processes, the process can not enter the critical section . The process can continue to try setnx operate in a loop, it has been locked.
190.redis distributed lock What flaws?
redis distributed lock timeout can not solve the problem, there is a distributed lock timeout, if the execution of the program beyond the lock timeout problem occurs.
How do 191.redis memory optimization?
Use hash table (hashes) as far as possible, the use of hash table memory is very small, should be as abstract data model to a hash table inside.
For instance, your web system has a user object, not to the user's name, last name, email, password, set up a separate key, but just think of all the information stored in the user to a hash table inside
192.redis out of what strategy?
volatile-lru: from a set expiration time of the data set selection phase out the least recently used data;
volatile-ttl: pick and choose to expire the data has been eliminated from the data set the expiration time point.
volatile-random: from a centralized arbitrarily set the expiration time of the data out of the data selection
allkeys-lru: data from the data set selected out of the least recently used
allkeys-random: from a centralized data arbitrarily selected data out of
no-enviction: get rid of prohibited data
193.redis common performance problems What? What is the solution?
Master write memory snapshots, can block the main thread of the work, when the snapshot is relatively large impact on performance is very large, it will be suspended intermittently, so it is best not to write the main server memory snapshot.
redis replication master from performance problems, in order from the master copy speed and stability of the link, the master from the library is preferably in the same LAN