You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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"
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
The text was updated successfully, but these errors were encountered:
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 nullApr 19, 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
This test fails:
Expected result is that the index for
Fruit:color:yellow
is removed, but it still exists inRedis
with 1 value with id1
:Redis output:
Note: If I set another value for color, say
purpule
it works fine andFruit:color:yellow
is removed andFruit:color:purpule
is createdThe text was updated successfully, but these errors were encountered: