jedis

Redis学习笔记(四) Redis的java客户端jedis

落爺英雄遲暮 提交于 2019-12-25 10:04:24
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Jedis所需要的jar包 Commons-pool-1.6.jar Jedis-2.1.0.jar 用windows连接虚拟机的Redis的注意事项 禁用Linux的防火墙 redis.conf中注释掉bind 127.0.0.1 ,然后 protect-mode no Jedis测试连通性 /** * @author Sun.Mr * @create 2019-12-24 17:31 */ public class Test { public static void main(String[] args) { Jedis jedis = new Jedis("47.105.154.78",6379); String result =jedis.ping(); System.out.println(result); } } 测试部分API public static void main(String[] args) { Jedis jedis = new Jedis("47.105.154.78",6379); String result =jedis.ping(); //keys (*) Set<String> keys = jedis.keys("*"); for (Iterator iterator =

Spring整合Redis

断了今生、忘了曾经 提交于 2019-12-25 08:41:08
目录 1、准备依赖Jar包 2、Spring-redis.xml 中的配置 3、service代码编写 4、RedisTemplateTest测试代码编写 前言 Spring整合Redis的环境可以使用搭建好的ssm环境下进行构建,方(懒)便(人)快(专)捷(用),首推! @ 1、准备依赖Jar包 <!-- ================ spring 整合 Redis================== --> <!-- 1、java连接Redis的jar包,也就是使用jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.4.2</version> </dependency> <!-- 2、spring整合Redis的jar包 --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.4.2.RELEASE</version> </dependency> 1.1、Jedis概述 是的,在上面使用到了Jedis的jar包,这里简单介绍一下Jedis。

Getting values with jedis pipeline

不问归期 提交于 2019-12-24 15:15:28
问题 I have a list of ids that I want to use to retrieve hashes from a Redis server using the java client jedis. As mentioned in the documentation, Jedis provides a way to use the pipeline by declaring Response objects and then sync the pipeline to get values: Pipeline p = jedis.pipelined(); p.set("fool", "bar"); p.zadd("foo", 1, "barowitch"); p.zadd("foo", 0, "barinsky"); p.zadd("foo", 0, "barikoviev"); Response<String> pipeString = p.get("fool"); Response<Set<String>> sose = p.zrange("foo", 0,

java连接redis集群

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 11:39:21
http://m.blog.csdn.net/koushr/article/details/50956870 连接redis数据库(非集群模式) public static void main(String[] args) { JedisPoolConfig poolConfig = new JedisPoolConfig(); // 最大连接数 poolConfig.setMaxTotal(2); // 最大空闲数 poolConfig.setMaxIdle(2); // 最大允许等待时间,如果超过这个时间还未获取到连接,则会报JedisException异常: // Could not get a resource from the pool poolConfig.setMaxWaitMillis(1000); JedisPool pool = new JedisPool(poolConfig, "192.168.83.128", 6379, 0, "123"); Jedis jedis = null; try { for (int i = 0; i < 5; i++) { jedis = pool.getResource(); jedis.set("foo" + i, "bar" + i); System.out.println("第" + (i + 1) + "个连接,

spring server cannot connect to redis using jedis client

淺唱寂寞╮ 提交于 2019-12-24 09:50:00
问题 I am getting this issue when I deploy redis server and spring server in two different servers and try to connect to spring server through my application. App Details: We have mobile application which publish gps coordinates to spring server using stomp. In the spring server we create jedis pubsub connection and publish those gps data to our web application and web users subscribe to those jedis pubsub connections. Library versions: stomp:1.7.1 jedis: 2.8.1 spring: 4.3.0 Working scenarios:

使用redis存取数据

旧街凉风 提交于 2019-12-24 00:56:24
1.首先到网站上 redis下载版本 下载redis并进行安装,目录如下: 2.启动redis 具体启动参考我上篇博客。 3.运行java或python存取数据 java存数据(项目需要导入两个jar包:commons-pool2-2.4.2.jar和jedis-2.9.0.jar,链接为:https://pan.baidu.com/s/1BNotwQyIU4NqAkGNRcx8Zw,提取码:g1qb): package redis; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; public class testRedis1 { public static void main(String[] args) { // 连接本地的 Redis 服务 //Jedis jedis = new Jedis("10.80.248.22"); // 默认端口 Jedis jedis = new Jedis("localhost",6379); // 指定端口 // jedis.auth("pass") // 指定密码 System.out.println("Connection to server sucessfully"); // 设置 redis 字符串数据 jedis.set("redis"

Jedis Changing the semantics of Redis?

 ̄綄美尐妖づ 提交于 2019-12-23 19:02:15
问题 So, Redis specify the zrange (and related sorted set commands) as an ORDERED set of results (a list without duplicates perhaps?). Why then the zrange (and related APIs) on Jedis (Official and Recommended REDIS client) return a Set??? Which has, by definition, no concept of ordering? That is a direct violation of the semantics of the redis operations. This is the zrange jedis 2.0.0 implementation: public Set<byte[]> zrange(final byte[] key, final int start, final int end) { checkIsInMulti();

Split a Redis big ZSET

孤街醉人 提交于 2019-12-23 04:29:18
问题 We hava a Redis key. It's a ZSET structure named test_key . The key is userId like 123 , 456 , 789 .The score is time stamps like 1474194838 , 1474194839 . Its length reached fifty million. We want to split it, just like test_key_1 , test_key_2 , test_key_3 . How to split it that can make the CRUD more easy? We are java developer. The most frequently used Redis commodity is zadd , zrem , zrange , zrangeByscore , zrangeByscoreWithScores , zcard and so on. 回答1: If you have to split the data

How to resume hash slots of a particular node in redis cluster in case of hard failure?

青春壹個敷衍的年華 提交于 2019-12-23 03:47:13
问题 So I am testing out the redis cluster. I have a setup with 3 masters and 3 slaves. Now, in case a node faces hard-failure (both master and slave go down), the cluster is still functional, barring the hash slots served by the failed node. Now, while testing such a scenario, I see that reads/writes that operate on keys served by these hash slots fail with exceptions, which is fine (I'm using jedis btw). However, if I am using redis cluster as a cache, I would like these hash slots to be served

How to read erlang term from redis by using java client?

ε祈祈猫儿з 提交于 2019-12-23 02:25:13
问题 e.g. I save the tuple T = {k1, v1, k2, v2} to the redis by jedis: eredis:q(Conn, ["SET", <<"mykey">>, term_to_binary(T)]). I am trying to use the code below to read this erlang term: Jedis j = Redis.pool.getResource(); byte[] t = j.get("mykey").getBytes(); OtpInputStream ois = new OtpInputStream(t); System.out.println(OtpErlangObject.decode(ois)); The error is: com.ericsson.otp.erlang.OtpErlangDecodeException: Uknown data type: 239. So how can I get the erlang term correctly? Erlang side: