天道酬勤,学无止境

jedis

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

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.city:Achalpur" 6) "persons:e493385a-64ae-42be-8398-51757153d273:idx" 7) "persons:053cdfea-e430-4e1c-acbd

2021-06-12 19:47:19    分类:问答    java   redis   jedis   spring-data-redis

多核 CPU 上的 Redis 性能(Redis performance on a multi core CPU)

问题 我正在寻找 redis 来为我提供一个中间缓存存储,并围绕集合操作(​​如交集和并集)进行大量计算。 我查看了redis网站,发现redis不是为多核CPU设计的。 我的问题是,为什么会这样? 另外,如果是的话,我们如何在多核 CPU 上使用 redis 使 CPU 资源的利用率达到 100%。 回答1 我查看了redis网站,发现redis不是为多核CPU设计的。 我的问题是,为什么会这样? 这是一个设计决策。 Redis 是单线程的,带有 epoll/kqueue,并且在 I/O 并发性方面可以无限​​扩展。 --@antirez(Redis 的创建者) 选择事件驱动方法的一个原因是线程之间的同步在软件(代码复杂性)和硬件级别(上下文切换)方面都有代价。 除此之外,Redis 的瓶颈通常是网络,而不是 CPU。 另一方面,单线程架构有其自身的优势(例如原子性的保证)。 因此,对于像 Redis 这样的高效且可扩展的系统,事件循环似乎是一个很好的设计。 另外,如果是的话,我们如何在多核 CPU 上使用 redis 使 CPU 资源的利用率达到 100%。 Redis 扩展多核的方法是分片,主要是与 Twemproxy 一起使用。 但是,如果出于某种原因您仍然想使用多线程方法,请查看 Thredis,但请确保您了解其作者所做的事情的含义(例如,您不能将其用作复制主机)。

2021-06-11 10:55:29    分类:技术分享    redis   cpu   cpu-usage   jedis

Jedis 池如何运作?(How Jedis Pool works?)

问题 我正在使用 Jedis 池来管理与 Redis 服务器的连接。 我的示例代码如下: public Set<String> getTopArticleList(int start, int end) { Set<String> list = null; Jedis j = JedisFactory.getInstance().getJedisPool().getResource(); Pipeline pipe = j.pipelined(); try { // do stuff with redis pipe.sync(); } catch (JedisConnectionException jex) { JedisFactory.getInstance().getJedisPool().returnBrokenResource(j); } finally { JedisFactory.getInstance().getJedisPool().returnResource(j); } return list; } 创建和检索 Jedis 池的代码: class JedisFactory { private static JedisPool jedisPool; public JedisFactory() { JedisPoolConfig poolConfig = new

2021-06-11 10:29:46    分类:技术分享    java   connection-pooling   jedis

如何使用 Jedis 库建立与 Redis Sentinel 的连接? [关闭](How to setup a connection to Redis Sentinel using Jedis library? [closed])

问题 关闭。 此问题不符合 Stack Overflow 准则。 它目前不接受答案。 想改善这个问题吗? 更新问题,使其成为 Stack Overflow 的主题。 2年前关闭。 改进这个问题 如何使用 Jedis 库建立到 Redis Sentinel 服务器/集群的连接? 回答1 Jedis 库是一个很棒的解决方案,不幸的是文档不好。 所以, @Autowired private JedisSentinelPool pool; public void mymethod() { Jedis jedis = null; try { jedis = pool.getResource(); jedis.hset(.... } catch (JedisException je) { throw je; } finally { if (jedis != null) pool.returnResource(jedis); } } 当我使用 Spring 时,我需要: <bean id="redisSentinel" class="redis.clients.jedis.JedisSentinelPool"> <constructor-arg index="0" value="mymaster" /> <constructor-arg index="1"> <set> <value

2021-06-10 22:15:11    分类:技术分享    java   redis   jedis   sentinel

Redis/Jedis 无单点故障和自动故障转移(Redis/Jedis no single point of failure and automated failover)

问题 在一个简单的情况下,有 3 个服务器,1 个主服务器和 2 个从服务器,没有分片。 是否有经过验证的 java 和 Jedis 解决方案,它没有单点故障,并且会自动处理单个服务器的故障,即主服务器或从服务器(自动故障转移)。 例如,提升主节点并在故障后重置而不会丢失任何数据。 在我看来,它应该是一个已解决的问题,但我找不到任何代码,只是对可能的方法的高级描述。 谁实际上已经涵盖并在生产中工作? 回答1 您可能想尝试使用 Redis Sentinel 来实现这一点: Redis Sentinel 是一个旨在帮助管理 Redis 实例的系统。 它执行以下三个任务: 监控。 Sentinel 会不断检查您的主从实例是否按预期工作。 通知。 Sentinel 可以通过 API 通知系统管理员或其他计算机程序,其中一个受监控的 Redis 实例出现问题。 自动故障转移。 如果 master 没有按预期工作,Sentinel 可以启动一个故障转移过程,其中一个 slave 被提升为 master,其他额外的 slave 被重新配置为使用新的 master,并且使用 Redis 服务器的应用程序被告知要使用的新地址。连接。 ...或使用外部解决方案,如 Zookeeper 和 Jedis_failover: JedisPool pool = new JedisPoolBuilder()

2021-06-10 04:20:30    分类:技术分享    java   amazon-web-services   nosql   redis   jedis

JedisPoolConfig is not assignable to GenericObjectPoolConfig

I have a Spring based java web application hosted on Heroku. I am attempting to utilize the Spring Caching abstraction using the Redis implementation. When the server starts, I get an error saying: Type 'redis/clients/jedis/JedisPoolConfig' (current frame, stack[3]) is not assignable to 'org/apache/commons/pool2/impl/GenericObjectPoolConfig' Here is my configuration: @Bean RedisConnectionFactory jedisConnectionFactory() throws Exception { URI redisUri = new URI(System.getenv("REDISCLOUD_URL")); JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory(); redisConnectionFactory

2021-06-05 14:34:10    分类:问答    java   spring   caching   redis   jedis

Can redis pipeline multiple commands that depend on previous ones?

I'm very very new to redis and still playing around with it. I want to test to see if its relevant to my project but I'm not sure about a specific command I'm running. The users on SO have got me convinced of the performance benefits of using pipelines and transactions so I thought I'd ask how to do this. Basically I have two statements that I just want to issue and not have to wait for the result(seems like a good candidate for pipe lining. It looks like this: Does valueX exist? If it does insert valueY Its pretty simple but so far all the ways I have been looking into it seem to wait for a

2021-06-05 11:20:56    分类:问答    database   redis   jedis

Jedis - When to use returnBrokenResource()

When exactly we should use this method. On JedisConnectionException, JedisDataException or for any JedisException. There is no good API documentation for Jedis to my knowledge. try { Jedis jedis = JedisFactory.getInstance(); Pipeline pipe = jedis.pipelined(); Response<Set<Tuple>> idWithScore = pipe.zrangeWithScores(cachekey, from, to); **// some statement which may cause some other exception** Response<String> val = pipe.get(somekey); pipe.exec(); pipe.sync(); }catch (JedisConnectionException e) { JedisFactory.returnBrokenResource(jedis); }catch(Exception e){ **// What API I should use here

2021-06-04 21:11:38    分类:问答    java   exception   redis   jedis

Could not get a resource from the pool(SocketTimeoutException:)

I'm running multiple worker threads(around 10) to access the data from the redis Q. For the i'm using infinte timeout for Jedis Client. Jedis jedis = pool.getResource(); jedis.getClient().setTimeoutInfinite(); Still i'm getting the error "Could not get a resource from the pool". The stacktrace is given below. redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool.java:22) at Workers.Worker1.met1(Worker1.java:124) at Workers.Worker1.work(Worker1.java:108) at org.gearman.impl.worker.WorkerConnectionController$3

2021-06-04 04:49:33    分类:问答    java   redis   socketexception   jedis

Why A single Jedis instance is not threadsafe?

https://github.com/xetorthio/jedis/wiki/Getting-started using Jedis in a multithreaded environment You shouldn't use the same instance from different threads because you'll have strange errors. And sometimes creating lots of Jedis instances is not good enough because it means lots of sockets and connections, which leads to strange errors as well. A single Jedis instance is not threadsafe ! To avoid these problems, you should use JedisPool, which is a threadsafe pool of network connections. You can use the pool to reliably create several Jedis instances, given you return the Jedis instance to

2021-06-03 03:16:38    分类:问答    redis   thread-safety   pool   jedis