use of org.springframework.data.redis.serializer.RedisSerializer in project newblogback by Zephery.
the class TagServiceImpl method updatetag.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Integer updatetag(Integer tId) {
// 标签
List<Tag> tags = tagMapper.getAllTags();
JsonArray jsonArray = new JsonArray();
for (Tag tag : tags) {
List<Blog> blogs = tagMapper.getblogbytagid(tag.gettId());
String str = tag.gettName() + " " + "(" + String.valueOf(blogs.size()) + ")";
KeyAndValue keyAndValue = new KeyAndValue();
keyAndValue.setKey(tag.gettName());
keyAndValue.setValue(str);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("key", tag.gettId());
jsonObject.addProperty("value", str);
jsonArray.add(jsonObject);
}
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
connection.set(serializer.serialize("biaoqian"), serializer.serialize(jsonArray.toString()));
return true;
}
});
return tId;
}
use of org.springframework.data.redis.serializer.RedisSerializer in project lamp-util by zuihou.
the class RedisAutoConfigure method setSerializer.
private void setSerializer(RedisConnectionFactory factory, RedisTemplate template, RedisSerializer<Object> redisSerializer) {
RedisSerializer stringSerializer = new StringRedisSerializer();
template.setKeySerializer(stringSerializer);
template.setHashKeySerializer(stringSerializer);
template.setHashValueSerializer(redisSerializer);
template.setValueSerializer(redisSerializer);
template.setConnectionFactory(factory);
}
use of org.springframework.data.redis.serializer.RedisSerializer in project blog_demos by zq2599.
the class RedisClient method set.
/**
* 更新缓存中的对象,也可以在redis缓存中存入新的对象
*
* @param key
* @param t
* @param <T>
*/
public <T> void set(String key, T t) {
byte[] keyBytes = getKey(key);
RedisSerializer serializer = redisTemplate.getValueSerializer();
byte[] val = serializer.serialize(t);
RedisConnection redisConnection = getConnection();
if (null != redisConnection) {
try {
redisConnection.set(keyBytes, val);
} finally {
releaseConnection(redisConnection);
}
} else {
logger.error("1. can not get valid connection");
}
}
use of org.springframework.data.redis.serializer.RedisSerializer in project blog_demos by zq2599.
the class RedisClient method set.
/**
* 更新缓存中的对象,也可以在redis缓存中存入新的对象
*
* @param key
* @param t
* @param <T>
*/
public <T> void set(String key, T t) {
byte[] keyBytes = getKey(key);
RedisSerializer serializer = redisTemplate.getValueSerializer();
byte[] val = serializer.serialize(t);
RedisConnection redisConnection = getConnection();
if (null != redisConnection) {
try {
redisConnection.set(keyBytes, val);
} finally {
releaseConnection(redisConnection);
}
} else {
logger.error("1. can not get valid connection");
}
}
use of org.springframework.data.redis.serializer.RedisSerializer in project study by youbl.
the class RedisConfiguration method initSerializer.
private static void initSerializer(RedisTemplate template) {
// Key用StringRedisSerializer,避免写入Redis的Key和Value,前缀都会出现 \xAC\xED\x00\x05t\x00\x03
RedisSerializer keySerializer = new StringRedisSerializer();
template.setKeySerializer(keySerializer);
template.setHashKeySerializer(keySerializer);
RedisSerializer valSerializer = new JsonRedisSerializer<>(Object.class);
// template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setValueSerializer(valSerializer);
template.setHashValueSerializer(valSerializer);
}
Aggregations