mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-07-31 15:56:18 +08:00
修复jFinal,jboot插件Redis缓存方法与通用方法不一致的问题
增加缓存序列化方法
This commit is contained in:
parent
4784cbd103
commit
9c852da49b
@ -1,36 +1,22 @@
|
||||
package cn.dev33.satoken.jboot;
|
||||
|
||||
import com.jfinal.kit.LogKit;
|
||||
import com.jfinal.plugin.redis.serializer.ISerializer;
|
||||
import com.jfinal.plugin.redis.serializer.JdkSerializer;
|
||||
import redis.clients.jedis.util.SafeEncoder;
|
||||
import com.jfinal.log.Log;
|
||||
import io.jboot.components.serializer.JbootSerializer;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class SaJdkSerializer implements ISerializer {
|
||||
public class SaJdkSerializer implements JbootSerializer {
|
||||
|
||||
public static final ISerializer me = new JdkSerializer();
|
||||
private static final Log LOG = Log.getLog(SaJdkSerializer.class);
|
||||
|
||||
public byte[] keyToBytes(String key) {
|
||||
return SafeEncoder.encode(key);
|
||||
}
|
||||
|
||||
public String keyFromBytes(byte[] bytes) {
|
||||
return SafeEncoder.encode(bytes);
|
||||
}
|
||||
|
||||
public byte[] fieldToBytes(Object field) {
|
||||
return valueToBytes(field);
|
||||
}
|
||||
|
||||
public Object fieldFromBytes(byte[] bytes) {
|
||||
return valueFromBytes(bytes);
|
||||
}
|
||||
|
||||
public byte[] valueToBytes(Object value) {
|
||||
@Override
|
||||
public byte[] serialize(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
ObjectOutputStream objectOut = null;
|
||||
try {
|
||||
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(1024);
|
||||
@ -45,14 +31,15 @@ public class SaJdkSerializer implements ISerializer {
|
||||
finally {
|
||||
if(objectOut != null)
|
||||
try {objectOut.close();} catch (Exception e) {
|
||||
LogKit.error(e.getMessage(), e);}
|
||||
LOG.error(e.getMessage(), e);}
|
||||
}
|
||||
}
|
||||
|
||||
public Object valueFromBytes(byte[] bytes) {
|
||||
if(bytes == null || bytes.length == 0)
|
||||
@Override
|
||||
public Object deserialize(byte[] bytes) {
|
||||
if (bytes == null || bytes.length == 0) {
|
||||
return null;
|
||||
|
||||
}
|
||||
ObjectInputStream objectInput = null;
|
||||
try {
|
||||
ByteArrayInputStream bytesInput = new ByteArrayInputStream(bytes);
|
||||
@ -64,7 +51,7 @@ public class SaJdkSerializer implements ISerializer {
|
||||
}
|
||||
finally {
|
||||
if (objectInput != null)
|
||||
try {objectInput.close();} catch (Exception e) {LogKit.error(e.getMessage(), e);}
|
||||
try {objectInput.close();} catch (Exception e) {LOG.error(e.getMessage(), e);}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class SaJedisImpl {
|
||||
Integer port = config.getPort();
|
||||
Integer timeout = config.getTimeout();
|
||||
String password = config.getPassword();
|
||||
Integer database = config.getSadb();
|
||||
Integer database = config.getDb()==null?config.getDatabase():config.getDb();
|
||||
String clientName = config.getClientName();
|
||||
|
||||
if (host.contains(":")) {
|
||||
|
@ -11,14 +11,14 @@ import io.jboot.support.redis.JbootRedisConfig;
|
||||
)
|
||||
public class SaRedisConfig extends JbootRedisConfig{
|
||||
|
||||
private Integer sadb = 1;
|
||||
private Integer db;
|
||||
|
||||
public Integer getSadb() {
|
||||
return this.sadb;
|
||||
public Integer getDb() {
|
||||
return this.db;
|
||||
}
|
||||
|
||||
public void setSadb(Integer sadb) {
|
||||
this.sadb = sadb;
|
||||
public void setDb(Integer db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,10 @@ package cn.dev33.satoken.jfinal.test;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.context.SaTokenContext;
|
||||
import cn.dev33.satoken.jfinal.*;
|
||||
import com.jfinal.config.*;
|
||||
import com.jfinal.plugin.redis.RedisPlugin;
|
||||
import com.jfinal.template.Engine;
|
||||
import cn.dev33.satoken.jfinal.SaAnnotationInterceptor;
|
||||
import cn.dev33.satoken.jfinal.SaTokenActionHandler;
|
||||
import cn.dev33.satoken.jfinal.SaTokenContextForJfinal;
|
||||
import cn.dev33.satoken.jfinal.SaTokenDaoRedis;
|
||||
|
||||
public class Config extends JFinalConfig {
|
||||
|
||||
@ -62,7 +59,9 @@ public class Config extends JFinalConfig {
|
||||
* @return
|
||||
*/
|
||||
private RedisPlugin createRedisPlugin(String name, Integer dbIndex) {
|
||||
return new RedisPlugin(name, "redis-host", 6379, 3000,"pwd",dbIndex);
|
||||
RedisPlugin redisPlugin=new RedisPlugin(name, "redis-host", 6379, 3000,"pwd",dbIndex);
|
||||
redisPlugin.setSerializer(SaJdkSerializer.me);
|
||||
return redisPlugin;
|
||||
}
|
||||
@Override
|
||||
public void onStart(){
|
||||
|
Loading…
Reference in New Issue
Block a user