Java 类org.springframework.data.redis.core.RedisConnectionUtils 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RedisHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    RedisConnection connection = RedisConnectionUtils
            .getConnection(this.redisConnectionFactory);
    try {
        if (connection instanceof RedisClusterConnection) {
            ClusterInfo clusterInfo = ((RedisClusterConnection) connection)
                    .clusterGetClusterInfo();
            builder.up().withDetail("cluster_size", clusterInfo.getClusterSize())
                    .withDetail("slots_up", clusterInfo.getSlotsOk())
                    .withDetail("slots_fail", clusterInfo.getSlotsFail());
        }
        else {
            Properties info = connection.info();
            builder.up().withDetail(VERSION, info.getProperty(REDIS_VERSION));
        }
    }
    finally {
        RedisConnectionUtils.releaseConnection(connection,
                this.redisConnectionFactory);
    }
}
项目:xlator    文件:RedisCacheMonitor.java   
@Scheduled(fixedDelay = 5000)
public void monitor() {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    // @see http://redis.io/commands/INFO
    RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
    try {
        Properties props = connection.info();
        Long hitCount = Long.parseLong(props.getProperty("keyspace_hits"));
        Long missCount = Long.parseLong(props.getProperty("keyspace_misses"));
        statistics.setGetCacheCounts(hitCount, missCount);
        // we do not currently have a way of calculating the cache size, so we have to filter
        List<Metric<?>> metrics = statistics
                                    .toMetrics("cache.")
                                        .stream()
                                            .filter(f -> !f.getName().contains(".size"))
                                            .collect(Collectors.toList());
        metrics.forEach(m -> metricServices.submit(m.getName(), (Double) m.getValue()));
    } finally {
        RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory);
    }
}
项目:iBase4J-Common    文件:RedisHelper.java   
@Override
public boolean setnx(String key, Serializable value) {
    RedisConnectionFactory factory = redisTemplate.getConnectionFactory();
    RedisConnection redisConnection = null;
    try {
        redisConnection = RedisConnectionUtils.getConnection(factory);
        if (redisConnection == null) {
            return redisTemplate.boundValueOps(key).setIfAbsent(value);
        }
        return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize(value));
    } finally {
        RedisConnectionUtils.releaseConnection(redisConnection, factory);
    }
}
项目:iBase4J-Common    文件:RedisHelper.java   
@Override
public boolean lock(String key) {
    RedisConnectionFactory factory = redisTemplate.getConnectionFactory();
    RedisConnection redisConnection = null;
    try {
        redisConnection = RedisConnectionUtils.getConnection(factory);
        if (redisConnection == null) {
            return redisTemplate.boundValueOps(key).setIfAbsent("0");
        }
        return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize("0"));
    } finally {
        RedisConnectionUtils.releaseConnection(redisConnection, factory);
    }
}
项目:redis-admin    文件:RedisServiceImpl.java   
private String getDataType(String serverName, int dbIndex, String key) {
    RedisTemplate redisTemplate = RedisApplication.redisTemplatesMap.get(serverName);
    RedisConnection connection = RedisConnectionUtils.getConnection(redisTemplate.getConnectionFactory());
    connection.select(dbIndex);
    DataType dataType = connection.type(key.getBytes());
    connection.close();
    return dataType.name().toUpperCase();
}
项目:redis-admin    文件:RedisServiceImpl.java   
private Object getKV(String serverName, int dbIndex, String key) {
    RedisTemplate redisTemplate = RedisApplication.redisTemplatesMap.get(serverName);
    RedisConnection connection = RedisConnectionUtils.getConnection(redisTemplate.getConnectionFactory());
    connection.select(dbIndex);
    DataType dataType = connection.type(key.getBytes());
    connection.close();
    Object values = null;
    switch(dataType) {
    case STRING:
        values = redisDao.getSTRING(serverName, dbIndex, key);
        break;
    case LIST:
        values = redisDao.getLIST(serverName, dbIndex, key);
        break;
    case SET:
        values = redisDao.getSET(serverName, dbIndex, key);
        break;
    case ZSET:
        values = redisDao.getZSET(serverName, dbIndex, key);
        break;
    case HASH:
        values = redisDao.getHASH(serverName, dbIndex, key);
        break;
    case NONE:
        //never be here
        values = null;
    }
    return values;
}
项目:redis-admin    文件:RedisApplication.java   
protected void initRedisKeysCache(RedisTemplate redisTemplate, String serverName , int dbIndex) {
    RedisConnection connection = RedisConnectionUtils.getConnection(redisTemplate.getConnectionFactory());
    connection.select(dbIndex);
    Set<byte[]> keysSet = connection.keys("*".getBytes());
    connection.close();
    List<RKey> tempList = new ArrayList<RKey>();
    ConvertUtil.convertByteToString(connection, keysSet, tempList);
    Collections.sort(tempList);
    CopyOnWriteArrayList<RKey> redisKeysList = new CopyOnWriteArrayList<RKey>(tempList);
    if(redisKeysList.size()>0) {
        redisKeysListMap.put(serverName+DEFAULT_SEPARATOR+dbIndex, redisKeysList);
    }
}
项目:spring-boot-concourse    文件:RedisHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    RedisConnection connection = RedisConnectionUtils
            .getConnection(this.redisConnectionFactory);
    try {
        Properties info = connection.info();
        builder.up().withDetail("version", info.getProperty("redis_version"));
    }
    finally {
        RedisConnectionUtils.releaseConnection(connection,
                this.redisConnectionFactory);
    }
}
项目:xlator    文件:RedisCacheStatisticsProvider.java   
@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager, RedisCache cache) {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    // @see http://redis.io/commands/INFO
    RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
    try {
        Properties props = connection.info();
        Long hitCount = Long.parseLong(props.getProperty("keyspace_hits"));
        Long missCount = Long.parseLong(props.getProperty("keyspace_misses"));
        statistics.setGetCacheCounts(hitCount, missCount);
    } finally {
        RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory);
    }
    return statistics;
}
项目:contestparser    文件:RedisHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    RedisConnection connection = RedisConnectionUtils
            .getConnection(this.redisConnectionFactory);
    try {
        Properties info = connection.info();
        builder.up().withDetail("version", info.getProperty("redis_version"));
    }
    finally {
        RedisConnectionUtils.releaseConnection(connection,
                this.redisConnectionFactory);
    }
}
项目:keti    文件:AbstractCacheHealthIndicator.java   
@Override
public RedisConnection getRedisConnection() {
    return RedisConnectionUtils.getConnection(this.redisConnectionFactory);
}