redis添加字符串存储类型支持

This commit is contained in:
2025-07-28 10:08:17 +08:00
parent fc43704b2c
commit 2009009296
2 changed files with 16 additions and 1 deletions

View File

@@ -2,10 +2,12 @@ package com.njcn.redis.utils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -351,4 +353,17 @@ public class RedisUtil {
return database; return database;
} }
/**
* 获取value为字符串的
* @param key
* @return
*/
public String getRawValue(String key) {
return redisTemplate.execute((RedisCallback<String>) connection -> {
byte[] data = connection.get(key.getBytes());
return data == null ? null : new String(data, StandardCharsets.UTF_8);
});
}
} }

View File

@@ -55,7 +55,7 @@ public class AreaInfoServiceImpl implements AreaInfoService {
} }
}else{ }else{
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalRunDeviceInfo(deviceInfoParam).getData(); List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
lineIds.addAll(generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList())); lineIds.addAll(generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList()));
} }