Created
October 1, 2018 12:13
-
-
Save jongyeol/edd80cb080aaab1fa619c7001b0ccbed to your computer and use it in GitHub Desktop.
LettuceClientCustomLatencyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.SocketAddress; | |
import java.util.Collections; | |
import java.util.Map; | |
import org.junit.Test; | |
import io.lettuce.core.RedisClient; | |
import io.lettuce.core.api.StatefulRedisConnection; | |
import io.lettuce.core.metrics.CommandLatencyCollector; | |
import io.lettuce.core.metrics.CommandLatencyId; | |
import io.lettuce.core.metrics.CommandMetrics; | |
import io.lettuce.core.protocol.ProtocolKeyword; | |
import io.lettuce.core.resource.ClientResources; | |
/* | |
// before fixing | |
(no stdout) | |
// after fixing | |
recordCommandLatency: SET: 7470963, 9753273 | |
recordCommandLatency: GET: 251762, 4559252 | |
*/ | |
public class LettuceClientCustomLatencyTest { | |
@Test | |
public void testToLocalRedis() { | |
final ClientResources clientResource = ClientResources.builder().commandLatencyCollector(LATENCY_COLLECTOR).build(); | |
final RedisClient client = RedisClient.create(clientResource, "redis://localhost:6479"); | |
try (StatefulRedisConnection<String, String> conn = client.connect()) { | |
conn.sync().set("k1", "value1"); | |
conn.sync().get("k1"); | |
} | |
} | |
private static final CommandLatencyCollector LATENCY_COLLECTOR = new CommandLatencyCollector() { | |
@Override | |
public void recordCommandLatency(SocketAddress local, SocketAddress remote, ProtocolKeyword commandType, | |
long firstResponseLatency, long completionLatency) { | |
System.out.println("recordCommandLatency: " + commandType + ": " + firstResponseLatency + ", " + completionLatency); | |
} | |
@Override | |
public void shutdown() { | |
} | |
@Override | |
public Map<CommandLatencyId, CommandMetrics> retrieveMetrics() { | |
return Collections.emptyMap(); | |
} | |
@Override | |
public boolean isEnabled() { | |
return true; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment