org.ssssssss.magicapi.modules.RedisModule Maven / Gradle / Ivy
package org.ssssssss.magicapi.modules;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.ssssssss.magicapi.config.MagicModule;
import org.ssssssss.script.functions.DynamicMethod;
import java.util.ArrayList;
import java.util.List;
/**
* redis模块
*/
public class RedisModule implements MagicModule, DynamicMethod {
private final StringRedisTemplate redisTemplate;
public RedisModule(RedisConnectionFactory connectionFactory) {
this.redisTemplate = new StringRedisTemplate(connectionFactory);
}
@Override
public String getModuleName() {
return "redis";
}
/**
* 序列化
*/
private byte[] serializer(Object value) {
if (value == null || value instanceof String) {
return redisTemplate.getStringSerializer().serialize((String) value);
}
return serializer(value.toString());
}
/**
* 反序列化
*/
private Object deserialize(Object value) {
if (value != null) {
if (value instanceof byte[]) {
return this.redisTemplate.getStringSerializer().deserialize((byte[]) value);
}
if (value instanceof List) {
@SuppressWarnings("unchecked")
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy