jedis单机版应用
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单机版应用的更多相关文章
- Redis单机版以及集群版的安装搭建以及使用
1,redis单机版 1.1 安装redis n 版本说明 本教程使用redis3.0版本.3.0版本主要增加了redis集群功能. 安装的前提条件: 需要安装gcc:yum install g ...
- Java中Jedis操作Redis与Spring的整合
Redis是一个key-value存储系统.它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有序集合).这些数据类型都支持push/pop. ...
- 深入浅出Redis-Spring整合Redis
概述: 在之前的博客中,有提到过Redis 在服务端的一些相关知识,今天主要讲一下Java 整合Redis的相关内容. 下面是Jedis 的相关依赖: <dependency> <g ...
- redis客户端(三)
redis客户端 一.>redis自带的客户端 启动 启动客户端命令:[root@ming bin]# ./redis-cli -h xxx.xxx.xx.xxx-p 6379 注意: -h:指 ...
- 使用jedis客户端连接redis,单机版和集群版
单机版 1.入门实例 @Test public void testJedis(){ //创建一个jedis对象,需要指定服务的ip和端口号 Jedis jedis=new Jedis("19 ...
- Jedis测试redis
首先:Jedis是redis的java版本的客户端. public class JedisTest { //单机版测试Jedis,不使用连接池 @Test public void testJedis( ...
- Redis 一二事 - 在spring中使用jedis 连接调试单机redis以及集群redis
Redis真是好,其中的键值用起来真心强大啊有木有, 之前的文章讲过搭建了redis集群 那么咋们该如何调用单机版的redis以及集群版的redis来使用缓存服务呢? 先讲讲单机版的,单机版redis ...
- 十分钟搭建redis单机版 & java接口调用
本次单机版redis服务器搭建采用的包为redis-3.0.0.tar.gz,主要是记录下安装的心得,不喜勿喷! 一.搭建redis服务器单机版 1.上传redis-3.0.0.tar.gz到服务器上 ...
- redis集群配置,spring整合jedis,缓存同步
前台的商品数据(图片等加载缓慢)查询,先从redis缓存查询数据. redis是一个nosql数据库,内存版数据库,读取速度11w/s.本身具有内存淘汰机制,是单线程服务器(分时操作系统),线程安全. ...
随机推荐
- Java-Method类常用方法详解
一.Method类的定义Method类位于 java.lang.reflect 包中,主要用于在程序运行状态中,动态地获取方法信息二.Method类的常用方法 1.getAnnotatedRetur ...
- python内建的命名空间研究
python内建的命名空间研究 说明: python内置模块的命名空间.python在启动的时候会自动为我们载入很多内置的函数.类,比如 dict,list,type,print,这些都位于 __bu ...
- Vue-发布订阅机制(bus)实现非父子组件的传值
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JavaEE学习之JAXB
一.前言 JAXB——Java Architecture for XML Binding,是一项可以根据XML Schema产生Java类的技术.JAXB提供将XML实例文档反向生成Java对象树的方 ...
- Grafana+Prometheus打造全方位立体监控系统
前言 本文主要介绍如何使用Grafana和Prometheus以及node_exporter对Linux服务器性能进行监控.下面两张图分别是两台服务器监控信息: 服务器A 服务器B 概述 Promet ...
- Spring MVC数据绑定入门总结
1.基本类型 基本类型参数不可为空 正例:http://localhost:8080/demo/he?id=2 反例:http://localhost:8080/demo/he?id=(报400错误) ...
- TRIO-basic指令--函数FUNCTION
TRIO-basic支持函数(强类型)编程,与PLC来相比较的话类似于定义的功能块可以重复调用,和C,C#......等一些高级的编程语言的函数类似.上一次的demo中决定尝试TRIO的函数来做一些例 ...
- Django signals 信号作用及用法说明
参考:https://docs.djangoproject.com/en/1.11/ref/signals/ 1.Model signals django.db.models.signales 作用于 ...
- Python_装饰器进阶_32
#带参数的装饰器 #500个函数 import time FLAGE = True def timmer_out(flag): def timmer(func): def inner(*args,** ...
- 百度统计微信网站绑定(vue项目)
*网站域名:----- *网站首页:----/index.html 下列代码放入index.html vue加百度统计代码(亲测有效)