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

Custom command with Lettuce occurs UnsupportedOperationException #2849

Closed
donggyu81 opened this issue May 8, 2024 · 1 comment
Closed

Custom command with Lettuce occurs UnsupportedOperationException #2849

donggyu81 opened this issue May 8, 2024 · 1 comment

Comments

@donggyu81
Copy link

Bug Report

Current Behavior

I am trying to use the lettuce library to execute a custom command with implements ProtocolKeyword interface. However, after execution, an java.lang.UnsupportedOperationException: io.lettuce.core.output.StatusOutput does not support set(long) exception occurs.

Stack trace
Exception in thread "main" java.lang.UnsupportedOperationException: io.lettuce.core.output.StatusOutput does not support set(long)
	at io.lettuce.core.output.CommandOutput.set(CommandOutput.java:107)
	at io.lettuce.core.protocol.RedisStateMachine.safeSet(RedisStateMachine.java:777)
	at io.lettuce.core.protocol.RedisStateMachine.handleInteger(RedisStateMachine.java:428)
	at io.lettuce.core.protocol.RedisStateMachine$State$Type.handle(RedisStateMachine.java:206)
	at io.lettuce.core.protocol.RedisStateMachine.doDecode(RedisStateMachine.java:358)
	at io.lettuce.core.protocol.RedisStateMachine.decode(RedisStateMachine.java:319)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:840)
	at io.lettuce.core.protocol.CommandHandler.decode0(CommandHandler.java:791)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:765)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:657)
	at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:597)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Input Code

Input Code
  • implemented custom command
import java.nio.charset.StandardCharsets;

import io.lettuce.core.protocol.ProtocolKeyword;

public enum Tile38Command implements ProtocolKeyword {
	NEARBY, SEARCH, WITHIN, INTERSECTS;

	private final byte commandBytes[];

	Tile38Command() {
		commandBytes = name().getBytes(StandardCharsets.UTF_8);
	}

	@Override
	public byte[] getBytes() {
		return commandBytes;
	}
}
  • main class
	public static void main(String[] args) throws Exception {
		RedisURI uri = RedisURI.Builder.redis("10.177.189.59", 6397).build();
		RedisClient client = RedisClient.create(uri);
		StatefulRedisConnection<String, String> connection = client.connect();
		RedisCommands<String, String> sync = connection.sync();

		StringCodec codec = StringCodec.UTF8;
		StopWatch stopWatch = new StopWatch("tile38");
		stopWatch.start();
		CommandArgs commandArgs =  new CommandArgs<>(codec)
			.add("am_emd_a_a")
			.add("POINT")
			.add(35.179816)
			.add(129.075022);
		System.out.println(commandArgs.toCommandString());

		String result = sync.dispatch(Tile38Command.INTERSECTS,
			new StatusOutput<>(codec), commandArgs);

		stopWatch.stop();
		System.out.println(stopWatch.prettyPrint());
	}

Expected behavior/code

  • execute custom command and receive resutls.
  • when custom command executes redis client, result is like below.
10.177.189.59:6397>  intersects am_emd_a_a POINT 35.179816 129.075022
1) (integer) 0
2) 1) 1) "2647069000"
      2) "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[129.073100795,35.179060681],...,[129.073100795,35.179060681]]]]},\"properties\":{\"admcode\":\"2647069000\",\"mid\":618}}"

Environment

  • Lettuce version(s): 6.3.2.RELEASE, 6.1.10.RELEASE
  • I executed this code with Tile38(https://tile38.com/)

Possible Solution

Additional context

@donggyu81
Copy link
Author

I have self solved this issue. it's my mistake. intersect returns result with Map or list. so I used NestedMultiOutput class instead of StatusOutput. ( it is matching with single value operation. ). sorry for my mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant