Example usage for org.springframework.data.redis.connection RedisConnection getClientName

List of usage examples for org.springframework.data.redis.connection RedisConnection getClientName

Introduction

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

Prototype

@Nullable
String getClientName();

Source Link

Document

Returns the name of the current connection.

Usage

From source file:com.zxy.commons.cache.RedisUtils.java

/**
 * Returns the name of the current connection.
 * <p>//from  w  ww .jav  a2 s  . c o m
 * See http://redis.io/commands/client-getname
 * 
 * @return String
 * @since 1.3
 */
public static String getClientName() {
    return redisTemplate.execute(new RedisCallback<String>() {
        @Override
        public String doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.getClientName();
        }
    });
}

From source file:com.zxy.commons.cache.RedisHelper.java

/**
 * Returns the name of the current connection.
 * <p>//w  ww.j  a  v a2s .co  m
 * See http://redis.io/commands/client-getname
 * 
 * @return String
 * @since 1.3
 */
public String getClientName() {
    return redisTemplate.execute(new RedisCallback<String>() {
        @Override
        public String doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.getClientName();
        }
    });
}

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

@Test // DATAREDIS-576
public void connectionAppliesClientName() {

    LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
            .clientResources(LettuceTestClientResources.getSharedClientResources()).clientName("clientName")
            .build();//from w  ww . ja v a2 s .  c  o m

    LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(),
            configuration);
    factory.setShareNativeConnection(false);
    factory.afterPropertiesSet();

    ConnectionFactoryTracker.add(factory);

    RedisConnection connection = factory.getConnection();

    assertThat(connection.getClientName(), is(equalTo("clientName")));
    connection.close();
}

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

@Test // DATAREDIS-576
public void getClientNameShouldEqualWithFactorySetting() {

    LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration());
    factory.setClientResources(LettuceTestClientResources.getSharedClientResources());
    factory.setClientName("clientName");
    factory.afterPropertiesSet();//from  w  ww  .  java  2  s  .co m

    ConnectionFactoryTracker.add(factory);

    RedisConnection connection = factory.getConnection();
    assertThat(connection.getClientName(), equalTo("clientName"));

    connection.close();
}