问题描述
我正在创建一个spring-data-redis项目,我的要求是在所有键之前添加一些常量字符串。
我尝试为此创建一个CustomStringSerializer
并将其添加到redistemplate
的Bean中,但是它似乎不起作用。
代码就是这样。
public class CustomStringSerializer implements RedisSerializer<String> {
@Autowired
private EnviornmentProperties env;
public static final Charset charset = StandardCharsets.UTF_8;
@Override
public byte[] serialize(String string) throws SerializationException {
String key = string == null ? env.getKeyPrefix() : env.getKeyPrefix().concat(string);
return key.getBytes(charset);
}
@Override
public String deserialize (byte[] bytes) throws SerializationException {
return (bytes == null ? null : new String(bytes,charset));
}
在redistemplate
创建期间,我使用的与
redistemplate.setKeySerializer(customSerializer);
我不确定我在这里缺少什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)