Java Code Examples for org.springframework.data.redis.connection.RedisConnection#del()

The following examples show how to use org.springframework.data.redis.connection.RedisConnection#del() . 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: CustomRedisTokenStore.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
public void removeRefreshToken(String tokenValue) {
    byte[] refreshKey = serializeKey(REFRESH + tokenValue);
    byte[] refreshAuthKey = serializeKey(REFRESH_AUTH + tokenValue);
    byte[] refresh2AccessKey = serializeKey(REFRESH_TO_ACCESS + tokenValue);
    byte[] access2RefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue);
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.del(refreshKey);
        conn.del(refreshAuthKey);
        conn.del(refresh2AccessKey);
        conn.del(access2RefreshKey);
        conn.closePipeline();
    } finally {
        conn.close();
    }
}
 
Example 2
Source File: CustomRedisTokenStore.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
private void removeAccessTokenUsingRefreshToken(String refreshToken) {
    byte[] key = serializeKey(REFRESH_TO_ACCESS + refreshToken);
    List<Object> results = null;
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.get(key);
        conn.del(key);
        results = conn.closePipeline();
    } finally {
        conn.close();
    }
    if (results == null) {
        return;
    }
    byte[] bytes = (byte[]) results.get(0);
    String accessToken = deserializeString(bytes);
    if (accessToken != null) {
        removeAccessToken(accessToken);
    }
}
 
Example 3
Source File: RedisAuthorizationCodeServices.java    From springcloud-oauth2 with MIT License 6 votes vote down vote up
/**
 * 取出授权码并删除授权码(权限码只能用一次,调试时可不删除,code就可多次使用)
 *
 * @param code
 * @return org.springframework.security.oauth2.provider.OAuth2Authentication
 */
@Override
protected OAuth2Authentication remove(String code) {
    byte[] serializedKey = serializeKey(AUTHORIZATION_CODE + code);
    RedisConnection conn = getConnection();
    byte[] bytes;
    try {
        bytes = conn.get(serializedKey);
        if (bytes != null) {
            conn.del(serializedKey);
        }
    } finally {
        conn.close();
    }
    return deserializeAuthentication(bytes);
}
 
Example 4
Source File: RedisService.java    From xmfcn-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * delete(将 key 缓存数据删除)
 *
 * @param key
 * @return
 */
@RequestMapping("delete")
public Long delete(String key) {
    logger.info("delete(将 key 缓存数据删除) 开始 key={}", key);
    Long result = null;
    if (StringUtil.isBlank(key)) {
        return result;
    }
    RedisConnection conn = getRedisConnection();
    if (conn == null) {
        return result;
    }
    try {
        result = conn.del(key.getBytes());
    } catch (Exception e) {
        logger.error("delete_error:" + StringUtil.getExceptionMsg(e));
    }
    logger.info("delete(将 key 缓存数据删除)结束 key={},result={}", key, result);
    return result;
}
 
Example 5
Source File: CustomRedisTokenStore.java    From Auth-service with MIT License 6 votes vote down vote up
public void removeRefreshToken(String tokenValue) {
    byte[] refreshKey = serializeKey(REFRESH + tokenValue);
    byte[] refreshAuthKey = serializeKey(REFRESH_AUTH + tokenValue);
    byte[] refresh2AccessKey = serializeKey(REFRESH_TO_ACCESS + tokenValue);
    byte[] access2RefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue);
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.del(refreshKey);
        conn.del(refreshAuthKey);
        conn.del(refresh2AccessKey);
        conn.del(access2RefreshKey);
        conn.closePipeline();
    } finally {
        conn.close();
    }
}
 
Example 6
Source File: CustomRedisTokenStore.java    From Auth-service with MIT License 6 votes vote down vote up
private void removeAccessTokenUsingRefreshToken(String refreshToken) {
    byte[] key = serializeKey(REFRESH_TO_ACCESS + refreshToken);
    List<Object> results = null;
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.get(key);
        conn.del(key);
        results = conn.closePipeline();
    } finally {
        conn.close();
    }
    if (results == null) {
        return;
    }
    byte[] bytes = (byte[]) results.get(0);
    String accessToken = deserializeString(bytes);
    if (accessToken != null) {
        removeAccessToken(accessToken);
    }
}
 
Example 7
Source File: RedisSpringDataCache.java    From jetcache with Apache License 2.0 6 votes vote down vote up
@Override
protected CacheResult do_REMOVE(K key) {
    RedisConnection con = null;
    try {
        con = connectionFactory.getConnection();
        byte[] keyBytes = buildKey(key);
        Long result = con.del(keyBytes);
        if (result == null) {
            return new CacheResult(CacheResultCode.FAIL, "result:" + result);
        } else if (result == 1) {
            return CacheResult.SUCCESS_WITHOUT_MSG;
        } else if (result == 0) {
            return new CacheResult(CacheResultCode.NOT_EXISTS, null);
        } else {
            return CacheResult.FAIL_WITHOUT_MSG;
        }
    } catch (Exception ex) {
        logError("REMOVE", key, ex);
        return new CacheResult(ex);
    } finally {
        closeConnection(con);
    }
}
 
Example 8
Source File: RedisSpringDataCache.java    From jetcache with Apache License 2.0 6 votes vote down vote up
@Override
protected CacheResult do_REMOVE_ALL(Set<? extends K> keys) {
    RedisConnection con = null;
    try {
        con = connectionFactory.getConnection();
        byte[][] newKeys = keys.stream().map((k) -> buildKey(k)).toArray((len) -> new byte[keys.size()][]);
        Long result = con.del(newKeys);
        if (result != null) {
            return CacheResult.SUCCESS_WITHOUT_MSG;
        } else {
            return new CacheResult(CacheResultCode.FAIL, "result:" + result);
        }
    } catch (Exception ex) {
        logError("REMOVE_ALL", "keys(" + keys.size() + ")", ex);
        return new CacheResult(ex);
    } finally {
        closeConnection(con);
    }
}
 
