引入redisson锁后,延迟大幅增加

问题描述 投票:0回答:0

我最近引入了redisson锁,之后需要5-7秒。没有锁需要<1s. (testing locally in both cases). Im I doing anything wrong here. This is local figure, but in production too delay will be proportionally high with lock. Can't afford this huge delay. Fine with few microseconds delay coz of lock.

Redis是集群模式,3主3从。

示例代码:

    public String getDataFromRedis(String key){
       RLock lock = client.getLock(System.nanoTime());

       String data = null;
       try {
           lock.lock(5, TimeUnit.SECONDS);
           data = (String) client.getMapCache("map").get(key);
       } catch (Exception e) {
           LOGGER.error("Exception while getting data from redis, tuple: {}. {}",key, e.getMessage());
       } finally {
           if (lock.isLocked() && lock.isHeldByCurrentThread()) {
               lock.unlock();
               LOGGER.info("Lock unlocked {}",key);
           }
       }
       return data;
    }

我也找不到插入/检索数据的直接方法。在 redisson 提供的所有不同的数据结构中,我们需要使用关键字获取该数据结构,然后获取实际数据。就像上面的例子一样,我需要通过

"map"
关键字获取HSet然后获取数据找不到任何其他方式。有人也可以帮忙吗?因为我想让两个客户都吃 redisson 和生菜。在 lettuce 中我们可以直接插入/检索数据,但在 redisson 中不行。所以可以互换使用两个客户端。

redis locking redisson distributed-lock
© www.soinside.com 2019 - 2024. All rights reserved.