那么如何才能正确的掌握Redis呢?
为了让大家能够在Redis上能够加深,所以这次给大家准备了一些Redis的学习资料,还有一些大厂的面试题,包括以下这些面试题
-
并发编程面试题汇总
-
JVM面试题汇总
-
Netty常被问到的那些面试题汇总
-
Tomcat面试题整理汇总
-
Mysql面试题汇总
-
Spring源码深度解析
-
Mybatis常见面试题汇总
-
Nginx那些面试题汇总
-
Zookeeper面试题汇总
-
RabbitMQ常见面试题汇总
JVM常频面试:
Mysql面试题汇总(一)
Mysql面试题汇总(二)
Redis常见面试题汇总(300+题)
官方推荐使用zookeeper作为注册中心。
(1)Zookeeper介绍
下图是zookeeper在dubbo所处的位置:
注册中心负责服务地址的注册与查找,相当于目录服务,服务提供者在启动时与注册中心交互,消费者不断的发起请求获取服务信息,注册中心不转发请求,压力较小。使用dubbo-2.3.3以上版本,建议使用zookeeper注册中心。
Zookeeper是Apacahe Hadoop的子项目,是一个树型的目录服务,支持变更推送,适合作为Dubbo服务的注册中心,工业强度较高,可用于生产环境,并推荐使用
Zookeeper:
1、可以作为集群的管理工具使用,和注册中心。
2、可以集中管理配置文件。
(2)Zookeeper安装到linux当中
a、下载Zookeeper
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0.tar.gz
b、在Linux当中安装Zookeeper
Zookeeper是java开发的,可以运行在windows、linux环境。
需要先安装jdk(课前资料的虚拟机,已经安装好JDK)
c.移动到/usr/local
[root@itcast-01 ~]# mv zookeeper-3.4.6.tar.gz /usr/local/
d.解压
[root@itcast-01 local]# tar -zxvf zookeeper-3.4.6.tar.gz
e.进入解压目录,创建data
[root@itcast-01 local]# cd zookeeper-3.4.6
[root@itcast-01 zookeeper-3.4.6]# mkdir data
f.进入conf目录,把zoo_sample.cfg复制一份叫zoo.cfg
[root@itcast-01 zookeeper-3.4.6]# cd conf/
[root@itcast-01 conf]# cp zoo_sample.cfg zoo.cfg
g.修改修改zoo.cfg
[root@itcast-01 conf]# vim zoo.cfg
修改属性:
dataDir=/usr/local/zookeeper-3.4.6/data
(新建的data目录所在的位置)
h.进入bin目录启动zookeeper
[root@itcast-01 bin]# pwd
/usr/local/zookeeper-3.4.6/bin
[root@itcast-01 bin]# ./zkServer.sh start
查看状态:[root@localhost bin]# ./zkServer.sh status
注意:zookeeper使用2181端口号,为了能正常使用zookeeper,我们需要打开2181端口号,或者关闭防火墙
关闭防火墙:[root@itcast-01 bin]# service iptables stop
/usr/local/apache-zookeeper-3.7.0/data
1、添加dobbo的依赖
a、service层:加入dobbo相关的jar包。服务层、表现层都添加。
com.alibaba
dubbo
org.springframework
spring
org.jboss.netty
netty
org.apache.zookeeper
zookeeper
com.github.sgroschupf
zkclient
上面当中默认依赖旧版本的spring需要排除旧版的spring的jar
b、web层:加入dobbo相关的jar包
2、整合思路
3、创建整合的xml文件
service当中
a、创建目录
b、mybatis当中创建SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>c、applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”
xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<context:property-placeholder location=“classpath:properties/*.properties” />
<bean id=“dataSource” class=“com.alibaba.druid.pool.DruidDataSource”
destroy-method=“close”>
d、dao当中定义包
e、dao当中定义资源文件bd.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
1、创建配置文件
a、applicationContext-service.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”
xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”
xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
创建包结构taotao-manager-interface当中创建com.taotao.service
b、applicationContext-transaction.xml
<beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:context=“http://www.springframework.org/schema/context” xmlns:p=“http://www.springframework.org/schema/p”
xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<bean id=“transactionManager”
class=“org.springframework.jdbc.datasource.DataSourceTransactionManager”>
<tx:advice id=“txAdvice” transaction-manager=“transactionManager”>
tx:attributes
<tx:method name=“save*” propagation=“REQUIRED” />
<tx:method name=“insert*” propagation=“REQUIRED” />
<tx:method name=“add*” propagation=“REQUIRED” />
<tx:method name=“create*” propagation=“REQUIRED” />
<tx:method name=“delete*” propagation=“REQUIRED” />
<tx:method name=“update*” propagation=“REQUIRED” />
<tx:method name=“find*” propagation=“SUPPORTS” read-only=“true” />
<tx:method name=“select*” propagation=“SUPPORTS” read-only=“true” />
<tx:method name=“get*” propagation=“SUPPORTS” read-only=“true” />
</tx:attributes>
</tx:advice>
aop:config
<aop:advisor advice-ref=“txAdvice”
pointcut=“execution(* com.taotao.service..(…))” />
</aop:config>
c、配置web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns=“http://java.sun.com/xml/ns/javaee”
xsi:schemaLocation=“http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”
version=“2.5”>
taotao-manager-service
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
contextConfigLocation
classpath:spring/applicationContext-*.xml
org.springframework.web.context.ContextLoaderListener
1、相关配置文件
springmvc.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:p=“http://www.springframework.org/schema/p”
xmlns:context=“http://www.springframework.org/schema/context”
xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo”
xmlns:mvc=“http://www.springframework.org/schema/mvc”
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan
base-package=“com.taotao.controller” />
<mvc:annotation-driven />
<bean
class=“org.springframework.web.servlet.view.InternalResourceViewResolver”>
创建对应的包结构
创建对应的jsp文件夹
在WEB-INF当中配置Servlet
2、dao层创建对应的接口对应的映射文件
a、创建对应的接口
package com.taotao.mapper;
/*
- 测试接口查询当前的时间
*/
public interface TestMapper {
public String queryNow();
}
b、创建对应的接口的映射文件TestMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>select NOW()
3、interface层创建对应的接口对应的映射文件
package com.taotao.service;
/*
- 测试接口查询当前的时间
*/
public interface TestService {
public String queryNow();
}
4、service层TestServiceImpl实现TestService接口
package com.taotao.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.taotao.mapper.TestMapper;
import com.taotao.service.TestService;
@Service
public class TestServiceImpl implements TestService {
@Autowired
private TestMapper mapper;
@Override
public String queryNow() {
// 1.注入mapper
// 2、调用mapper方法返回
return mapper.queryNow();
}
}
1、配置dubbo
<dubbo:application name=“taotao-manager” />
<dubbo:registry protocol=“zookeeper” address=“192.168.25.128:2181” />
<dubbo:protocol name=“dubbo” port=“20880” />
<dubbo:service interface=“com.taotao.service.TestService” ref=“testServiceImpl” />
2、applicationContext-service.xml
<dubbo:application name=“taotao-manager” />
<dubbo:registry protocol=“zookeeper” address=“115.159.79.135:2181” />
<dubbo:protocol name=“dubbo” port=“20880” />
<dubbo:service interface=“com.taotao.service.TestService” ref=“testServiceImpl” />
3、创建控制层相关内容
a、springmvc.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:p=“http://www.springframework.org/schema/p”
xmlns:context=“http://www.springframework.org/schema/context”
xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo”
xmlns:mvc=“http://www.springframework.org/schema/mvc”
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan
base-package=“com.taotao.controller” />
<mvc:annotation-driven />
<bean
class=“org.springframework.web.servlet.view.InternalResourceViewResolver”>
<dubbo:application name=“taotao-manager-web”/>
<dubbo:registry protocol=“zookeeper” address=“192.168.25.128:2181”/>
<dubbo:reference interface=“com.taotao.service.TestService” id=“testService” />
b、创建TestController
启动服务的消费者
访问项目
http://localhost:8081/test/queryNow
运行报错
没有找到对应的类
在taotao-manager-dao\pom.xml当中配置一个插件
src/main/java
**/*.properties
**/*.xml
false
改好后需要选择taotao-manager-dao工程执行
run as maven install
(一)显示后台页面
1、引入逆向工程
逆向工程下载地址和页面下载:
链接: https://pan.baidu.com/s/1W2s0mNdEr5G-D-_WwmSztw 提取码: 3y73
2、运行逆向工程
生成对应的文件
3、将生成的内容拷贝到当前自己的工程当中
4、引入页面
放置在WEB-INF当中
页面代码下载地址:
链接: https://pan.baidu.com/s/1BuzcPiNd0E1_urtmHCvJjw 提取码: 18u4
5、资源映射的配置
由于在web.xml中定义的url拦截形式为“/”表示拦截所有的url请求,包括静态资源例如css、js等。
所以需要在springmvc.xml中添加资源映射标签:
<mvc:resources location=“/WEB-INF/js/” mapping=“/js/**”/>
<mvc:resources location=“/WEB-INF/css/” mapping=“/css/**”/>
6、创建控制层PageController
package com.taotao.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/*
- 显示页面
*/
@Controller
public class PageController {
@RequestMapping(“/”)
public String showIndex() {
return “index”;
}
}
删除创建web的时候自动生成的index.jsp
7、运行项目
8、访问项目
http://localhost:8081/
(二)显示商品列表
完结
Redis基于内存,常用作于缓存的一种技术,并且Redis存储的方式是以key-value的形式。Redis是如今互联网技术架构中,使用最广泛的缓存,在工作中常常会使用到。Redis也是中高级后端工程师技术面试中,面试官最喜欢问的问题之一,因此作为Java开发者,Redis是我们必须要掌握的。
Redis 是 NoSQL 数据库领域的佼佼者,如果你需要了解 Redis 是如何实现高并发、海量数据存储的,那么这份腾讯专家手敲《Redis源码日志笔记》将会是你的最佳选择。
tps://img-blog.csdnimg.cn/20210421155744482.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NzU3MDM0,size_16,color_FFFFFF,t_70)
7、运行项目
8、访问项目
http://localhost:8081/
(二)显示商品列表
完结
Redis基于内存,常用作于缓存的一种技术,并且Redis存储的方式是以key-value的形式。Redis是如今互联网技术架构中,使用最广泛的缓存,在工作中常常会使用到。Redis也是中高级后端工程师技术面试中,面试官最喜欢问的问题之一,因此作为Java开发者,Redis是我们必须要掌握的。
Redis 是 NoSQL 数据库领域的佼佼者,如果你需要了解 Redis 是如何实现高并发、海量数据存储的,那么这份腾讯专家手敲《Redis源码日志笔记》将会是你的最佳选择。
[外链图片转存中…(img-djvnEnuN-1715293251798)]