jedis

java链接redis服务器

独自空忆成欢 提交于 2020-01-02 05:09:53
1.首先你需要下载驱动包jedis.jar确保下载最新驱动包。 2.public class RedisUtil { //服务器IP地址 private static String ADDR = "192.168.41.65"; //端口 private static int PORT = 6379; //密码 private static String AUTH = "123456"; //连接实例的最大连接数 private static int MAX_ACTIVE = 1024; //控制一个pool最多有多少个状态为idle(空闲的)的jedis实例,默认值也是8。 private static int MAX_IDLE = 200; //等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException private static int MAX_WAIT = 10000; //连接超时的时间   private static int TIMEOUT = 10000; // 在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的; private static boolean TEST_ON_BORROW = true;

redis 入门

左心房为你撑大大i 提交于 2020-01-02 01:24:44
(一)安装 redis官方下载安装链接: https://redis.io/download 按照官网的来总流程上是没问题的。不过我本地还是有点小问题。 1、到你想安装的目录 下 $ wget http://download.redis.io/releases/redis-3.2.8.tar.gz $ tar xzf redis-3.2.8.tar.gz $ cd redis-3.2.8 $ make 我的本地到make这就不行了,开始报错:提示缺少cc $ yum -y install gcc 继续make,此时还是报错 $ make CFLAGS="-march=x86-64" 再make,就ok了。 下面按官网的启动服务 $ src/redis-server (二)java通过Jedis来操作 这里说下我的环境:测试java连接是在我windows本地,redis装在我的虚拟机上 package test.com.redis; import redis.clients.jedis.Jedis; public class RedisDemo { public static void main(String[] args) { Jedis jedis = new Jedis("10.99.8.166",6379); // Jedis jedis = new Jedis("10

Redis Java客户端Jedis入门

一世执手 提交于 2020-01-02 01:23:58
Linux下redis的安装及运行可以参考随笔( redis入门与安装 ) 一、jedis下载 在 https://github.com/xetorthio/jedis/downloads 上下载jedis-2.0.0.jar 二、将jedis-2.0.0.jar放入eclipse\plugins的目录中 打开Window->Preferences->Java->Install JREs 在jre6->Edit->Add External JARs把eclipse\plugins\jedis-2.0.0.jar添加进来。 三、进入 Maven生成Helloworld 编辑pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.marshal</groupId> <artifactId>helloworld<

使用jedis操作redis

蓝咒 提交于 2020-01-02 01:23:35
首先来简单介绍一下jedis,其实一句话就可以概括的,就是java操作redis的一种api。我们知道redis提供了基本上所有常用编程语言的clients,大家可以到 http://redis.io/clients 上面去查看,包含C,C++,C#等等。 1、download jedis的源码: https://github.com/xetorthio/jedis/releases/tag/jedis-2.1.0 ,jedis采用的是git托管的,这边使用的是2.1.0版本; 2、解压打开可以看到,jedis采用的是maven构建工程的,所以我们的开发工具最好能支持maven工程,关于maven工程的支持,这边就不介绍了,大家可以去网上查找,或者查看本人写的关于maven的博文,之所以要选择maven工程呢,是为了更好的去查看jedis的源码。 3、eclipse导入jedis工程,在Package Exploer右键Import,选择maven工程 点击Finish即可完成导入工作,工程结构如下: 4、完成基本连接操作 修改pom.xml文件,将此处的localhost修改为自己的redis server IP <properties> <redis-hosts>192.168.2.105:6379,192.168.2.105:6380</redis-hosts> <

jvm-序列化优化以及redis中的使用。

孤者浪人 提交于 2020-01-02 00:21:30
自定义持久化 jvm-Serialization jvm优化。 优点,序列化时间短,转换后空间小。压缩空间大概为jvm自带Serialization 的1/5-1/10 压缩速度提高几倍。提高序列化性能。 maven依赖 <!--prostuff序列化依赖 --> <dependency> <groupId>com.dyuproject.protostuff</groupId> <artifactId>protostuff-core</artifactId> <version>1.0.8</version> </dependency> <dependency> <groupId>com.dyuproject.protostuff</groupId> <artifactId>protostuff-runtime</artifactId> <version>1.0.8</version> </dependency> 实现代码 //引用路径 import com.dyuproject.protostuff.LinkedBuffer; import com.dyuproject.protostuff.ProtostuffIOUtil; import com.dyuproject.protostuff.runtime.RuntimeSchema; import redis.clients

Redis - How the key HASH and SET and ZSET are related on the CrudRepository save?

元气小坏坏 提交于 2020-01-01 19:58:35
问题 I am new to Redis and developing code using Spring Boot + Spring Data Redis example. When I saved the records, I see KEYS gets created and out of these keys 4 are HASH , 1 ZSET and all others are SET . I did not see in the Spring docs, meaning of each KEY is getting saved. . 127.0.0.1:6379> KEYS * 1) "persons:c5cfd49d-6688-4b83-a9b7-be55dd1c36ad" 2) "persons:firstname:bran" 3) "persons:39e14dae-fa23-4935-948f-1922d668d1c2" 4) "persons:f0b6dd26-8922-4a36-bd2a-792a17dddff7" 5) "persons:address

Connect Redis cluster with jedis

安稳与你 提交于 2020-01-01 10:05:18
问题 Since a single redis instance doesn't meet my requirements, I went for redis cluster. I formed cluster with three nodes and populated data into the cluster. When I get data from cluster using JedisCluster it takes more time than the single instance. So, what's the proper way to connect jedis with redis cluster. How can I make use of connection pool to connect jedis with redis cluster? 回答1: It's normal that you observe latency when you retrieve datas in a jedis cluster depending of the

Redis常见面试题

房东的猫 提交于 2019-12-31 23:44:52
1、什么是Redis?   Redis 是一个基于内存的高性能key-value数据库,不过在系统中一般充当高速缓存的角色。 2、为什么Redis需要把所有数据放到内存中?    访问内存的速度远高于访问硬盘的速度,如果不将数据放在内存中,磁盘I/O速度将严重影响Redis的性能。在内存越来越便宜的今天,Redis将会越来越受欢迎。 3、对Redis的访问为什么是单进程单线程的   Redis利用队列技术将并发访问变为串行访问,消除了传统数据库串行控制的开销。Redis的开发者认为Redis的性能瓶颈不在CPU,而是网络等因素。所以采取单线程的方式是最快的。单线程能够有效避免CPU切换的开销,另外I/O多路复用技术也有效的提升了访问速度。 4、Reids的特点(Redis的好处) 访问速度快。原因归结为三个方面:一是数据存储在内存中;二是对数据的访问是单线程操作,避免了不必要的IO开销;三是底层的数据结构合理,类似于hashMap,存取的时间复杂度为O(1)。 拥有丰富数据类型。支持string,list,hash ,set,sorted set五种类型 支持事务。拥有与传统数据库不同的独特的事务特性。在Redis中,一个事务中所有命令操作具有原子性 可以持久化缓存数据。拥有AOF和RDB两种持久化方式,保证系统重启数据不丢失 拥有成熟的可扩展,高可用的分布式解决方案。像Redis

Get Set value from Redis using RedisTemplate

大城市里の小女人 提交于 2019-12-31 09:03:31
问题 I am able to retrieve values from Redis using Jedis : public static void main(String[] args) { Jedis jedis = new Jedis(HOST, PORT); jedis.connect(); Set<String> set = jedis.smembers(KEY); for (String s : set) { System.out.println(s); } jedis.disconnect(); jedis.close(); } But when I am trying to use Spring's RedisTemplate , I am not getting any data. My data is stored in Redis as a Set . // inject the actual template @Autowired private RedisTemplate<String, Object> template; // inject the

Idea中使用Redis的Java客户端和Jedis

杀马特。学长 韩版系。学妹 提交于 2019-12-30 15:13:16
Jedis   导入依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> </parent> <groupId>com.my</groupId> <artifactId>redis_jedis01</artifactId> <version>1.0-SNAPSHOT</version> <name>redis_jedis01</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency>