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

Index value for @Index column not removed after setting value to null #2882

Closed
soheilrahsaz opened this issue Mar 27, 2024 · 0 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@soheilrahsaz
Copy link

soheilrahsaz commented Mar 27, 2024

Using Spring data 3.2.4 and repositories and following this link https://docs.spring.io/spring-data/redis/reference/redis/redis-repositories/indexes.html

@RedisHash("Fruit")
public class Fruit {
    @Id
    private Integer id;
    private String name;
    @Indexed
    private String color;
}

public interface FruitRedisRepository extends CrudRepository<Fruit, Integer> {
    List<Fruit> findByColor(String color);
}

@Configuration
public class RedisConfig {
    @Bean
    public RedisConnectionFactory redisConnectionFactory()
    {
        return new LettuceConnectionFactory("localhost", 16379);
    }
}

This test fails:

@SpringBootTest
class TestSpringRedisApplicationTests {

    @Autowired
    FruitRedisRepository fruitRedisRepository;

    @Test
    void test() {
        //sample fruit with `yellow` as index value
        Fruit banana = Fruit.builder()
                .id(1)
                .name("banana")
                .color("yellow")
                .build();
        fruitRedisRepository.save(banana);

        //retrieving the banana and setting null as color, expecting that the index would be removed
        Fruit foundBanana = fruitRedisRepository.findById(1).orElseThrow();
        foundBanana.setColor(null);
        fruitRedisRepository.save(foundBanana);

        //finding by color yellow, expect empty list, but it actually returns the banana.
        assertThat(fruitRedisRepository.findByColor("yellow")).isEmpty();
    }
}

Expected result is that the index for Fruit:color:yellow is removed, but it still exists in Redis with 1 value with id 1:

Redis output:

smembers Fruit:color:yellow

  1. "1"

Note: If I set another value for color, say purpule it works fine and Fruit:color:yellow is removed and Fruit:color:purpule is created

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 27, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 15, 2024
@mp911de mp911de changed the title @Index column not removed after setting null as the indexed value Index value for @Index column not removed after setting value to null Apr 19, 2024
@mp911de mp911de added this to the 3.1.12 (2023.0.12) milestone Apr 19, 2024
mp911de pushed a commit that referenced this issue Apr 19, 2024
mp911de added a commit that referenced this issue Apr 19, 2024
Reduce allocations by reusing IndexDefinition in RemoveIndexedData.

Tweak test method name.

See #2882
Original pull request: #2895
mp911de pushed a commit that referenced this issue Apr 19, 2024
mp911de added a commit that referenced this issue Apr 19, 2024
Reduce allocations by reusing IndexDefinition in RemoveIndexedData.

Tweak test method name.

See #2882
Original pull request: #2895
mp911de added a commit that referenced this issue Apr 19, 2024
Reduce allocations by reusing IndexDefinition in RemoveIndexedData.

Tweak test method name.

See #2882
Original pull request: #2895
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

Successfully merging a pull request may close this issue.

4 participants