Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException occurs when using RedisCommandFactory with custom commands #1075

Closed
mdebellefeuille opened this issue Jul 5, 2019 · 1 comment
Labels
type: bug A general bug
Milestone

Comments

@mdebellefeuille
Copy link

Bug Report

Current Behavior

when RedisCommandFactory(connection) creates a custom command generates a class cast exception when trying to cast the reactive object to AbstractRedisReactiveCommands because the reactive object has been proxied (((StatefulRedisClusterConnection) connection).reactive() is a proxy)

Stack trace
java.lang.ClassCastException: com.sun.proxy.$Proxy67 cannot be cast to io.lettuce.core.AbstractRedisReactiveCommands
	at io.lettuce.core.dynamic.RedisCommandFactory$CompositeCommandLookupStrategy.<init>(RedisCommandFactory.java:254)
	at io.lettuce.core.dynamic.RedisCommandFactory.getCommands(RedisCommandFactory.java:188)

Input Code

Input Code
public interface CustomCommands extends Commands {
	@Command("SET :key :value EX :ex")
	RedisFuture<String> setex(@Param("key") String key, @Param("ex") Long ttl, @Param("value") byte[] value);
}
final int REDIS_CONNECTION_POOL_SIZE = 3;
final int REDIS_CONNECTION_MAX_WAIT_MILLIS = 5000;
final Duration redisClusterRefreshPeriod = Duration.ofMinutes(1);
final Duration redisClusterEventEmitInterval = Duration.ofMinutes(1);
final ClientResources res = DefaultClientResources.builder().commandLatencyPublisherOptions(DefaultEventPublisherOptions.builder().eventEmitInterval(redisClusterEventEmitInterval).build()).build();
final ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions.builder().enablePeriodicRefresh(redisClusterRefreshPeriod).enableAllAdaptiveRefreshTriggers().build();

final RedisClusterClient redisClient = RedisClusterClient.create(res, getRedisClusterDbUri());
redisClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(topologyRefreshOptions).cancelCommandsOnReconnectFailure(true).validateClusterNodeMembership(false).disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build());

final GenericObjectPoolConfig redisConnectionPoolConfig = new GenericObjectPoolConfig();
redisConnectionPoolConfig.setMaxWaitMillis(REDIS_CONNECTION_MAX_WAIT_MILLIS);
redisConnectionPoolConfig.setMaxIdle(REDIS_CONNECTION_POOL_SIZE);
redisConnectionPoolConfig.setMaxTotal(REDIS_CONNECTION_POOL_SIZE);
final GenericObjectPool<StatefulRedisClusterConnection<String, String>> redisConnectionPool = ConnectionPoolSupport.createGenericObjectPool(redisClient::connect,redisConnectionPoolConfig);

try (final StatefulRedisClusterConnection<String, String> connect = redisConnectionPool.borrowObject()) {
final CustomCommands commands = new RedisCommandFactory(connect).getCommands(CustomCommands.class);
}

Expected behavior/code

The object interface should be initialized

Environment

  • Lettuce version(s): 5.1.7.RELEASE
  • Redis version: 3.2.12

Possible Solution

Additional context

@mdebellefeuille mdebellefeuille added the type: bug A general bug label Jul 5, 2019
@mp911de mp911de added this to the 5.2.0 milestone Jul 6, 2019
mp911de added a commit that referenced this issue Jul 6, 2019
RedisCommandFactory now unwraps the reactive API which can potentially be a proxy (e.g. when using connection pooling) so we get hold of the implementation to invoke properly createMono(…) and createFlux(…).
mp911de added a commit that referenced this issue Jul 6, 2019
RedisCommandFactory now unwraps the reactive API which can potentially be a proxy (e.g. when using connection pooling) so we get hold of the implementation to invoke properly createMono(…) and createFlux(…).
@mp911de
Copy link
Collaborator

mp911de commented Jul 6, 2019

Thanks for report. That's fixed now.

@mp911de mp911de closed this as completed Jul 6, 2019
@mp911de mp911de modified the milestones: 5.2.0, 5.1.8 Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants