Collect some Redis interview questions and welcome the challenge

Source: Internet
Author: User
Tags allkeys current time redis volatile in python

one, MySQL has 2000w data, Redis only 20w of data, how to ensure that the data in Redis are hot data

related knowledge: when the Redis memory dataset size rises to a certain size, it will implement a data-phase-out strategy. Redis offers 6 kinds of data-culling strategies:
VOLATILE-LRU: Pick the least recently used data from the set of data sets (Server.db[i].expires) that have expired time

Volatile-ttl: Select the data that will expire from the set of expired data sets (Server.db[i].expires)

Volatile-random: Choose data culling from any data set (Server.db[i].expires) that has an expiration time set

ALLKEYS-LRU: Pick the least recently used data culling from the dataset (Server.db[i].dict)

Allkeys-random: Choose data culling from data set (SERVER.DB[I].DICT)

No-enviction (expulsion): Prohibition of eviction data

second, the difference between memcache and Redis are what.

1), storage mode

Memecache all of the data in memory, after the power outage will be suspended, the data can not exceed the memory size.

Redis is partially present on the hard drive, which guarantees the data's durability.

2), Data support type

Memcache support for data types is relatively straightforward.

Redis has complex data types.

3), using the underlying model is different

They are not the same as the underlying implementation and the application protocols that communicate with the client.

Redis builds its own VM mechanism directly, because the normal system calls system functions, it wastes a certain amount of time to move and request.

Iii. What are the common performance issues with Redis? How to resolve.

1). Master Write memory snapshot, save command dispatch Rdbsave function, will block the work of the main thread, when the snapshot is large, the performance impact is very large, will intermittently pause service, so master should not write memory snapshot.

2). Master AoF Persistence, if you do not rewrite the aof file, the performance impact of this persistence is minimal, but the aof file will continue to grow, aof file over the General Assembly to affect the recovery speed of master restart. Master should not do any persistent work, including memory snapshots and aof log files, in particular, do not enable memory snapshots to persist, if the data is more critical, a slave open aof backup data, the policy is synchronized once per second.

3). Master calls bgrewriteaof rewrite aof file, aof in the time of rewriting will occupy a large amount of CPU and memory resources, resulting in service load is too high, there is a short service pause phenomenon.

4). Redis Master-slave replication performance issues, for master-slave replication speed and connection stability, slave and master preferably in the same LAN

Four, please use Redis and any language to implement a malicious login protection code, limit 1 hours per User ID can only log in 5 times. The specific login function or function with empty function can not be written in detail.

Implemented in list: Each element in the list represents the login time, so long as the last 5th time and the current time difference is not more than 1 hours. The code written in Python is as follows:

#!/usr/bin/env python3

Import 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)) <= 3600:  
    print ("you a Re Forbidden logining ")
else:  
    print (' You're allowed to login ')
    R.lpush (ID, time.time ())
    # Login_ Func ()

Reference Document: Http://www.100mian.com/mianshi/dba/37381.html

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.