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

The following examples show how to use org.springframework.data.redis.core.HashOperations#delete() . 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: 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 2
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 3
Source File: AbsRedisDao.java    From jeesupport with MIT License 6 votes vote down vote up
@Override
public void delete( 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 ) ){
            long num = hash.delete( sn, hk );
            log.debug( "--已删除纪录:" + num + "条" );
        }else
            throw new Exception( "删除失败,包含主键[" + hk + "]的对象[" + sn + "]不存在!" );
    }catch ( Exception e ){
        log.error( "update 发生错误:IDX=[" + _idx + "]" + e.toString(), e );
        throw e;
    }
}
 
Example 4
Source File: RedisHashServiceImpl.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
@Override
public Long removeFields(String key, String... hashKeys) {
	HashOperations<String, String, Object> hash = rt.opsForHash();
	Long result = hash.delete(key, (Object) hashKeys);
	log.info("removeFields- 删除一个或多个哈希表字段. [OK] key={}, hashKeys={}, result={}", key, hashKeys, result);
	return result;
}
 
Example 5
Source File: AbsRedisDao.java    From jeesupport with MIT License 5 votes vote down vote up
@Override
public void deleteList ( int _idx, List< T > _list, Class< T > _cls ) {
    try{
        database( _idx );
        HashOperations< String, ID, T > hash = tpl.opsForHash();
        String sn = _cls.getClass().getSimpleName();
        long num = hash.delete( sn, _list.toArray() );
        log.debug( "--已删除纪录:" + num + "条" );
    }catch ( Exception e ){
        log.error( "update 发生错误:IDX=[" + _idx + "]" + e.toString(), e );
    }
}
 
Example 6
Source File: AbsRedisDao.java    From jeesupport with MIT License 5 votes vote down vote up
@Override
public void deleteById( int _idx, ID _id, Class< T > _cls ){
    try{
        database( _idx );
        HashOperations< String, ID, T > hash = tpl.opsForHash();
        ID hk = _id;
        String sn = _cls.getSimpleName();
        if( hash.hasKey( sn, hk ) ){
            hash.delete( sn, hk );
        }else
            throw new Exception( "删除失败,包含主键[" + hk + "]的对象[" + sn + "]不存在!" );
    }catch ( Exception e ){
        log.error( "update 发生错误:IDX=[" + _idx + "]" + e.toString(), e );
    }
}
 
Example 7
Source File: RecruitService.java    From microservice-recruit with Apache License 2.0 4 votes vote down vote up
public void deleteById(Long id) {
    // 删除对应缓存
    HashOperations<String, String, String> redisHash = redis.opsForHash();
    redisHash.delete(Constant.RECRUIT_REDIS_PREFIX, String.valueOf(id));
    recruitRepo.deleteById(id);
}
 
Example 8
Source File: RedisSupport.java    From mykit-delay with Apache License 2.0 4 votes vote down vote up
/**
 * 删除hash中的指定key
 */
public void deleteHashKeys(String key, Object... keys) {
    HashOperations<String, String, String> hashOperations = template.opsForHash();
    hashOperations.delete(key, keys);
}
 
Example 9
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 4 votes vote down vote up
public void deleteMap(String key, String mapkey) {
    HashOperations<String, String, T> hashOperations = redisTemplate.opsForHash();
    hashOperations.delete(key, mapkey);
}
 
Example 10
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 4 votes vote down vote up
public void deleteMap(String key, String mapkey) {
    HashOperations<String, String, T> hashOperations = redisTemplate.opsForHash();
    hashOperations.delete(key, mapkey);
}
 
Example 11
Source File: RedisCacheUtils.java    From sophia_scaffolding with Apache License 2.0 4 votes vote down vote up
public void deleteMap(String key, String mapkey) {
    HashOperations<String, String, T> hashOperations = redisTemplate.opsForHash();
    hashOperations.delete(key, mapkey);
}
 
Example 12
Source File: RecruitService.java    From microservice-recruit with Apache License 2.0 4 votes vote down vote up
public void deleteById(Long id) {
    // 删除对应缓存
    HashOperations<String, String, String> redisHash = redis.opsForHash();
    redisHash.delete(Constant.RECRUIT_REDIS_PREFIX, String.valueOf(id));
    recruitRepo.deleteById(id);
}
 
Example 13
Source File: RedisSupport.java    From sdmq with Apache License 2.0 4 votes vote down vote up
/**
 * 删除hash中的指定key
 */
public void deleteHashKeys(String key, Object... keys) {
    HashOperations<String, String, String> hashOperations = template.opsForHash();
    hashOperations.delete(key, keys);
}
 
Example 14
Source File: CacheServiceProvider.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void delete(final String key, final Object... hashKeys) {
	final HashOperations<String, Object, Object> operation = redisTemplate.opsForHash();
	operation.delete(getKey(key), hashKeys);
}
 
Example 15
Source File: RedisServiceImpl.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * 删除一个或多个哈希字段
 * 
 * @time 下午10:07:08
 * 
 * @version V1.0
 * @param key
 * @param hashKeys
 * @return 成功删除的个数
 */
@Override
public Long hashDeleteHashKey(String key, Object... hashKeys) {
	long result = 0l;
	HashOperations<Object, Integer, List<String>> hashOps = redisTemplate.opsForHash();
	if (hashOps.hasKey(key, hashKeys)) {
		result = hashOps.delete(key, hashKeys);
	}
	return result;
}