org.springframework.data.redis.core.HashOperations.increment()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(172)

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

HashOperations.increment介绍

[英]Increment value of a hash hashKey by the given delta.
[中]按给定增量递增散列哈希键的值。

代码示例

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

@Override
public Long increment(HK key, long delta) {
  return ops.increment(getKey(), key, delta);
}

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

@Override
public Double increment(HK key, double delta) {
  return ops.increment(getKey(), key, delta);
}

代码示例来源:origin: whvcse/EasyWeb

/**
 * 为哈希表 key 中的指定字段的整数值加上增量 increment
 *
 * @param key
 * @param field
 * @param delta
 * @return
 */
public Double hIncrByFloat(String key, Object field, double delta) {
  return redisTemplate.opsForHash().increment(key, field, delta);
}

代码示例来源:origin: whvcse/EasyWeb

/**
 * 为哈希表 key 中的指定字段的整数值加上增量 increment
 *
 * @param key
 * @param field
 * @param increment
 * @return
 */
public Long hIncrBy(String key, Object field, long increment) {
  return redisTemplate.opsForHash().increment(key, field, increment);
}

代码示例来源:origin: gudaoxuri/dew

@Override
public long hashIncrBy(String h, String hk, long incrValue) {
  return redisTemplate.opsForHash().increment(h, hk, incrValue);
}

代码示例来源:origin: gudaoxuri/dew

@Override
public long hashDecrBy(String h, String hk, long decrValue) {
  return redisTemplate.opsForHash().increment(h, hk, -decrValue);
}

代码示例来源:origin: vvsuperman/coolmq

@Override
public Long incrResendKey(String key, String hashKey) {
  return  redisTemplate.opsForHash().increment(key, hashKey, 1);
}

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

@Override
public Long increment(HK key, long delta) {
  return ops.increment(getKey(), key, delta);
}

代码示例来源:origin: lzh-boy/cskit

@Override
public <HK> Double hashIncrementDoubleOfHashMap(K hKey, HK hashKey, Double delta) {
  return redisTemplate.opsForHash().increment(hKey, hashKey, delta);
}

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

@Override
public Long increment(HK key, long delta) {
  return ops.increment(getKey(), key, delta);
}

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

@Override
public Double increment(HK key, double delta) {
  return ops.increment(getKey(), key, delta);
}

代码示例来源:origin: sentilo/sentilo

protected void incrementCounter(final String hashKey, final String hashField, final int total) {
 redisTemplate.opsForHash().increment(hashKey, hashField, total);
}

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

/**
 * Internally increments the given hash key, keeping track of created hash for a given counter, so they can be
 * cleaned up when needed.
 */
private void doIncrementHash(String key, String hashKey, long amount, String bookkeepingKey) {
  long newValue = hashOperations.increment(key, hashKey, amount);
  // TODO: the following test does not necessarily mean that the hash
  // is new, just that the key inside that hash is new. So we end up
  // calling add more than needed
  if (newValue == amount) {
    setOperations.add(bookkeepingKey, key);
  }
}

代码示例来源:origin: org.springframework.cloud.stream.app/app-starters-common-analytics

/**
 * Internally increments the given hash key, keeping track of created hash for a given counter, so they can be
 * cleaned up when needed.
 */
private void doIncrementHash(String key, String hashKey, long amount, String bookkeepingKey) {
  long newValue = hashOperations.increment(key, hashKey, amount);
  // TODO: the following test does not necessarily mean that the hash
  // is new, just that the key inside that hash is new. So we end up
  // calling add more than needed
  if (newValue == amount) {
    setOperations.add(bookkeepingKey, key);
  }
}

代码示例来源:origin: 3zamn/kingMicro

/**
 * 高并发的分布式环境下保证线程安全
 * @param key
 * @param hashKey
 * @param delta
 * @return
 */
@SuppressWarnings("unchecked")
public Long incrementHash(String key, String hashKey, Long delta) {
  if (null == delta) {
    delta = 1L;
  }
  return redisTemplate.opsForHash().increment(key, hashKey, delta);
}

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

@Override
public Double increment(HK key, double delta) {
  return ops.increment(getKey(), key, delta);
}

代码示例来源:origin: lzh-boy/cskit

@Override
public <HK> Long hashIncrementLongOfHashMap(K hKey, HK hashKey, Long delta) {
  return redisTemplate.opsForHash().increment(hKey, hashKey, delta);
}

代码示例来源:origin: dqeasycloud/easy-cloud

/**
 * <p>
 * 通过给定的delta增加散列hashKey的值(整型)
 * </p>
 * <p>
 * <pre>
 * DqRedisTemplateHandler.incrementOfHash("key", "hashKey", 2) = 2
 * </pre>
 *
 * @param key     : String : 主key
 * @param hashKey : String : hashKey
 * @param delta   : Long : 递增的值
 * @return 递增后的值
 * @author daiqi
 * @date 2017年12月13日 下午2:10:23
 */
public Long incrementOfHash(String key, Object hashKey, long delta) {
  if (EcStringUtils.isEmpty(key) || EcBaseUtils.isNull(hashKey)) {
    return null;
  }
  return stringRedisTemplate.opsForHash().increment(key, String.valueOf(hashKey), delta);
}

代码示例来源:origin: dqeasycloud/easy-cloud

/**
 * <p>
 * 通过给定的delta增加散列hashKey的值(浮点型)
 * </p>
 * <p>
 * <pre>
 * DqRedisTemplateHandler.incrementOfHash("key", "hashKey", 2.0) = 2.0
 * </pre>
 *
 * @param key     : String : 主key
 * @param hashKey : String : hashKey
 * @param delta   : double : 递增的值
 * @return 递增后的值
 * @author daiqi
 * @date 2017年12月13日 下午2:10:23
 */
public Double incrementOfHash(String key, Object hashKey, double delta) {
  if (EcStringUtils.isEmpty(key) || EcBaseUtils.isNull(hashKey)) {
    return null;
  }
  return stringRedisTemplate.opsForHash().increment(key, String.valueOf(hashKey), delta);
}

代码示例来源:origin: vvsuperman/coolmq

@Override
public void onMessage(Message message, Channel channel) throws Exception {
  MessageProperties messageProperties = message.getMessageProperties();
  Long deliveryTag = messageProperties.getDeliveryTag();
  Long consumerCount = redisTemplate.opsForHash().increment(MQConstants.MQ_CONSUMER_RETRY_COUNT_KEY,
      messageProperties.getMessageId(), 1);
  logger.info("收到消息,当前消息ID:{} 消费次数:{}", messageProperties.getMessageId(), consumerCount);
  try {
    receiveMessage(message);
    // 成功的回执
    channel.basicAck(deliveryTag, false);
    // 如果消费成功,将Redis中统计消息消费次数的缓存删除
    redisTemplate.opsForHash().delete(MQConstants.MQ_CONSUMER_RETRY_COUNT_KEY,
        messageProperties.getMessageId());
  } catch (Exception e) {
    logger.error("RabbitMQ 消息消费失败," + e.getMessage(), e);
    if (consumerCount >= MQConstants.MAX_CONSUMER_COUNT) {
      // 入死信队列
      channel.basicReject(deliveryTag, false);
    } else {
      // 重回到队列,重新消费, 按照2的指数级递增
      Thread.sleep((long) (Math.pow(MQConstants.BASE_NUM, consumerCount)*1000));
      redisTemplate.opsForHash().increment(MQConstants.MQ_CONSUMER_RETRY_COUNT_KEY,
          messageProperties.getMessageId(), 1);
      channel.basicNack(deliveryTag, false, true);
    }
  }
}

相关文章