jedis

Redis behavior with multiple concurrent programs doing read/del on the same hash key

拥有回忆 提交于 2019-12-06 13:15:44
问题 I've a program ( program_1 ) (Jedis-based) that writes to a Redis HASH ( KEY_1 ) on a regular basis. I've another program ( program_2 ) (separate JVM process) that executes periodically, and in a Redis transaction does the following: Transaction transaction = redis.multi(); //get the current entity table Response<Map<String, String>> currentEntityTableResponse = transaction.hgetAll(KEY_1); transaction.del(KEY_1); transaction.exec(); My assumption is when program_2 has deleted the HASH (with

redis多实例&分片&jedis的使用

你离开我真会死。 提交于 2019-12-06 13:07:36
接下来学习redis多实例的部署、数据分片,以及jedis API的使用。 redis多实例部署 一般单个redis的进程是不能满足实际需求的,需要在单台服务器上部署多个redis进程,充分发挥cpu的效能,多台服务器上的redis进程将组成庞大的集群,多的一般部署达到数千个redis进程。 暂时不考虑高可用的情况,下面在一台centos6.5上部署三个redis实例,要想实现部署需要修改redis.conf文件,需要修改服务端口号、日志文件编号、rdb文件编号等,下面边查看常用配置边修改。 (1)units单位,定义了基本的度量单位,不区分大小写。 8 # Note on units: when memory size is needed, it is possible to specify 9 # it in the usual form of 1k 5GB 4M and so forth: 10 # 11 # 1k => 1000 bytes 12 # 1kb => 1024 bytes 13 # 1m => 1000000 bytes 14 # 1mb => 1024*1024 bytes 15 # 1g => 1000000000 bytes 16 # 1gb => 1024*1024*1024 bytes 17 # 18 # units are case

Jedis:Exception in thread \"main\" java.lang.VerifyError: Bad type on operand stack

会有一股神秘感。 提交于 2019-12-06 09:57:47
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack Exception Details: Location: com/test/tools/jedis/JedisTools.init()V @117: invokespecial Reason: Type 'redis/clients/jedis/JedisPoolConfig' (current frame, stack[2]) is not assignable to 'org/apache/commons/pool2/impl/GenericObjectPoolConfig' Current Frame: bci: @117 flags: { } locals: { 'com/test/tools/jedis/JedisTools', 'redis/clients/jedis/JedisPoolConfig', 'java/lang/String' } stack: { uninitialized 90, uninitialized 90, 'redis/clients/jedis/JedisPoolConfig', 'java/lang/String', integer, integer, 'java/lang/String'

Springboot2.x整合Redis以及连接哨兵模式/集群模式

a 夏天 提交于 2019-12-06 08:29:59
依赖: <!--spirngboot版本为2.x--> <!-- 加载spring boot redis包,springboot2.0中直接使用jedis或者lettuce配置连接池,默认为lettuce连接池,这里使用jedis连接池 --> <!-- 加载spring boot redis包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <!-- 排除lettuce包,使用jedis代替--> <exclusions> <exclusion> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> application.properties配置 ##配置redis的连接信息 #spring.redis

Cannot get Jedis connection; Could not get a resource from the pool

橙三吉。 提交于 2019-12-06 06:06:10
问题 I am running a batch job for every 5 minutes and I don't wanna other nodes to run the same job hence I am using Jedis lock to lock an object for 5 minutes. So that other node won't get the lock if they try to run the same job. Job started after acquiring the lock and when I try to read it from Redis I am getting the following exception saying 'Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool

Using jedis how to write to a specific slot/node in redis cluster

筅森魡賤 提交于 2019-12-06 06:03:45
I'm trying to improve the performance of writing data to redis cluster. We are planning to move from redi-sentinel to cluster mode for scalability. But, the performance of write operations is very less compared to redis-sentinel. We leveraged pipeline in redis-sentinel but cluster mode doesn't support pipeline. So, I was thinking to group all the keys that go to a same node and send the batch to that specific node using pipeline. So, I'm wondering how to know/compute (before writing to cluster) to which node/slot a particular key would be written to? Solution 1: Found a solution to identify

Redis应用学习——Redis Cluster客户端

大憨熊 提交于 2019-12-06 05:57:46
1. moved重定向 1. 客户端读写(get/set)操作执行过程:如果是一个普通的客户端连接到redis cluster中的任意一个节点,然后向该节点发送一条get/set命令,接收的节点首先会依据该key计算对应槽位,然后再找到槽位所在的节点,判断找到的节点是否是自身,如果是则在当前节点执行该命令,否则回复客户端moved异常,异常中包含真正执行命令的节点的信息,客户端需要使用获取到节点信息,重新连接获取到的节点并发送命令,但是该行为不是自动的,需要主动操作(如下图中第4步,该步骤需要在客户端通过专门编写逻辑代码执行);客户端依据返回的moved异常中的节点信息,进行的转移连接操作就是moved重定向 2. moved异常演示:首先启动集群,然后以普通模式的客户端连接到任意一个节点上,进行set/get操作,linux中普通模式的客户端对应Java中的Jedis客户端 2. 可自动进行moved重定向的客户端: redis-cli -h host -p port -c :linux系统中redis自带的客户端,该客户端可以自动进行moved重定向操作,主要在于 -c 命令参数,该参数表示以集群模式启动客户端并连接到到集群中的某个节点上,如下图所示,客户端会自动进行连接转移并执行命令 3. ask重定向:类似于moved重定向,但该转移通常与集群伸缩有关

springboot2.1.7-整合redis

倾然丶 夕夏残阳落幕 提交于 2019-12-06 05:42:44
在 springboot1.x 系列中,其中使用的是 jedis ,但是到了 springboot2.x 其中使用的是 Lettuce 。 此处 springboot2.x ,所以使用的是 Lettuce 。 关于 jedis 跟 lettuce 的区别: Lettuce 和 Jedis 的定位都是Redis的client,所以他们当然可以直接连接redis server。 Jedis在实现上是直接连接的redis server,如果在多线程环境下是非线程安全的,这个时候只有使用连接池,为每个Jedis实例增加物理连接 Lettuce的连接是基于Netty的,连接实例(StatefulRedisConnection)可以在多个线程间并发访问,应为StatefulRedisConnection是线程安全的,所以一个连接实例(StatefulRedisConnection)就可以满足多线程环境下的并发访问,当然这个也是可伸缩的设计,一个连接实例不够的情况也可以按需增加连接实例。 来源: https://www.cnblogs.com/hellohero55/p/11964448.html

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type to type [java.lang.String] - Redis

ぃ、小莉子 提交于 2019-12-06 05:22:42
I am using Spring Data Redis with the Spring Boot 2.0 example. In this example, I am trying to save the Customer data + Student data together. I'm not very sure how the data modelling happens here, but assuming its same like as Mongo DB (pure non relational). Could someone please help with the below error ? As its clear that some conversion has been expected to see the data. Error: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.javasampleapproach.redis.model.Customer] to type [java.lang.String] at org.springframework.core

# 使用Redis实现延时任务(二)

巧了我就是萌 提交于 2019-12-06 01:10:13
前提 前一篇文章通过 Redis 的有序集合 Sorted Set 和调度框架 Quartz 实例一版简单的延时任务,但是有两个相对重要的问题没有解决: 分片。 监控。 这篇文章的内容就是要完善这两个方面的功能。前置文章: 使用Redis实现延时任务(一) 。 为什么需要分片 这里重新贴一下查询脚本 dequeue.lua 的内容: -- 参考jesque的部分Lua脚本实现 local zset_key = KEYS[1] local hash_key = KEYS[2] local min_score = ARGV[1] local max_score = ARGV[2] local offset = ARGV[3] local limit = ARGV[4] -- TYPE命令的返回结果是{'ok':'zset'}这样子,这里利用next做一轮迭代 local status, type = next(redis.call('TYPE', zset_key)) if status ~= nil and status == 'ok' then if type == 'zset' then local list = redis.call('ZREVRANGEBYSCORE', zset_key, max_score, min_score, 'LIMIT', offset,