@Override public void put(HK key, HV value) { ops.put(getKey(), key, value); }
@Override public Boolean addTxTransaction(final String txGroupId, final TxTransactionItem txTransactionItem) { try { redisTemplate.opsForHash().put(cacheKey(txGroupId), txTransactionItem.getTaskKey(), txTransactionItem); } catch (Exception e) { return false; } return true; }
@Override public Boolean saveTxTransactionGroup(final TxTransactionGroup txTransactionGroup) { try { final String groupId = txTransactionGroup.getId(); //保存数据 到sortSet redisTemplate.opsForZSet().add(CommonConstant.REDIS_KEY_SET, groupId, CommonConstant.REDIS_SCOPE); final List<TxTransactionItem> itemList = txTransactionGroup.getItemList(); if (CollectionUtils.isNotEmpty(itemList)) { for (TxTransactionItem item : itemList) { redisTemplate.opsForHash().put(cacheKey(groupId), item.getTaskKey(), item); } } } catch (Exception e) { return false; } return true; }
@Override public void updateTxTransactionItemStatus(final String key, final String hashKey, final int status, final Object message) { try { final TxTransactionItem item = (TxTransactionItem) redisTemplate.opsForHash().get(cacheKey(key), hashKey); item.setStatus(status); if (Objects.nonNull(message)) { item.setMessage(message); } //计算耗时 final String createDate = item.getCreateDate(); final LocalDateTime now = LocalDateTime.now(); try { final LocalDateTime createDateTime = DateUtils.parseLocalDateTime(createDate); final long consumeTime = DateUtils.getSecondsBetween(createDateTime, now); item.setConsumeTime(consumeTime); } catch (ParseException e) { e.printStackTrace(); } redisTemplate.opsForHash().put(cacheKey(key), item.getTaskKey(), item); } catch (BeansException e) { e.printStackTrace(); } }
/** * 对HashMap操作 * * @param key the key * @param hashKey the hash key * @param hashValue the hash value */ public void putHashValue(String key, String hashKey, String hashValue) { LOGGER.info("[redisTemplate redis] putHashValue() key={},hashKey={},hashValue={} ", key, hashKey, hashValue); opsForHash().put(key, hashKey, hashValue); }
public boolean publishConfig(String group, String serviceId, String config) { hashOperations.put(group, serviceId, config); stringRedisTemplate.convertAndSend(group + "-" + serviceId, config); return true; }
/** * 保存一个用户 */ public void save(User user) { HashOperations<String, String, String> opsForHash = stringRedisTemplate.opsForHash(); try { opsForHash.put(KEY_PREFIX, user.getId() + "", objectMapper.writeValueAsString(user)); } catch (JsonProcessingException e) { logger.error("save user error,user id is ", user.getId()); } }
/** * 实现命令:HSET key field value,将哈希表 key中的域 field的值设为 value * * @param key * @param field * @param value */ public void hset(String key, String field, Object value) { redisTemplate.opsForHash().put(key, field, value); }
@Override public void storeCaptcha(String sid, Captcha captcha, Locale locale) throws CaptchaServiceException { CAPTCHA_LOG.debug("Store captcha, Sid: {}.", sid); this.hashOperations.put(CAPTCHA_SESSION_KEY, sid, new CaptchaAndLocale(captcha, locale)); }
public boolean publishConfig(String group, String serviceId, String config) { hashOperations.put(group, serviceId, config); stringRedisTemplate.convertAndSend(group + "-" + serviceId, config); return true; }
/** * 保存到hash集合中 * * @param hName 集合名 * @param key * @param value */ public static void hashSet(String hName, String key, String value) { cacheUtils.redisTemplate.opsForHash().put(hName, key, value); }
@Override public Boolean bindJob(Long jobId, Long jobConfigId) { String jobConfigMappingsKey = RedisKeys.JOB_CONFIG_MAPPINGS; redis.opsForHash().put(jobConfigMappingsKey, jobId.toString(), jobConfigId.toString()); return Boolean.TRUE; }
@Override public Boolean indexJobClass(Long appId, Long jobId, String clazz) { String appJobClassesKey = RedisKeys.keyOfAppJobClasses(appId); redis.opsForHash().put(appJobClassesKey, clazz, jobId.toString()); return Boolean.TRUE; }
/** * 保存到数据库。改成关系数据库,重写此方法 * * @param configCached * @return 影响行数 */ @Override protected int doSave(LimitConfig configCached) { String hashKey = configCached.getNameVersion(); this.redisTemplate.opsForHash().put(REDIS_KEY, hashKey, JSON.toJSONString(configCached)); return 1; }
@Override public Boolean updateField(Long id, String fieldName, Object fieldValue) { String objectKey = objectKey(id); redis.opsForHash().put(objectKey, fieldName, fieldValue); return Boolean.TRUE; }
@Override public Boolean index(App app) { redis.opsForHash().put(RedisKeys.APP_INDEX_NAMES, app.getAppName(), app.getId()); return Boolean.TRUE; }
@Override public void setMsgReady(String msgId, com.coolmq.amqp.util.RabbitMetaMessage rabbitMetaMessage) { redisTemplate.opsForHash().put(MQConstants.MQ_MSG_READY, msgId, rabbitMetaMessage); redisTemplate.opsForSet().remove(MQConstants.MQ_MSG_PREPARE,msgId); }
@Override public Boolean offline(TacInst tacInst) { String msCode = tacInst.getMsCode(); // 1. update data TacMsPublishMeta publishMeta = new TacMsPublishMeta(tacInst, TacMsConstants.INST_STATUS_OFFLINE); hashOperations.put(getMainKey(), msCode, publishMeta); // 2. send message redisTopicTemplate.convertAndSend(getPublishChannel(), JSONObject.toJSONString(publishMeta)); return true; }