Example usage for org.springframework.data.redis.connection StringRedisConnection flushDb

List of usage examples for org.springframework.data.redis.connection StringRedisConnection flushDb

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection StringRedisConnection flushDb.

Prototype

void flushDb();

Source Link

Document

Delete all keys of the currently selected database.

Usage

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test
public void testSelectDb() {

    LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
            SettingsUtils.getPort());/*from   w w  w. jav a  2  s .c  o m*/
    factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
    factory2.setShutdownTimeout(0);
    factory2.setDatabase(1);
    factory2.afterPropertiesSet();

    ConnectionFactoryTracker.add(factory2);

    StringRedisConnection connection2 = new DefaultStringRedisConnection(factory2.getConnection());
    connection2.flushDb();
    // put an item in database 0
    connection.set("sometestkey", "sometestvalue");
    try {
        // there should still be nothing in database 1
        assertEquals(Long.valueOf(0), connection2.dbSize());
    } finally {
        connection2.close();
        factory2.destroy();
    }
}