|
44 | 44 |
|
45 | 45 | import org.apache.commons.logging.Log;
|
46 | 46 | import org.apache.commons.logging.LogFactory;
|
| 47 | + |
47 | 48 | import org.springframework.beans.factory.DisposableBean;
|
48 | 49 | import org.springframework.beans.factory.InitializingBean;
|
49 | 50 | import org.springframework.dao.DataAccessException;
|
|
56 | 57 | import org.springframework.data.redis.connection.RedisConfiguration.DomainSocketConfiguration;
|
57 | 58 | import org.springframework.data.redis.connection.RedisConfiguration.WithDatabaseIndex;
|
58 | 59 | import org.springframework.data.redis.connection.RedisConfiguration.WithPassword;
|
59 |
| -import org.springframework.data.redis.connection.lettuce.LettuceConnection.*; |
60 | 60 | import org.springframework.data.util.Optionals;
|
61 | 61 | import org.springframework.lang.Nullable;
|
62 | 62 | import org.springframework.util.Assert;
|
@@ -788,6 +788,45 @@ public void setClientName(@Nullable String clientName) {
|
788 | 788 | this.getMutableConfiguration().setClientName(clientName);
|
789 | 789 | }
|
790 | 790 |
|
| 791 | + /** |
| 792 | + * Returns the native {@link AbstractRedisClient} used by this instance. The client is initialized as part of |
| 793 | + * {@link #afterPropertiesSet() the bean initialization lifecycle} and only available when this connection factory is |
| 794 | + * initialized. |
| 795 | + * <p/> |
| 796 | + * Depending on the configuration, the client can be either {@link RedisClient} or {@link RedisClusterClient}. |
| 797 | + * |
| 798 | + * @return the native {@link AbstractRedisClient}. Can be {@literal null} if not initialized. |
| 799 | + * @since 2.5 |
| 800 | + * @see #afterPropertiesSet() |
| 801 | + */ |
| 802 | + @Nullable |
| 803 | + public AbstractRedisClient getNativeClient() { |
| 804 | + return this.client; |
| 805 | + } |
| 806 | + |
| 807 | + /** |
| 808 | + * Returns the native {@link AbstractRedisClient} used by this instance. The client is initialized as part of |
| 809 | + * {@link #afterPropertiesSet() the bean initialization lifecycle} and only available when this connection factory is |
| 810 | + * initialized. Throws {@link IllegalStateException} if not yet initialized. |
| 811 | + * <p/> |
| 812 | + * Depending on the configuration, the client can be either {@link RedisClient} or {@link RedisClusterClient}. |
| 813 | + * |
| 814 | + * @return the native {@link AbstractRedisClient}. |
| 815 | + * @since 2.5 |
| 816 | + * @throws IllegalStateException if not yet initialized. |
| 817 | + * @see #getNativeClient() |
| 818 | + */ |
| 819 | + public AbstractRedisClient getRequiredNativeClient() { |
| 820 | + |
| 821 | + AbstractRedisClient client = getNativeClient(); |
| 822 | + |
| 823 | + if (client == null) { |
| 824 | + throw new IllegalStateException("Client not yet initialized"); |
| 825 | + } |
| 826 | + |
| 827 | + return client; |
| 828 | + } |
| 829 | + |
791 | 830 | @Nullable
|
792 | 831 | private String getRedisUsername() {
|
793 | 832 | return RedisConfiguration.getUsernameOrElse(configuration, standaloneConfig::getUsername);
|
|
0 commit comments