spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

`StringRedisConnection` returns `null` using read operations during transactions

Open CHYhave opened this issue 6 months ago • 1 comments

A minimize cases as belong, which expect return some value but get null。

    @GetMapping("/get")
    @Transactional
    public String get(@RequestParam String key) {
        String value = stringRedisTemplate.opsForValue().get(key);
        System.out.println(value);
        return value;
    }

DefaultStringConnection hold LettuceRedisConnection with multi = true, result isFutureConversion() always return true

	@Nullable
	private <T> T convertAndReturn(@Nullable Object value, Converter converter) {

		if (isFutureConversion()) {

			addResultConverter(converter);
			return null;
		}

		if (!(converter instanceof ListConverter) && value instanceof List) {
			return (T) new ListConverter<>(converter).convert((List) value);
		}

		return value == null ? null
				: ObjectUtils.nullSafeEquals(converter, Converters.identityConverter()) ? (T) value
						: (T) converter.convert(value);
	}

截屏2024-08-01 下午7 52 26

CHYhave avatar Aug 01 '24 11:08 CHYhave