Redis notes collection, very complete, welcome to exchange and study together.

1. What is Redis?

Redis is a high performance key-value database based on memory.

 

2. The characteristics of the Reids

1) Memory database of key-value type,

2) Support to save a variety of data structures,

3) The main disadvantage of Redis is that the database capacity is limited by physical memory and cannot be used as high-performance read and write of massive data.

 

3. What are the benefits of redis?

(1) Fast speed (2) support rich data types, support string, list, set, sorted set, hash (3) support transactions, (4) rich features: can be used for cache, message, set expiration time by key, will be automatically deleted after expiration

 

4. What advantages does Redis have over memcached?

(1) All memcached values are simple strings, and Redis, as an alternative, supports richer data types. (2) Redis is much faster than memcached

(3) Redis can persist its data

 

5. Several ways to persist redis

Snapshots are enabled by default. We call it “snapshots” and save data snapshots in a binary file named dump.rdb on disk. You can configure Redis persistence policies, such as writing data to disk if there are more than M updates in the data set every N seconds. Or you can manually invoke the command SAVE or BGSAVE.

The following is the default snapshot save configuration

save 900 1

save 300 10

Save 60 10000 2), the AOF snapshot mode is not very robust. When the system stops or Redis is accidentally killed, the last data written to Redis is lost. You can enable AOF mode in the configuration file and persist it every second.

This function is disabled by default. The system is backed up once every second as long as there is a write operation

6. Redis is the most suitable scenario

(1) Session Cache, shopping cart information

(2) Full page Cache (FPC)

(3) queue (4) leaderboard/counter

Publish/subscribe

 

7. What are the Java clients supported by Redis?

Redisson, Jedis

 

8. Which data type is more convenient to use?

Zset, score, sort (default to sort by score from smallest to largest)

 

9. How to use string data type to express a row in mysql?

You can represent the entire line as a JSON string

10. If the id card of a class is stored, and it is convenient to count the total number, which data type should be used?

1)set,scard

2)hash,hlen

 

11. What does zset score mean?

A fraction is a number of type double.

 

12. How to arrange the score in reverse order?

zrevrange

 

13. Find the names of students with scores between 80 and 90

zrangbyscore kaoshi 80 90

 

14. How to back up immediately (in real time)?

Save: block the main Redis process until the save is complete

Bgsave: Fork out a child process, asynchronous backup

 

15. What is the default configuration file name suffix for RDB?

dump.rdb

 

16. How do I enable AOF persistence?

appendonly yes 

 

17. How do you understand the horizontal scaling of redis clusters?

Horizontal expansion/horizontal expansion, only need to add/subtract machines, the original structure does not need to change. There are 16384 slots, which may need to be redivided.

 

18. Explain the CAP?

Theory of CAP

C:consistency: data is consistent across multiple copies

A: Avalibility should respond to every operation by users within A certain period of time

P:Partition-tolerence to Partition: A distributed network is still providing services when parts of the network are unavailable

The three can not coexist, availability and consistency are antagonism, in the premise of tolerating network partition, either sacrifice data consistency, or sacrifice write availability.

Redis meets AP and gives up part of C, which is Redis’ CAP strategy.

 

19. How to understand fault tolerance of partitions: A distributed system can still provide consistent and available services when encountering any network partition failure, unless the entire network environment fails.

.

20. A master library can have multiple slave libraries, but a slave library can only belong to one master library, right?

Yes, that means there is only one master in the master-slave schema

 

21. Load balancing strategy for redis cluster?

Points slot

 

23. What is a daemon? How do I run Redis in daemon mode?

daemize yes

 

24. How do I change the running port of a Redis instance?

port 6380

 

25. How do I close Redis?

Shutdown the save | unsave command

./redis-cli -p 6379 shutdown

 

26. How do I persist it manually?

save

bgsave

 

27. Write the command to log in to the redis instance with port 7000 and password ads999 on host 192.168.3.3.

Redis -cli -h 192.168.3.3 -p 7000 -a ADS999

 

28. How to obtain how long will a key expire?

ttl keyname

-1 never expires

-2 has expired

Five has five seconds left to expire

 

29. How do I randomly get the name of a key from the 5th library and write the command?

select 4

randomkey

 

30. Can the key value be changed? How to modify if so?

Yes, rename oldName newName

 

31. How to obtain the total number of keys in the fifth database? Write command

select 4

dbsize

 

32. How to determine the data type of a key?

type

 

33. How do I determine if wangming is a member of the set student?

SISMEMBER students wangming

 

34. How do I add an access password to a Redis?

redis.conf

requirepass admin132

 

35. What are the differences between RDB persistence and AOF persistence? Which persistence file is read first for default recovery?

Choose aof first.

 

36. In a master-slave replication schema, is it better to persist in master or slave to improve the throughput of the entire schema?

slave

37. In master-slave architecture, a master can have N slaves, right? What is the relationship between the slaves?

right

1) In the first architecture, one master has many slaves, and each slave has no relationship, but the data of each slave is ultimately consistent. Because asynchronous replication is performed, real-time consistency is not guaranteed.

2) The second structure, cascading relation, slave has relation,

 

38. In a master-slave schema, the values of the master and all slaves are ultimately the same, right?

right

 

39. A Redis cluster must have at least 3 masters. It can have no slaves or multiple slaves, right?

Yes, the minimum configuration is 3 masters and 0 slaves.

 

40. A Redis cluster requires at least six redis instances if each master must have one slave, right?

right

 

41. Explain the asynchronous replication between master and slave.

You can also respond to client requests during replication without waiting for a successful replication before responding to users.

The result of asynchronous replication agents is that we do not know whether the replication is successful, we are not 100% sure whether the replication is successful, and it is not real-time.

 

42. Master instances in the cluster are interconnected and synchronized with each other, right

Not right. It’s good to connect to each other. The data isn’t synchronized. Slot allocation principle data is stored in slots.

 

43. If persistence is disabled in the configuration file, will the save command still generate the persistence file?

Yes, no conflict. Disabling persistence simply disables automatic persistence.

 

44. What is the return value if the transaction fails?

1) If nil is returned on the command line

2) If the jedis client returns null

 

45. What data type is returned when a transaction is executed in Jedis, if successful? How do I know what the return value of the second command in the transaction is?

Jedis returns a List object that holds the execution results of each command. get(1)

 

46. In a master-slave replication architecture, there is no guarantee of real-time master-slave replication or success, right

Yes, asynchronous replication.

 

47. Describe the load balancing principle of a cluster.

Load balancing is achieved through the allocation of slots. Firstly, the number of slots must be 16384 and the slots are allocated to the master node according to a relatively average algorithm

 

Welcome to qq group: 894294771, learn and communicate together.