package com.lunhan.xxx.common.cache;
|
|
import com.lunhan.xxx.common.config.SysConfig;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.lang.Nullable;
|
|
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
|
public class RedisKeySerializer implements RedisSerializer<String> {
|
private static final Charset charset = StandardCharsets.UTF_8;
|
|
/*
|
* (non-Javadoc)
|
* @see org.springframework.data.redis.serializer.RedisSerializer#deserialize(byte[])
|
*/
|
@Override
|
public String deserialize(@Nullable byte[] bytes) {
|
return (bytes == null ? null : new String(bytes, charset).replaceFirst(SysConfig.redis.getKeyPrefix(), ""));
|
}
|
|
/*
|
* (non-Javadoc)
|
* @see org.springframework.data.redis.serializer.RedisSerializer#serialize(java.lang.Object)
|
*/
|
@Override
|
public byte[] serialize(@Nullable String string) {
|
return (string == null ? null : (SysConfig.redis.getKeyPrefix() + string).getBytes(charset));
|
}
|
}
|