1.pom文件添加依赖:

2.创建配置文件

创建单机版redisClient

代码:

package com.skymall.rest.dao.imp;

import org.springframework.beans.factory.annotation.Autowired;

import com.skymall.rest.dao.JedisClient;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; /**
* jedis单机版客户端 dao
* @ClassName: JedisClientSingle
* @Description: TODO
* @author
* @date 2018年3月22日 下午1:46:20
* @version V1.0
*/
public class JedisClientSingle implements JedisClient { @Autowired
private JedisPool jedisPool; @Override
public String get(String key) {
Jedis jedis = jedisPool.getResource();
String value = jedis.get(key);
jedis.close();
return value;
} @Override
public String set(String key, String value) {
Jedis jedis=jedisPool.getResource();
jedis.set(key, value);
jedis.close();
return null;
} @Override
public String hget(String hkey, String key) {
Jedis jedis= jedisPool.getResource();
String str=jedis.hget(hkey, key);
jedis.close();
return str;
} @Override
public long hset(String hkey, String key, String value) {
Jedis jedis= jedisPool.getResource();
long result=jedis.hset(hkey, key,value);
jedis.close();
return result;
} @Override
public long incr(String key) {
Jedis jedis= jedisPool.getResource();
long result=jedis.incr(key);
jedis.close();
return result;
} @Override
public long expire(String key, int second) {
Jedis jedis= jedisPool.getResource();
long result=jedis.expire(key, second);
jedis.close();
return result;
} @Override
public long ttl(String key) {
Jedis jedis= jedisPool.getResource();
long result=jedis.ttl(key);
jedis.close();
return result;
} @Override
public long del(String key) {
Jedis jedis=jedisPool.getResource();
long result=jedis.del(key);
jedis.close();
return result;
} @Override
public long hdel(String hkey, String key) {
Jedis jedis=jedisPool.getResource();
long result=jedis.hdel(hkey,key);
jedis.close();
return result;
} }

  

测试:

package com.skymall.rest.jedis;

import java.util.HashSet;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool; public class TestJedis { //测试jedis
// @Test
// public void testJedis(){
// //创建jedis对象
// Jedis jedis=new Jedis("192.168.203.137",6379);
// //与reids指令操作一至
// jedis.set("key1","88888888888888" );
// //删除
// Long del = jedis.del("cccc");
// //添加
//// String result=jedis.get("cccc");
// System.err.println(del);
// //关闭jedis对象
// jedis.close();
// } // 测试jedis连接池
// @Test
// public void testJedisPool(){
// //创建连接池
// JedisPool jedisPool=new JedisPool("192.168.203.137",6379);
// //从连接池里取jedis对象
// Jedis jedis = jedisPool.getResource();
// //一下操作都一样
// String result=jedis.get("ddd");
// System.err.println(result);
// //关闭jedis
// jedis.close();
// //关闭连接池
// jedisPool.close();
// }
//
//
// //测试redis集群(自带连接池)不需要关闭否则会报错
// @Test
// public void testJedisCluster(){
// HashSet<HostAndPort> nodes=new HashSet<>();
// nodes.add(new HostAndPort("192.168.203.137", 6001));
// nodes.add(new HostAndPort("192.168.203.137", 6002));
// nodes.add(new HostAndPort("192.168.203.137", 6003));
// nodes.add(new HostAndPort("192.168.203.137", 6004));
// nodes.add(new HostAndPort("192.168.203.137", 6005));
// nodes.add(new HostAndPort("192.168.203.137", 6006));
// JedisCluster cluster=new JedisCluster(nodes);
// cluster.set("key2","成功了");
// System.out.println(cluster.get("key2"));
//
//
// }
// //测试单机版jedis与spring整合
// @Test
// public void testJedisAndSpring(){
//
// ApplicationContext applicationContext=new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
// JedisPool jedisPool=(JedisPool) applicationContext.getBean("redisClient");
// Jedis jedis=jedisPool.getResource();
// jedis.set("gggg", "09090900");
// String str=jedis.get("gggg");
// System.out.println(str);
//
// jedis.close();
// jedisPool.close();
// }
//
// //测试jedis集群与spring整合
// @Test
// public void JedisClusterAndSpring(){
// ApplicationContext applicationContext=new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
// JedisCluster jedisCluster=(JedisCluster) applicationContext.getBean("redisClient");
// jedisCluster.set("name","8822288");
// String str=jedisCluster.get("name");
// System.out.println(str);
//
//
// }
}

  

jedis单机版应用的更多相关文章

  1. Redis单机版以及集群版的安装搭建以及使用

    1,redis单机版 1.1   安装redis n  版本说明 本教程使用redis3.0版本.3.0版本主要增加了redis集群功能. 安装的前提条件: 需要安装gcc:yum install g ...

  2. Java中Jedis操作Redis与Spring的整合

    Redis是一个key-value存储系统.它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有序集合).这些数据类型都支持push/pop. ...

  3. 深入浅出Redis-Spring整合Redis

    概述: 在之前的博客中,有提到过Redis 在服务端的一些相关知识,今天主要讲一下Java 整合Redis的相关内容. 下面是Jedis 的相关依赖: <dependency> <g ...

  4. redis客户端(三)

    redis客户端 一.>redis自带的客户端 启动 启动客户端命令:[root@ming bin]# ./redis-cli -h xxx.xxx.xx.xxx-p 6379 注意: -h:指 ...

  5. 使用jedis客户端连接redis,单机版和集群版

    单机版 1.入门实例 @Test public void testJedis(){ //创建一个jedis对象,需要指定服务的ip和端口号 Jedis jedis=new Jedis("19 ...

  6. Jedis测试redis

    首先:Jedis是redis的java版本的客户端. public class JedisTest { //单机版测试Jedis,不使用连接池 @Test public void testJedis( ...

  7. Redis 一二事 - 在spring中使用jedis 连接调试单机redis以及集群redis

    Redis真是好,其中的键值用起来真心强大啊有木有, 之前的文章讲过搭建了redis集群 那么咋们该如何调用单机版的redis以及集群版的redis来使用缓存服务呢? 先讲讲单机版的,单机版redis ...

  8. 十分钟搭建redis单机版 & java接口调用

    本次单机版redis服务器搭建采用的包为redis-3.0.0.tar.gz,主要是记录下安装的心得,不喜勿喷! 一.搭建redis服务器单机版 1.上传redis-3.0.0.tar.gz到服务器上 ...

  9. redis集群配置,spring整合jedis,缓存同步

    前台的商品数据(图片等加载缓慢)查询,先从redis缓存查询数据. redis是一个nosql数据库,内存版数据库,读取速度11w/s.本身具有内存淘汰机制,是单线程服务器(分时操作系统),线程安全. ...

随机推荐

  1. 在DreamView中支持一辆新车

    Support a new Vehicle in DreamView In order to support a new vehicle in DreamView, please follow the ...

  2. 2018-2019-2 20175310 实验二《Java面向对象程序设计》实验报告

    2018-2019-2 20175310 实验二<Java面向对象程序设计>实验报告 一.实验步骤及内容 (一).面向对象程序设计-1 参考 http://www.cnblogs.com/ ...

  3. 【Codeforces Round 650】Codeforces #334 (Div. 1)

    模拟CF650,ABC三题,RK90 Codeforces 650 A 思路:首先看式子 \(\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}=|x_i-x_j|+|y_i-y_j|\) ...

  4. AWS re:Invent(2019.01.09)

    时间:2019.01.09地点:北京国际饭店

  5. 如何编写.NET Core Global Tools (附两个案例)

    一.什么是 .NET Core Global Tools 2018年5月31日(北京时间)微软发布了 .NET Core 2.1 正式版,.NET Core 2.1 为我们带来了一个新的特性:.NET ...

  6. mybatis源码-解析配置文件(四-1)之配置文件Mapper解析(cache)

    目录 1. 简介 2. 解析 3 StrictMap 3.1 区别HashMap:键必须为String 3.2 区别HashMap:多了成员变量 name 3.3 区别HashMap:key 的处理多 ...

  7. [WPF]何如在Win7使用Aero2主题

    1. 问题 假设我在Windows10的环境新建一个4.6的WPF项目,添加一个ComboBox,并用Blend在这个ComboBox上右键"编辑模板"->"编辑副 ...

  8. 【Java面试宝典】深入理解JAVA虚拟机

    一.运行时数据区域 线程隔离:线程隔离的意思,就是给不同的线程多分配的资源用,以做到不争用. 线程共享:线程共享就是资源只有一个没有办法分配更多,只能共享. Java虚拟机管理的内存包括几个运行时数据 ...

  9. python三数之和

    给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三元组. ...

  10. 使用faker去构造一个User-Agent

    faker可以仿造各种各样的信息,可以使用faker去构造一个User-Agent from faker import Factory f = Factory.create() 'User-Agent ...