Java Code Examples for org.springframework.data.redis.core.HashOperations#put()

The following examples show how to use org.springframework.data.redis.core.HashOperations#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResumeService.java    From microservice-recruit with Apache License 2.0 6 votes vote down vote up
/**
 * 处理简历
 */
public void handleResume(SendResume sendResume) {
    log.info("start handle resume");
    HashOperations<String, String, String> redisHash = redis.opsForHash();
    long start = System.currentTimeMillis();
    Long userId = sendResume.getUserId();
    Long recruitId = sendResume.getRecruitId();
    // 构建发送列表
    String sendKey = Constant.getKey(RedisKeys.RESUME_SEND, String.valueOf(userId));
    redisHash.put(sendKey, String.valueOf(recruitId), JSONObject.toJSONString(sendResume));
    // 构建获取列表
    String receiveKey = Constant.getKey(RedisKeys.RESUME_RECEIVE, String.valueOf(recruitId));
    UserInfo userInfo = userClient.getUserInfo(userId).getData();
    // 计算匹配度
    Recruit recruit = recruitClient.getRecruit(recruitId).getData();
    int rate = calculate(recruit, userId);
    ReceiveResume receiveResume = new ReceiveResume(sendResume.getTitle(), userInfo.getNickname(), userInfo.getUserId(), rate, LocalDateTime.now());
    redisHash.put(receiveKey, String.valueOf(userId), JSONObject.toJSONString(receiveResume));
    log.info("end handle resume spend time is " + (System.currentTimeMillis() - start));
}
 
Example 2
Source File: ResumeService.java    From microservice-recruit with Apache License 2.0 6 votes vote down vote up
/**
 * 处理简历
 */
public void handleResume(SendResume sendResume) {
    log.info("start handle resume");
    HashOperations<String, String, String> redisHash = redis.opsForHash();
    long start = System.currentTimeMillis();
    Long userId = sendResume.getUserId();
    Long recruitId = sendResume.getRecruitId();
    // 构建发送列表
    String sendKey = Constant.getKey(RedisKeys.RESUME_SEND, String.valueOf(userId));
    redisHash.put(sendKey, String.valueOf(recruitId), JSONObject.toJSONString(sendResume));
    // 构建获取列表
    String receiveKey = Constant.getKey(RedisKeys.RESUME_RECEIVE, String.valueOf(recruitId));
    UserInfo userInfo = userClient.getUserInfo(userId).getData();
    // 计算匹配度
    Recruit recruit = recruitClient.getRecruit(recruitId).getData();
    int rate = calculate(recruit, userId);
    ReceiveResume receiveResume = new ReceiveResume(sendResume.getTitle(), userInfo.getNickname(), userInfo.getUserId(), rate, LocalDateTime.now());
    redisHash.put(receiveKey, String.valueOf(userId), JSONObject.toJSONString(receiveResume));
    log.info("end handle resume spend time is " + (System.currentTimeMillis() - start));
}
 
Example 3
Source File: DistributedlockApplicationTests.java    From java-tutorial with MIT License 6 votes vote down vote up
@Test
public void hash() throws InterruptedException {
    HashOperations hashOperations = redisTemplate.opsForHash();
    Info info1 = new Info(1001, "Hong");
    Info info2 = new Info(1002, "Kong");
    //is exist
    if (hashOperations.getOperations().hasKey("info_1001")) {
        //delete
        hashOperations.delete("info_1001", "1001");
        hashOperations.delete("info_1002", "1002");
        Thread.sleep(3000);
    }
    //put
    hashOperations.put("info_1001", "1001", info1);
    hashOperations.put("info_1002", "1002", info2);
    //get
    Info info = (Info) hashOperations.get("info_1001", "1001");

    System.out.println();
    System.out.println(info);


}
 
Example 4
Source File: MessageServiceController.java    From sctalk with Apache License 2.0 6 votes vote down vote up
/**
 * 消息用户计数
 * @param userCountReq 会话信息
 * @return 更新结果
 * @since  1.0
 */
@PostMapping("/clearUserCounter")
public BaseModel<?> clearUserCounter(@RequestBody ClearUserCountReq userCountReq) {

    HashOperations<String, String, String> hashOptions = redisTemplate.opsForHash();

    if (userCountReq.getSessionType() == IMBaseDefine.SessionType.SESSION_TYPE_SINGLE) {
        // Clear P2P msg Counter
        final String userKey = RedisKeys.concat(RedisKeys.USER_UNREAD, userCountReq.getUserId());
        hashOptions.delete(userKey, String.valueOf(userCountReq.getPeerId()));
    } else if (userCountReq.getSessionType() == IMBaseDefine.SessionType.SESSION_TYPE_GROUP) {
        // Clear Group msg Counter
        final String groupSetKey = RedisKeys.concat(RedisKeys.GROUP_INFO, userCountReq.getPeerId(), RedisKeys.SETTING_INFO);
        final String countValue = hashOptions.get(groupSetKey, RedisKeys.COUNT);

        final String userUnreadKey = RedisKeys.concat(RedisKeys.GROUP_UNREAD, userCountReq.getUserId());
        hashOptions.put(userUnreadKey, String.valueOf(userCountReq.getPeerId()), countValue);
    } else {
        logger.warn("参数不正: SessionType={}", userCountReq.getSessionType());
    }
    return null;
}
 
Example 5
Source File: AbsRedisDao.java    From jeesupport with MIT License 6 votes vote down vote up
@Override
public void insert ( int _idx, T _obj ) throws Exception{
    try{
        database( _idx );
        HashOperations< String, ID, T > hash = tpl.opsForHash();
        ID hk = _get_hk( _obj );
        String sn = _obj.getClass().getSimpleName();
        if( hash.hasKey( sn, hk ) ){
            throw new Exception( "插入失败,包含主键[" + hk + "]的对象[" + sn + "]已存在!" );
        }

        hash.put( _obj.getClass().getSimpleName(), hk, _obj );
    }catch ( Exception e ){
        log.error( "insert 发生错误:IDX=[" + _idx + "]" + e.toString(), e );
        throw e;
    }
}
 
Example 6
Source File: RedisCache.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 缓存Map
 *
 * @param key
 * @param dataMap
 * @return
 */
public <T> HashOperations<String, String, T> setCacheMap(String key, Map<String, T> dataMap)
{
    HashOperations hashOperations = redisTemplate.opsForHash();
    if (null != dataMap)
    {
        for (Map.Entry<String, T> entry : dataMap.entrySet())
        {
            hashOperations.put(key, entry.getKey(), entry.getValue());
        }
    }
    return hashOperations;
}
 
Example 7
Source File: RedisCacheService.java    From DimpleBlog with Apache License 2.0 5 votes vote down vote up
/**
 * 缓存Map
 *
 * @param key
 * @param dataMap
 * @return
 */
public <T> HashOperations<String, String, T> setCacheMap(String key, Map<String, T> dataMap) {
    HashOperations hashOperations = redisTemplate.opsForHash();
    if (null != dataMap) {
        for (Map.Entry<String, T> entry : dataMap.entrySet()) {
            hashOperations.put(key, entry.getKey(), entry.getValue());
        }
    }
    return hashOperations;
}
 
Example 8
Source File: LoginServiceController.java    From sctalk with Apache License 2.0 5 votes vote down vote up
@PostMapping(path = "/login/pushShield")
public BaseModel<Integer> pushShield(@RequestParam("userId") long userId, @RequestParam("shieldStatus") int shieldStatus) {
    String key = RedisKeys.concat(RedisKeys.USER_INFO, userId); 
    HashOperations<String, String, String> userMapOps = redisTemplate.opsForHash();
    userMapOps.put(key, RedisKeys.USER_SHIELD, String.valueOf(shieldStatus));
    
    return new BaseModel<Integer>();
}
 
Example 9
Source File: AbsRedisDao.java    From jeesupport with MIT License 5 votes vote down vote up
@Override
public void update ( int _idx, T _obj ){
    try{
        database( _idx );
        HashOperations< String, ID, T > hash = tpl.opsForHash();
        ID hk = _get_hk( _obj );
        hash.put( _obj.getClass().getSimpleName(), hk, _obj );
    }catch ( Exception e ){
        log.error( "update 发生错误:IDX=[" + _idx + "]" + e.toString(), e );
        throw e;
    }
}
 
Example 10
Source File: RedisSupport.java    From mykit-delay with Apache License 2.0 4 votes vote down vote up
public void hashPut(String key, String hashKey, String hashValue) {
    HashOperations<String, String, String> hashOperations = template.opsForHash();
    hashOperations.put(key, hashKey, hashValue);
}
 
Example 11
Source File: RedisSupport.java    From sdmq with Apache License 2.0 4 votes vote down vote up
public void hashPut(String key, String hashKey, String hashValue) {
    HashOperations<String, String, String> hashOperations = template.opsForHash();
    hashOperations.put(key, hashKey, hashValue);
}
 
Example 12
Source File: CacheServiceProvider.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void putHash(final String key, final Object hashKey, final Object hashValue) {
	final HashOperations<String, Object, Object> operation = redisTemplate.opsForHash();
	operation.put(getKey(key), hashKey, hashValue);
}
 
Example 13
Source File: GroupInternalServiceImpl.java    From sctalk with Apache License 2.0 4 votes vote down vote up
@Override
public void setGroupPush(long groupId, long userId, int shieldStatus) {
    final String groupSetKey = RedisKeys.concat(RedisKeys.GROUP_INFO, groupId, RedisKeys.SETTING_INFO); 
    HashOperations<String, String, String> groupMapOps = redisTemplate.opsForHash();
    groupMapOps.put(groupSetKey, String.valueOf(userId), String.valueOf(shieldStatus));
}
 
Example 14
Source File: RedisServiceImpl.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * 添加键值对到哈希表key中
 * 
 * @time 下午9:50:04
 * 
 * @version V1.0
 * @param key
 * @param hashKey
 * @param value
 */
@Override
public void hashPushHashMap(String key, Integer hashKey, List<String> value) {

	HashOperations<Object, Integer, List<String>> hashOps = redisTemplate.opsForHash();
	hashOps.put(key, hashKey, value);
}