package com.sandu.common.redis;
|
|
import cn.hutool.core.util.StrUtil;
|
import org.springframework.lang.Nullable;
|
|
import java.util.Optional;
|
|
/**
|
* @author chenjiantian
|
*/
|
public abstract class BasePrefix implements KeyPrefix {
|
|
private final int expireSeconds;
|
|
private final String prefix;
|
|
public BasePrefix(int expireSeconds, String prefix) {
|
this.expireSeconds = expireSeconds;
|
this.prefix = prefix;
|
}
|
|
@Override
|
public int expireSeconds() {//默认0代表永不过期
|
return expireSeconds;
|
}
|
|
@Override
|
public String key(@Nullable String uniqueId) {
|
String modelName = getModelName();
|
if(StrUtil.isEmpty(modelName)){
|
throw new IllegalArgumentException("modelName 不能为空");
|
}
|
return modelName + ":" + prefix + ":" + Optional.ofNullable(uniqueId).orElse("");
|
}
|
}
|