javaredisspring-data-redis

How to delete all data from Redis using RedisTemplate in java


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.


Solution

  • Try:

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

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

    redisTemplate.getConnectionFactory().getConnecion().serverCommands().flushAll();