Beijing Taobao project day15


1. Redis cluster description

1.1 what are the disadvantages of fragmentation / sentry

1. Fragmentation disadvantage: the main function of fragmentation is to expand memory, but it has no high availability effect
2. Disadvantages of sentry: the data is not expanded, and the sentry itself has no high availability mechanism
Requirements: it can not only realize the expansion of memory, but also realize the high availability mechanism (without a third party)

1.2 redis cluster construction

1.2.1 description of redis cluster construction

1. First shut down all redis servers
Beijing Taobao project day15

2. Check whether the configuration file is edited correctly
3. Delete redundant configuration files
Beijing Taobao project day15

4. Restart the redis server
Beijing Taobao project day15

5. Build a redis cluster

redis-cli --cluster create --cluster-replicas 1

1.3 introduction to cluster

    public void testCluster(){
        Set<HostAndPort> sets = new HashSet<>();
        sets.add(new HostAndPort("", 7000));
        sets.add(new HostAndPort("", 7001));
        sets.add(new HostAndPort("", 7002));
        sets.add(new HostAndPort("", 7003));
        sets.add(new HostAndPort("", 7004));
        sets.add(new HostAndPort("", 7005));
        JedisCluster jedisCluster = new JedisCluster(sets);
        Jediscluster.set ("jedis", "cluster assignment");

1.4 interview questions

1. A total of 16384 keys can be stored in the redis cluster?? incorrect
A: 16384 is just the number of slots. It is only responsible for planning who manages the data. How to store the data is determined by redis memory
2. How many hosts can there be in a redis cluster? 16384 main engine
3. If multi-threaded operation is encountered in redis, is there a thread safety problem? No,
Because: redis server is a single process and single thread operation. Each operation is executed by one thread, so there will be no thread safety problem
4. How does redis optimize memory data? LRU / LFU / random algorithm / TTL

1.5 integration of redis cluster with springboot

1.5.1 edit the properties file

Note: write the nodes of the redis cluster into the pro configuration file

#Configure a single redis server

##Configure redis fragmentation

#Redis cluster configuration

1.5.2 edit configuration class

package com.jt.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

@Configuration // identifies me as a configuration class
public class RedisConfig {

    //Redis cluster operation
    private String nodes;   //node,node,node

    public JedisCluster jedisCluster(){
        Set<HostAndPort> nodeSet = new HashSet<>();
        String[] nodeArray = nodes.split(",");
        for (String node : nodeArray){ //host:port
            String host = node.split(":")[0];
            int port = Integer.parseInt(node.split(":")[1]);
            nodeSet.add(new HostAndPort(host,port));
       return new JedisCluster(nodeSet);

   /* *//**
     *Springboot integrates redis fragmentation, in essence: shardedjedis objects, which are managed by containers
    private String nodes;   //node,node,node

    public ShardedJedis shardedJedis(){
        List<JedisShardInfo> shards = new ArrayList<>();
        String[] nodeArray = nodes.split(",");
        for(String node : nodeArray){ //node=ip:port
            String host = node.split(":")[0];
            int port = Integer.parseInt(node.split(":")[1]);
            //Prepare fragment node information
            JedisShardInfo info = new JedisShardInfo(host,port);
        return new ShardedJedis(shards);

   /* @Value("${}")
    private String host;
    private Integer port;

    public Jedis jedis(){
        return new Jedis(host,port);

1.5.3 edit AOP configuration

Inject redis cache object into AOP
Beijing Taobao project day15

2. Construction of Jingtao front desk project

2.1 composition design of Jingtao rack

Beijing Taobao project day15

2.2 jt-web project creation

2.2.1 create jt-web server

Beijing Taobao project day15

2.2.2 add Inheritance / dependency / Plug-in

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

    <!-- Project coordinates -- >
    <!-- Pack war -- >

    <!-- Parent project -- >

    <!-- Add dependency -- >

    <!-- 4. Add Maven plug-in -- >

2.2.3 importing static resource files

Note: import the file SRC directory in the pre class materials into JT web
Beijing Taobao project day15

2.2.4 description of main startup class

Note: the JT web server will load the automatic configuration of the data source when it is started, but the web server does not configure the data source, so an error is reported
Beijing Taobao project day15

Add data source on startup class
Beijing Taobao project day15

2.2.5 configure working directory

Beijing Taobao project day15

2.3 domain name reverse proxy

Requirements: users are required to pass Visit localhost: 8092 server

2.3.1 modifying the host file

Beijing Taobao project day15

2.3.2 modifying the nginx configuration file

#Configure foreground server
    server {
        listen 80;

        location / {
            proxy_pass http://localhost:8092;

After modification, restart the nginx server
Beijing Taobao project day15

2.3.3 page effect display

Beijing Taobao project day15

2.4 disable HTTPS in Google browser

Type the address:
Beijing Taobao project day15

After modification, empty the cache and restart the browser

2.5 enable suffix type matching

Note: because the commodities of Jingdong Mall are displayed through

URL address summary:
    one          The request will be intercepted by the controller
    two   By default, the request means to obtain the resource file and will not be intercepted
    Under normal conditions: the controller only intercepts prefix type requests. If it needs to intercept suffix type requests, it needs to be configured separately

3 jump to the login registration page

3.1 realize general page Jump

url1:      Jump to page login.jsp
url2:   Jump to page register.jsp

Requirement: can you use a controller method to jump to a general page?

package com.jt.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

public class UserController {

     *Jump to user login / registration page
     * url1:
     * url2:
    public String module(@PathVariable String moduleName){

        return moduleName;


3.2 embodiment of pseudo static

Pseudo static is relative to real static,Usually we want to enhance the friendliness of search engines, the article content will be generated into static pages, but some friends want to display some information in real time. Or you want to use dynamic scripts to solve some problems. You can’t display the website content in a static way. But this loses the friendliness to the search engine. How to find an intermediate method between the two, which is producedPseudo static technique。 Pseudo static technology shows that it is in the form of static pages such as HTML, but it is actually handled by dynamic scripts such as ASP.

Summary: a form of dynamic page ending in. HTML


1. Preview what is cross domain?

1. Jsonp 2. CORS mode