jedis icon indicating copy to clipboard operation
jedis copied to clipboard

Adding support for custom JedisProtocol

Open gaspardpetit opened this issue 2 years ago • 5 comments

Supplying a custom JedisProtocol makes it possible to implement custom logging or monitoring or the execution of redis commands. For example, the following JedisProtocol customization would catch and log all commands sent to the redis server:

class LoggingJedisProtocol extends JedisProtocol {
  private static final Logger log = LoggerFactory.getLogger(LoggingJedisProtocol.class);
  
  @Override
  public void sendCommand(final RedisOutputStream os, final ProtocolCommand command, final byte[]... args) { 
    log.trace(command.toString() + "(" + Arrays.stream(args)
            .map(a -> new String(a))
            .collect(Collectors.joining(", ")) + ")");
    super.sendCommand(os, command, args);
  }
}

Refer to https://github.com/redis/jedis/discussions/2635 for general discussion around this pull request

gaspardpetit avatar Aug 26 '21 06:08 gaspardpetit

Test failure seems random - it was from timing in ControlCommandsTest.clientPause(ControlCommandsTest.java:262) on

      assertTrue(pauseMillis <= latencyMillis1 && latencyMillis1 <= pauseMillis + pauseMillisDelta);

Is there a way to can rerun the test?

gaspardpetit avatar Sep 03 '21 02:09 gaspardpetit

@gaspardpetit Please merge/rebase your branch.

sazzad16 avatar Sep 07 '21 05:09 sazzad16

Rebased - please let me know if I did this right

gaspardpetit avatar Sep 07 '21 19:09 gaspardpetit

@gaspardpetit It's okay. (Could be easier though :))

sazzad16 avatar Sep 08 '21 01:09 sazzad16

Hello, I was wondering if there was anything I could do to move this pull request forward? If the approach is not the right one, or you have concerns you would like me to address, please let me know.

gaspardpetit avatar Nov 17 '21 18:11 gaspardpetit

I was directed from https://github.com/redis/jedis/discussions/2635, sorry for the late reply..., I think this idea is good, would you like to continue? @gaspardpetit

yangbodong22011 avatar Jun 16 '23 09:06 yangbodong22011