use of org.springframework.data.redis.connection.RedisConnection in project springBoot-learn-demo by nbfujx.
the class RedisLock method setNX.
private boolean setNX(final String key, final String value) {
Object obj = null;
try {
obj = redisTemplate.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisSerializer serializer = new StringRedisSerializer();
Boolean success = connection.setNX(serializer.serialize(key), serializer.serialize(value));
connection.close();
return success;
}
});
} catch (Exception e) {
logger.error("setNX redis error, key : {}", key);
}
return obj != null ? (Boolean) obj : false;
}
use of org.springframework.data.redis.connection.RedisConnection in project Spring-Family by Sierou-Java.
the class RedisLock method setNX.
private boolean setNX(final String key, final String value) {
Object obj = null;
try {
obj = redisTemplate.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisSerializer serializer = new StringRedisSerializer();
Boolean success = connection.setNX(serializer.serialize(key), serializer.serialize(value));
connection.close();
return success;
}
});
} catch (Exception e) {
log.error("setNX redis error, key : {}", key);
}
return obj != null ? (Boolean) obj : false;
}
use of org.springframework.data.redis.connection.RedisConnection in project Spring-Family by Sierou-Java.
the class RedisLock method get.
private String get(final String key) {
Object obj = null;
try {
obj = redisTemplate.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisSerializer serializer = new StringRedisSerializer();
byte[] data = connection.get(serializer.serialize(key));
connection.close();
if (data == null) {
return null;
}
return serializer.deserialize(data);
}
});
} catch (Exception e) {
log.error("get redis error, key : {}", key);
}
return obj != null ? obj.toString() : null;
}
use of org.springframework.data.redis.connection.RedisConnection in project spring-session by spring-projects.
the class AbstractHttpSessionListenerTests method createMockRedisConnection.
static RedisConnectionFactory createMockRedisConnection() {
RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
RedisConnection connection = mock(RedisConnection.class);
given(factory.getConnection()).willReturn(connection);
given(connection.getConfig(anyString())).willReturn(new Properties());
return factory;
}
use of org.springframework.data.redis.connection.RedisConnection in project spring-session by spring-projects.
the class RedisHttpSessionConfigurationXmlTests method connectionFactory.
static RedisConnectionFactory connectionFactory() {
RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
RedisConnection connection = mock(RedisConnection.class);
given(factory.getConnection()).willReturn(connection);
given(connection.getConfig(anyString())).willReturn(new Properties());
return factory;
}
Aggregations