3

I am using Lettuce as Redis client for my Java Spring project. I am doing several operations with RedisTemplate. I'm not able to delete all data from Redis using RedisTemplate.

I tried

redisTemplate.delete("*")

However, this is not making any change.

3 Answers 3

10

Try:

redisTemplate.getConnectionFactory().getConnection().flushAll();

Update: The above method is deprecated since spring-data-redis 3.x. In that case, check:

redisTemplate.getConnectionFactory().getConnection().serverCommands().flushAll();
Sign up to request clarification or add additional context in comments.

2 Comments

it is deprecated
Just use server commands instead: redisTemplate. getConnectionFactory.getConnecion().serverCommands().flushAll()
3

In case you are using kotlin and reactive connection within a suspendable function, the code is:

suspend fun flushCache(): String {
   return redisTemplate.connectionFactory.reactiveConnection.serverCommands().flushDb().awaitSingle()
}

Comments

0

redisTemplate.getConnectionFactory().getConnection().flushAll();

This thing is also deprecated.

You can try this one:

RedisConnection redisConnection = this.redisTemplate.getConnectionFactory().getConnection();

RedisSerializer<String> redisSerializer = this.redisTemplate.getKeySerializer();

DefaultStringRedisConnection defaultStringRedisConnection = new DefaultStringRedisConnection(redisConnection, redisSerializer);

defaultStringRedisConnection.flushAll();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.