本文整理汇总了Java中org.springframework.data.redis.core.RedisConnectionUtils.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java RedisConnectionUtils.getConnection方法的具体用法?Java RedisConnectionUtils.getConnection怎么用?Java RedisConnectionUtils.getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.redis.core.RedisConnectionUtils
的用法示例。
在下文中一共展示了RedisConnectionUtils.getConnection方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doHealthCheck
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
@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);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:RedisHealthIndicator.java
示例2: monitor
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
@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);
}
}
示例3: setnx
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
@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);
}
}
示例4: lock
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
@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);
}
}
示例5: getDataType
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
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();
}
示例6: getKV
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
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;
}
示例7: initRedisKeysCache
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
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);
}
}
示例8: doHealthCheck
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
@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);
}
}
示例9: getCacheStatistics
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
@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;
}
示例10: getRedisConnection
import org.springframework.data.redis.core.RedisConnectionUtils; //导入方法依赖的package包/类
@Override
public RedisConnection getRedisConnection() {
return RedisConnectionUtils.getConnection(this.redisConnectionFactory);
}