Example 9
Source File: RedisClient.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * 删除指定对象
 * @param key
 * @return
 */
public long del(String key){
    RedisConnection redisConnection = getConnection();
    long rlt = 0L;

    if(null!=redisConnection){
        try {
            rlt = redisConnection.del(getKey(key));
        }finally {
            releaseConnection(redisConnection);
        }
    }else{
        logger.error("1. can not get valid connection");
    }
    return rlt;
}
 
Example 10
Source File: RedisLockProvider.java    From ShedLock with Apache License 2.0 6 votes vote down vote up
@Override
public void unlock() {
    Expiration keepLockFor = getExpiration(lockConfiguration.getLockAtLeastUntil());
    RedisConnection redisConnection = null;
    // lock at least until is in the past
    if (keepLockFor.getExpirationTimeInMilliseconds() <= 0) {
        try {
            redisConnection = redisConnectionFactory.getConnection();
            redisConnection.del(key.getBytes());
        } catch (Exception e) {
            throw new LockException("Can not remove node", e);
        } finally {
            close(redisConnection);
        }
    } else {
        try {
            redisConnection = redisConnectionFactory.getConnection();
            redisConnection.set(key.getBytes(), buildValue(lockConfiguration.getLockAtMostUntil()), keepLockFor, SetOption.SET_IF_PRESENT);
        } finally {
            close(redisConnection);
        }
    }
}
 
Example 11
Source File: CustomRedisTokenStore.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
public void removeAccessToken(String tokenValue) {
    byte[] accessKey = serializeKey(ACCESS + tokenValue);
    byte[] authKey = serializeKey(SecurityConstants.REDIS_TOKEN_AUTH + tokenValue);
    byte[] accessToRefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue);
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.get(accessKey);
        conn.get(authKey);
        conn.del(accessKey);
        conn.del(accessToRefreshKey);
        // Don't remove the refresh token - it's up to the caller to do that
        conn.del(authKey);
        List<Object> results = conn.closePipeline();
        byte[] access = (byte[]) results.get(0);
        byte[] auth = (byte[]) results.get(1);

        OAuth2Authentication authentication = deserializeAuthentication(auth);
        if (authentication != null) {
            String key = authenticationKeyGenerator.extractKey(authentication);
            byte[] authToAccessKey = serializeKey(AUTH_TO_ACCESS + key);
            byte[] unameKey = serializeKey(SecurityConstants.REDIS_UNAME_TO_ACCESS + getApprovalKey(authentication));
            byte[] clientId = serializeKey(SecurityConstants.REDIS_CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId());
            conn.openPipeline();
            conn.del(authToAccessKey);
            conn.lRem(unameKey, 1, access);
            conn.lRem(clientId, 1, access);
            conn.del(serialize(ACCESS + key));
            conn.closePipeline();
        }
    } finally {
        conn.close();
    }
}
 
Example 12
Source File: CustomRedisTokenStore.java    From Auth-service with MIT License 5 votes vote down vote up
public void removeAccessToken(String tokenValue) {
    byte[] accessKey = serializeKey(ACCESS + tokenValue);
    byte[] authKey = serializeKey(AUTH + tokenValue);
    byte[] accessToRefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue);
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.get(accessKey);
        conn.get(authKey);
        conn.del(accessKey);
        conn.del(accessToRefreshKey);
        // Don't remove the refresh token - it's up to the caller to do that
        conn.del(authKey);
        List<Object> results = conn.closePipeline();
        byte[] access = (byte[]) results.get(0);
        byte[] auth = (byte[]) results.get(1);

        OAuth2Authentication authentication = deserializeAuthentication(auth);
        if (authentication != null) {
            String key = authenticationKeyGenerator.extractKey(authentication);
            byte[] authToAccessKey = serializeKey(AUTH_TO_ACCESS + key);
            byte[] unameKey = serializeKey(UNAME_TO_ACCESS + getApprovalKey(authentication));
            byte[] clientId = serializeKey(CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId());
            conn.openPipeline();
            conn.del(authToAccessKey);
            conn.lRem(unameKey, 1, access);
            conn.lRem(clientId, 1, access);
            conn.del(serialize(ACCESS + key));
            conn.closePipeline();
        }
    } finally {
        conn.close();
    }
}
 
Example 13
Source File: CustomRedisCacheWriter.java    From spring-microservice-exam with MIT License 4 votes vote down vote up
private Long doUnlock(String name, RedisConnection connection) {
    return connection.del(createCacheLockKey(name));
}
 
Example 14
Source File: DefaultRedisCacheWriter.java    From black-shop with Apache License 2.0 4 votes vote down vote up
private Long doUnlock(String name, RedisConnection connection) {
	return connection.del(createCacheLockKey(name));
}
 
Example 15
Source File: DefaultRedisCacheWriter.java    From gateway-helper with Apache License 2.0 4 votes vote down vote up
private Long doUnlock(String name, RedisConnection connection) {
    return connection.del(createCacheLockKey(name));
}
 
Example 16
Source File: DefaultRedisCacheWriter.java    From api-gateway-old with Apache License 2.0 4 votes vote down vote up
private Long doUnlock(String name, RedisConnection connection) {
    return connection.del(createCacheLockKey(name));
}