需要的jar包

spring-data-Redis-1.6.2.RELEASE.jar

jedis-2.7.2.jar(依赖 commons-pool2-2.3.jar)

commons-pool2-2.3.jar

spring-redis.xml 配置文件

xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"

xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/util

http://www.springframework.org/schema/util/spring-util-3.0.xsd">

测试代码

import java.util.HashMap;

import java.util.Map;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import org.springframework.data.redis.core.HashOperations;

import org.springframework.data.redis.core.ListOperations;

import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.data.redis.core.ValueOperations;

public static void main(String[] args) {

ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext("spring-redis.xml");

final RedisTemplate redisTemplate = appCtx.getBean("redisTemplate",RedisTemplate.class);

//添加一个 key

ValueOperations value = redisTemplate.opsForValue();

value.set("lp", "hello word");

//获取 这个 key 的值

System.out.println(value.get("lp"));

//添加 一个 hash集合

HashOperations hash = redisTemplate.opsForHash();

Map map = new HashMap();

map.put("name", "lp");

map.put("age", "26");

hash.putAll("lpMap", map);

//获取 map

System.out.println(hash.entries("lpMap"));

//添加 一个 list 列表

ListOperations list = redisTemplate.opsForList();

list.rightPush("lpList", "lp");

list.rightPush("lpList", "26");

//输出 list

System.out.println(list.range("lpList", 0, 1));

//添加 一个 set 集合

SetOperations set = redisTemplate.opsForSet();

set.add("lpSet", "lp");

set.add("lpSet", "26");

set.add("lpSet", "178cm");

//输出 set 集合

System.out.println(set.members("lpSet"));

//添加有序的 set 集合

ZSetOperations zset = redisTemplate.opsForZSet();

zset.add("lpZset", "lp", 0);

zset.add("lpZset", "26", 1);

zset.add("lpZset", "178cm", 2);

//输出有序 set 集合

System.out.println(zset.rangeByScore("lpZset", 0, 2));

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

redis3.0 java spring_spring整合redis以及使用RedisTemplate的方法相关推荐

  1. redis3.0 java spring_Redis-3.0.6 集群部署集成SpringJava工程-----环境搭建

    注:本文所有操作都使用管理员权限 su root 输入密码 1.打开对应的端口- 既所有集群的端口号全部都打开 / 安装Jdk----暂时使用openJDK可行 /sbin/iptables -I I ...

  2. SpringBoot整合Redis - @Cacheable 和 RedisTemplate

    对之前网站做了一些很简单的优化,给用户列表加了一个分页功能. 分页就更好考虑加载速度,如果换一页就要等几秒,那体验感是非常差的. 因此想到了加一个redis缓存. springboot整合redis有 ...

  3. Java中使用Redis Hash的3种方法

    前言:    不用说Map是Java中最流行的数结构.Redis提供了一个与Java的Map结构非常相似的数据结构,它吸引了许多Java开发者的兴趣.已经有越来越多的Java库与Redis进行对话,其 ...

  4. redis java spring_spring配置redis(xml+java方式)(最底层)

    条件:引用好架包 org.springframework.data spring-data-redis 2.1.3.RELEASE redis.clients jedis 2.9.0 一.使用xml进 ...

  5. springboot整合redis,使用redisTemplate实现简易秒杀功能,使用jmeter压力测试秒杀接口

    项目结构 1.新建maven项目导入pom依赖 <parent><groupId>org.springframework.boot</groupId><art ...

  6. SpringBoot之整合Redis分析和实现-基于Spring Boot2.0.2版本

    一.背景介绍 公司最近的新项目在进行技术框架升级,基于的Spring Boot的版本是2.0.2,整合Redis数据库.网上基于2.X版本的整个Redis少之又少,中间踩了不少坑,特此把整合过程记录, ...

  7. redis3.0.2 编译安装 (启动服务方式启动)

    1.基础环境介绍: 操作系统:Centos 6.7 redis版本:3.0.2 2.开始安装: 1)基础安装 参考链接:http://309173854.blog.51cto.com/7370240/ ...

  8. redis3.0.2安装

    1:下载http://download.redis.io/releases/redis-3.0.2.tar.gz [root@web02 jifeng]# wget http://download.r ...

  9. redis3.0.3 安装与配置

    看到redis3版本已出最新 3.0.3 测试了一下它的集群功能. 1.安装: $ wget http://download.redis.io/releases/redis-3.0.3.tar.gz ...

最新文章

  1. 9、 Struts2验证(声明式验证、自定义验证器)
  2. oracle urlencode 中文,Python2和Python3中urllib库中urlencode的使用注意事项
  3. 总结—elasticsearch启动失败的几种情况及解决
  4. slc、mlc、tlc闪存芯片颗粒区别介绍
  5. Linux系统密码忘记修改方法
  6. My First Window构造过程,SendMessage同步,PostMessage异步
  7. 6 不更新无法使用_win10更新后无线网络无法使用
  8. 按一行一行的方法将一个文本文件复制到另一个文件中_命令行技巧:分割文件内容...
  9. 新手教程:不写JS,在MIP页中实现异步加载数据
  10. python 对象(一分钟读懂)03
  11. Java之品优购课程讲义_day09(2)
  12. java json.stringify_JSON.stringify 语法实例讲解
  13. 使用激活工具后主页被篡改为hao123
  14. 高通蓝牙耳机(QCC3034)Sink开发基础教程一:高通蓝牙方案介绍及开发环境搭建
  15. javascript有效的anagram挑战
  16. Linux—虚拟机下如何查看系统是多少位的?32 or 64
  17. [Eigen]Eigen的单位矩阵C++
  18. Windows常用快捷键及结束explorer.exe出现蓝屏的办法
  19. 【中国人口金字塔2019,python,pandas,matplotlib,numpy 】
  20. .NET平台开源项目速览(19)Power BI神器DAX Studio

热门文章

  1. edas部署需要哪些参数_强夯设计与施工中需要确定的主要技术参数有哪些
  2. [知识图谱构建] 一.Neo4j图数据库安装初识及药材供应图谱实例
  3. [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论
  4. 【数据结构与算法】之深入解析“矩形区域不超过K的最大数值和”的求解思路与算法示例
  5. 【数据结构与算法】之深入解析“组合总和III”的求解思路与算法示例
  6. PyTorch 加载超大 Libsvm 格式数据
  7. 无人机飞控开发平台培训理论课程——MSP430最小系统
  8. 【C/C++9】天气APP:Oracle的虚表/日期/序列,索引/视图/链路/同义词,数据库高可用性
  9. 【Qt】QModbusDataUnit类
  10. 【Android】Android模拟器无法上网问题