redis.clients.jedis.Jedis.watch()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(258)

本文整理了Java中redis.clients.jedis.Jedis.watch()方法的一些代码示例,展示了Jedis.watch()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.watch()方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:watch

Jedis.watch介绍

暂无

代码示例

代码示例来源:origin: qiurunze123/miaosha

/**
 * watch 监控多个key 一防止其他地方调用释放锁的时候对这个key进行修改 那么事务里面的代码就不会被执行 !
 */
  public boolean releaseLock(String key , String value){
    try {
      Jedis jedis = RedisManager.getJedis();
      while (true){
        jedis.watch(key);
        if(value.equals(jedis.get(key))){
          Transaction transaction = jedis.multi();
          transaction.del(key);
          List<Object> list = transaction.exec();
          if(list ==null){
            continue;
          }
          jedis.unwatch();
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public void watch(byte[]... keys) {
  if (isQueueing()) {
    throw new UnsupportedOperationException();
  }
  try {
    for (byte[] key : keys) {
      if (isPipelined()) {
        pipeline(newStatusResult(getRequiredPipeline().watch(key)));
      } else {
        jedis.watch(key);
      }
    }
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: com.github.sogyf/goja-mvt

@Override
  public String action(Jedis jedis) {
    return jedis.watch(keys);
  }
});

代码示例来源:origin: davidmarquis/redis-scheduler

@Override
public void watch(String key) {
  jedis.watch(key);
}

代码示例来源:origin: io.leopard/leopard-redis

@Override
public String watch(String... keys) {
  return jedis.watch(keys);
}

代码示例来源:origin: io.leopard/leopard-redis

@Override
public String watch(String... keys) {
  return jedis.watch(keys);
}

代码示例来源:origin: penggle/jedis-ms-sentinel

public String watch(String... keys) {
  return master.watch(keys);
}

代码示例来源:origin: penggle/jedis-ms-sentinel

public String watch(byte[]... keys) {
  return master.watch(keys);
}

代码示例来源:origin: mindwind/craft-atom

private String watch0(Jedis j, String... keys) {
  String r = j.watch(keys);
  bind(j);
  return r;
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public String watch(byte[]... keys) {
 String command = "watch";
 return instrumented(command, () -> delegated.watch(keys));
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public String watch(String... keys) {
 String command = "watch";
 return instrumented(command, () -> delegated.watch(keys));
}

代码示例来源:origin: io.enoa/nosql-redis

default String watch(String... keys) {
 return this.run((jedis, serializer) -> jedis.watch(keys));
}

代码示例来源:origin: org.nutz/nutz-integration-jedis

public String watch(byte[]... keys) {
  Jedis jedis = getJedis();
  try {
    return jedis.watch(keys);
  } finally {Streams.safeClose(jedis);}
}

代码示例来源:origin: org.nutz/nutz-integration-jedis

public String watch(String... keys) {
  Jedis jedis = getJedis();
  try {
    return jedis.watch(keys);
  } finally {Streams.safeClose(jedis);}
}

代码示例来源:origin: xetorthio/rmq

public String watch() {
  Jedis jedis = getResource();
  String result = jedis.watch(key());
  returnResource(jedis);
  return result;
}

代码示例来源:origin: youtongluan/sumk

@Override
public java.lang.String watch(byte[]... keys) {
  Exception e1 = null;
  for (int i = 0; i < tryCount; i++) {
    Jedis jedis = null;
    try {
      jedis = pool.getResource();
      return jedis.watch(keys);
    } catch (Exception e) {
      if (isConnectException(e)) {
        Log.get(LOG_NAME).error(this.hosts + " - redis connection failed,idle=" + pool.getNumIdle()
            + ",active=" + pool.getNumActive(), e);
        e1 = e;
        continue;
      }
      Log.get(LOG_NAME).error("watch - redis execute error!" + e.getMessage(), e);
      SumkException.throwException(12342411, e.getMessage(), e);
    } finally {
      close(jedis);
    }
  }
  handleRedisException(e1);
  throw new SumkException(12342423, "未知redis异常");
}

代码示例来源:origin: org.springframework.data/spring-data-redis

@Override
public void watch(byte[]... keys) {
  if (isQueueing()) {
    throw new UnsupportedOperationException();
  }
  try {
    for (byte[] key : keys) {
      if (isPipelined()) {
        pipeline(newStatusResult(getRequiredPipeline().watch(key)));
      } else {
        jedis.watch(key);
      }
    }
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public void watch(byte[]... keys) {
  if (isQueueing()) {
    throw new UnsupportedOperationException();
  }
  try {
    for (byte[] key : keys) {
      if (isPipelined()) {
        pipeline(newStatusResult(getRequiredPipeline().watch(key)));
      } else {
        jedis.watch(key);
      }
    }
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: Baqend/Orestes-Bloomfilter

public FilterBuilder persistConfig(RedisPool pool, FilterBuilder builder) {
  return pool.safelyReturn(jedis -> {
    FilterBuilder newConfig = null;
    //Retry on concurrent changes
    while (newConfig == null) {
      if (!builder.overwriteIfExists() && jedis.exists(builder.name())) {
        newConfig = this.parseConfigHash(jedis.hgetAll(builder.name()), builder.name(), pool);
      } else {
        Map<String, String> hash = this.buildConfigHash(builder);
        jedis.watch(builder.name());
        Transaction t = jedis.multi();
        hash.forEach((k, v) -> t.hset(builder.name(), k, v));
        if (t.exec() != null) {
          newConfig = builder;
        }
      }
    }
    return newConfig;
  });
}

代码示例来源:origin: pyloque/captain

public int nextId(String name) {
  String key = keyFor(name);
  Holder<Integer> holder = new Holder<>();
  redis.execute(jedis -> {
    jedis.sadd(ALL_SEQS, name);
    long pos = 0;
    do {
      jedis.watch(key);
      pos = jedis.bitpos(key, false);
      if (pos < 0) {
        pos = 0;
      }
      Transaction tx = jedis.multi();
      tx.setbit(key, pos, true);
      if (tx.exec() != null) {
        break;
      }
    } while (true);
    holder.set((int) pos);
  });
  return holder.value();
}

相关文章

Jedis类方法