Redis结合Spring的小demo

本文介绍了如何在Spring环境下使用Jedis客户端连接并操作Redis数据库。首先讲解了Redis配置文件中bind和protected-mode的设置,以允许外部访问。接着展示了添加Jedis的相关依赖,并提供了在applicationContext.xml中配置JedisDao的示例,以及IJedisDao接口和其实现类JedisDaoImpl的简单代码。最后,提到了JedisClientTestDemo的测试用例。
摘要由CSDN通过智能技术生成

Jedis Client是Redis官网推荐的一个面向java客户端,库文件实现了对redis各类API进行封装调用,通过这些API我们会非常方便的操作我们的Redis数据库。

1.注释掉绑定信息
在redis.conf的配置文件中bind配置的信息表示的是redis服务可以接收外部访问的地址,这个主要还是为了提高安全性,我们在学习阶段可以将这个信息直接注释掉,这样的话任意的外部ip地址都可以访问。bind是protected-mode配合使用的。

2.关闭保护模式
1、关闭protected-mode模式,此时外部网络可以直接访问
2、开启protected-mode保护模式,需配置bind ip或者设置访问密码
在这里插入图片描述

Jedis结合spring
依赖

	<dependencies>
		<dependency>
			<groupId>redis.clients</groupId>
			<artifactId>jedis</artifactId>
			<version>2.9.0</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.3.3.RELEASE</version>
		</dependency>
	</dependencies>

applicationContext.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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframewo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

偷偷学习被我发现

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值