Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringRedisConnection returns null using read operations during transactions #2953

Open
CHYhave opened this issue Aug 1, 2024 · 1 comment
Labels
type: bug A general bug

Comments

@CHYhave
Copy link

CHYhave commented Aug 1, 2024

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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 1, 2024
@mp911de mp911de changed the title StringRedisTemplate return null with read operation under with spring transactional StringRedisConnection returns null using read operations during transactions Aug 1, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 1, 2024
@mp911de
Copy link
Member

mp911de commented Aug 1, 2024

The problem originates in DefaultStringConnection. The backend connection uses a proxy mechanism to determine whether the called method is a read method that should return a value. DefaultStringRedisConnection uses manual decoration without access to command metadata for roughly 530 commands.

As workaround, you can use RedisTemplate<String, String> with StringRedisSerializer.UTF_8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants