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. jupyter notebook安装纪要

    本次教程使用python工具pip安装.更多安装方式请参考官网. 1.升级pip工具到最新 2.运行安装执行 pip install jupyter 3.安装中 4.更改工作目录 4.1获取配置文件路 ...

  2. Linux常用命令全称

    Linux常用命令全称 pwd:print work directory   打印当前目录 显示出当前工作目录的绝对路径 ps: process status(进程状态,任务管理器)    常用参数: ...

  3. centos 7 安装mqtt 修改用户名和密码

    我先新买个Centos 的系统 咱登录呢就用这个软件,主要是方便,可以少安装一些东西 根据自己的系统选择,上面的是32位的. 输入 root 回车 输入密码然后回车  输入的时候什么也不显示 输入 c ...

  4. HTML5事件

    Html5事件 contextmenu事件 用以表示何时应该显示上下文菜单,以便开发人员取消默认的上下文菜单而提供自定义的菜单. 由于此事件时冒泡的,因此可以为document指定一个事件处理程序,用 ...

  5. JAVA 最新 环境搭建(JDK 1.8 + Tomcat 9 + eclipse oxygen + mysql 5.7)

    一.JDK的安装与配置 1.从官网下载jdk,注意是jdk不是jre.jdk包里面包含了jre.最好从官网下载.传送门:http://www.oracle.com/technetwork/java/j ...

  6. BZOJ1969 航线规划

    给定一个无向图,每次删除一条边,求每次有多少关键边.一条边是关键边,当且仅当从1到n的所有路径都包含这条边.所有时刻图都联通. 考虑倒着做.相当于给一棵树,每次加一条边,这样树上这条边的两个端点间的路 ...

  7. PyCharm Debug 调试

    断点(breakpoint),表示标记一行的位置,当程序运行到该行代码的时候,会将程序暂时暂停,以便对该行代码进行分析. 编辑python脚本,debug.py def hello(): return ...

  8. 03-HTML之body标签

    body标签 HTML标签按作用主要分为两类:字体标签和排版标签 HTML标签按级别主要分为两类:文本级标签和容器级标签 文本级标签:p.span.a.b.i.u.em.文本标签里只能放文字.图片.表 ...

  9. python学习之第八篇——字典嵌套之字典中嵌套字典

    cities = { 'shanghai':{'country':'china','population':10000,'fact':'good'}, 'lendon':{'country':'eng ...

  10. 批量采集世纪佳缘会员图片及winhttp异步采集效率

    原始出处:http://www.cnblogs.com/Charltsing/p/winhttpasyn.html 最近老有人问能不能绕过世纪佳缘的会员验证来采集图片,我测试了一下,发现是可以的. 同 ...