In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Mainly used as a cache function, not as a database and message server
Single point server building
1: download the release package:
Wget http://download.redis.io/releases/redis-4.0.11.tar.gz
Decompress: tar-zxvf
2: compile after entering the directory: make, you need to install c:yum install gcc-c++
Compile time: jemalloc/jemalloc.h: No such file or directory
Jemalloc overloads the malloc and free functions of LInux's ANSI C: specify parameters when make:
Make MALLOC=libc
The compiled files are all in src
3: start the server:
Src/redis-server
4: connect to the server: src/redis-cli
Cluster building
Using more than 4. 0 environment, using self-contained ruby script to build redis cluster requires at least 6 nodes, three masters and three slaves
1: install a single server on multiple nodes, and then modify the redis.conf file
Minimize configuration:
Port 7000
Cluster-enabled yes
When cluster-config-file nodes.conf / / starts, it is generated and managed by redis.
Cluster-node-timeout 5000
Appendonly yes
Bind 10.99.32.16 / / you need to bind the ip of your own node, otherwise the outside cannot access it.
2: use src/redis-server. / redis.conf at startup
Multiple instances are launched separately.
3: if ruby is already installed, you do not need to perform this step
The process of installing ruby:
Download the release package:
Wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz
Decompress,. / configure & & make & & make install
After installation, you can use gem install redis.
The installation process may report an error and resolve it on its own.
4:src/redis-trib.rb create-- replicas 1 10.99.32.16RV 6379 10.99.32.17RU 6379 10.99.32.18Rd 6379 10.99.32.20Rd 6379 10.99.32.22Rd 6379 10.99.32.236379
A minimum of 6 nodes are required
[OK] All 16384 slots covered. That is, success
5: append new nodes
1: start the node instance first
2: use redis-trib.rb
. / redis-trib.rb add-node myNewNodeIp:port
Append replica node:
. / redis-trib.rb add-node-- slave 127.0.0.1 7006 127.0.0.1 VR 7000
Assign a master node to the new copy node:
. / redis-trib.rb add-node-- slave-- master-id 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 127.0.0.1 master-id 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 7006 127.0.0.1 VR 7000
6: remove nodes
. / redis-trib del-node myip:port mynodeId
Some concepts
Cluster port:
Each redis cluster node needs to open two tcp connections. One is the client connection, for example, the default port 6379pagePlus acquires the data port by adding 10000, such as 16379
The other port is the cluster bus, which is the node-to-node communication channel, using the binary transport protocol. Nodes use the cluster bus to detect failures, configure updates and failover authorizations and more. Clients should not use the cluster bus port for communication, but can use the redis command port.
Cluster data fragmentation: distribute the data to each node for storage. Redis clusters do not use a consistent hashing, but each shard takes the form of a key, which is called hash slot. Redis has 16384 hash slot and calculates the key of hash slot. For example, there are three nodes.
NodeA contains hash slot 0-5500
NodeB contains 5501-11000
NodeC contains 11011-16383
Redis cluster does not guarantee strong consistency
When you run the redis server directly, it will run at the front end, and if you need to run it in the background:
Run redis in the background: change the daemonize of the configuration file redis.conf to yes
-
When configuring a cluster, if you don't understand the jam, you may have configured some nodes before, shut down and rerun the script. If you run the footer: Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in databas
Solution: delete appendonly.aof file and nodes.conf file
-
The design of caching key:
1: the maximum length is 1024 bytes, not too long, not too short, key comparison time-consuming
2: use schema to identify, such as com.payment.User:id
Binary safe characters: some special characters, such as escape symbols, will not be parsed
Redis key: binary secure, which means you can use any binary sequence as a key, from a string like foo to the contents of a jpeg file. An empty string is also a legitimate key
A few other rules for key:
1: very long key is not a good idea. 1024byte's key is not good.
2: too short key is not good.
Data type
Data type:
String: the most basic data type, which is binary safe, means that Redis strings can contain any type of data
A string value can be up to 512m
1: you can use String as an atomic counter and INCR,DECR,INCRBY
2: string append, use APPEND command
3: use a string as a random access vector
4: encode a large amount of data and compress it into a small space
List: sort by insertion order. Head or tail tail,left or right
The maximum length of list is 2 to the power of 32-1
The main function of redis's list is to support constant time insertion and deletion of header and tail elements. Even if a lot of inserted data
Accessing the elements on both sides is very fast, but it will be slow if you want to access the elements in the middle, which is an O (N) operation.
Main uses:
1: build a social network timeline model, use lpush insert, and then use lrange to get a small amount of recently inserted data
2: you can use lpush and ltrim to create a list that never exceeds a given number, but keep in mind the latest N elements.
3:list can be used as the original message delivery
4: you can do a lot of content.
Set: an unsorted collection of strings that executes O (1).
Redis Set does not allow duplicate members, adding the same member will result in a separate copy. In effect, it means that adding a member does not need to check whether it already exists.
You can do federation operations on the server side
The length of set is 2 to the 32-1.
Main uses:
1: you can track unique content, for example, if you want to know the unique ip address of all posts, simply use SADD to process a page, which ensures that there are no duplicate ip additions.
2: it can identify the association relationship very well. You can create a tagging system. This adds the id of all objects with the specified label to the collection.
3: you can use set to extract elements, spop,srandmember
Hash: a map type, field, and value that represents an object, such as user:1 userObj
A hash with a small number of fields can be stored with very little space. So that millions of objects can be stored in a small instance of redis Hash is mainly used to identify objects, they can store many elements, so you can use hash to save other content
Each hashkey storage 2 to the power of 32-1 key-value pair, more than 400 million pairs
Persistence
Redis provides persistence options:
1:RDB: perform a snapshot at a point in time
2:AOF: record all writes received by the server, which can be re-performed when the server is restarted to construct the original dataset. Use the append method. Redis can be rewritten in the background when the log is large.
3: persistence can be disabled, and data exists only when the server is running
4: combine AOF,RDB in the same instance. In this case, when redis is restarted, the AOF file is used to construct the original data.
Advantages of RDB:
1:RDB is a very compact stand-alone file that represents redis data at a certain point in time. Rdb files are preferred for backup. For example, you can compress your RDB file every hour and save a snapshot of RDB every day. This makes it easy to recover different versions of the data.
2:RDB is a very good disaster recovery, as a separate compressed file, can be transferred to the data center
3:RDB maximizes the performance of redis because the redis parent process only needs to allocate, while the child process does the rest.
4:RDB allows quick startup, while AOF does not
Disadvantages of RDB:
1: if you need as little data loss as possible, RDB is not a good way. You need to configure many Savepoints to ensure less data loss.
2:RDB requires frequent fork to enable child processes to persist data.
Advantages of AOF:
1: using AOF,redis for more persistence, you can use different fsync policies. With these fsync policies, every second write execution is saved in a daemon.
2:AOF is an append log only
3:redis can automatically rewrite when the AOF file is too large, so it is safe to rewrite.
4:AOF contains logs of all operations
Disadvantages of AOF:
1:AOF files are larger than RDB files
2:AOF is slower than RDB, and fsync policy executes records once a second.
3:bug
Distributed unique ID
41bit storage time: accurate to milliseconds
ID of 12bit storing node shards: the maximum value is 4095
Self-adding ID for 10bit storage:
For example, GTM time Fri Mar 13 10:00:00 CST 2015, its millisecond from 1970 is 1426212000000, assuming that the shard ID is 53 and the self-growing sequence is 4, the resulting ID is:
5981966696448054276 = 1426212000000
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.