Java Code Examples for io.lettuce.core.RedisClient#shutdown()
The following examples show how to use
io.lettuce.core.RedisClient#shutdown() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisBackedJobServiceTest.java From feast with Apache License 2.0 | 7 votes |
@Test public void shouldRecoverIfRedisConnectionIsLost() { RedisClient client = RedisClient.create(RedisURI.create("localhost", REDIS_PORT)); RedisBackedJobService jobService = new RedisBackedJobService(client.connect(new ByteArrayCodec())); jobService.get("does not exist"); redis.stop(); try { jobService.get("does not exist"); } catch (Exception e) { // pass, this should fail, and return a broken connection to the pool } redis.start(); jobService.get("does not exist"); client.shutdown(); }
Example 2
Source File: RedisFeatureSink.java From feast with Apache License 2.0 | 6 votes |
@Override public PCollection<FeatureSetReference> prepareWrite( PCollection<KV<FeatureSetReference, FeatureSetProto.FeatureSetSpec>> featureSetSpecs) { if (getRedisConfig() != null) { RedisClient redisClient = RedisClient.create( RedisURI.create(getRedisConfig().getHost(), getRedisConfig().getPort())); try { redisClient.connect(); } catch (RedisConnectionException e) { throw new RuntimeException( String.format( "Failed to connect to Redis at host: '%s' port: '%d'. Please check that your Redis is running and accessible from Feast.", getRedisConfig().getHost(), getRedisConfig().getPort())); } redisClient.shutdown(); } else if (getRedisClusterConfig() == null) { throw new RuntimeException( "At least one RedisConfig or RedisClusterConfig must be provided to Redis Sink"); } specsView = featureSetSpecs.apply(ParDo.of(new ReferenceToString())).apply(View.asMultimap()); return featureSetSpecs.apply(Keys.create()); }
Example 3
Source File: TracingLettuce52Test.java From java-redis-client with Apache License 2.0 | 6 votes |
@Test public void pubSub() { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisPubSubConnection<String, String> connection = new TracingStatefulRedisPubSubConnection<>(client.connectPubSub(), new TracingConfiguration.Builder(mockTracer).build()); connection.addListener(new RedisPubSubAdapter<>()); RedisPubSubCommands<String, String> commands = connection.sync(); commands.subscribe("channel"); final RedisCommands<String, String> commands2 = client.connect().sync(); commands2.publish("channel", "msg"); client.shutdown(); await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(), equalTo(3)); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(3, spans.size()); }
Example 4
Source File: TracingLettuce52Test.java From java-redis-client with Apache License 2.0 | 6 votes |
@Test public void sync() { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisCommands<String, String> commands = connection.sync(); assertEquals("OK", commands.set("key", "value")); assertEquals("value", commands.get("key")); connection.close(); client.shutdown(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 5
Source File: TracingLettuce50Test.java From java-redis-client with Apache License 2.0 | 6 votes |
@Test public void pubSub() { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisPubSubConnection<String, String> connection = new TracingStatefulRedisPubSubConnection<>(client.connectPubSub(), new TracingConfiguration.Builder(mockTracer).build()); connection.addListener(new RedisPubSubAdapter<>()); RedisPubSubCommands<String, String> commands = connection.sync(); commands.subscribe("channel"); final RedisCommands<String, String> commands2 = client.connect().sync(); commands2.publish("channel", "msg"); client.shutdown(); await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(), equalTo(3)); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(3, spans.size()); }
Example 6
Source File: TracingLettuce50Test.java From java-redis-client with Apache License 2.0 | 6 votes |
@Test public void sync() { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisCommands<String, String> commands = connection.sync(); assertEquals("OK", commands.set("key", "value")); assertEquals("value", commands.get("key")); connection.close(); client.shutdown(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 7
Source File: LettuceController.java From skywalking with Apache License 2.0 | 6 votes |
@RequestMapping("/lettuce-case") @ResponseBody public String lettuceCase() { RedisClient redisClient = RedisClient.create("redis://" + address); StatefulRedisConnection<String, String> connection0 = redisClient.connect(); RedisCommands<String, String> syncCommand = connection0.sync(); syncCommand.get("key"); StatefulRedisConnection<String, String> connection1 = redisClient.connect(); RedisAsyncCommands<String, String> asyncCommands = connection1.async(); asyncCommands.setAutoFlushCommands(false); List<RedisFuture<?>> futures = new ArrayList<>(); futures.add(asyncCommands.set("key0", "value0")); futures.add(asyncCommands.set("key1", "value1")); asyncCommands.flushCommands(); LettuceFutures.awaitAll(5, TimeUnit.SECONDS, futures.toArray(new RedisFuture[futures.size()])); connection0.close(); connection1.close(); redisClient.shutdown(); return "Success"; }
Example 8
Source File: TracingLettuce51Test.java From java-redis-client with Apache License 2.0 | 6 votes |
@Test public void pubSub() { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisPubSubConnection<String, String> connection = new TracingStatefulRedisPubSubConnection<>(client.connectPubSub(), new TracingConfiguration.Builder(mockTracer).build()); connection.addListener(new RedisPubSubAdapter<>()); RedisPubSubCommands<String, String> commands = connection.sync(); commands.subscribe("channel"); final RedisCommands<String, String> commands2 = client.connect().sync(); commands2.publish("channel", "msg"); client.shutdown(); await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(), equalTo(3)); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(3, spans.size()); }
Example 9
Source File: TracingLettuce51Test.java From java-redis-client with Apache License 2.0 | 6 votes |
@Test public void sync() { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisCommands<String, String> commands = connection.sync(); assertEquals("OK", commands.set("key", "value")); assertEquals("value", commands.get("key")); connection.close(); client.shutdown(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 10
Source File: RequiresRedisSentinel.java From spring-data-examples with Apache License 2.0 | 5 votes |
private boolean isAvailable(RedisNode node) { RedisClient redisClient = RedisClient.create(ManagedClientResources.getClientResources(), RedisURI.create(node.getHost(), node.getPort())); try (StatefulRedisConnection<String, String> connection = redisClient.connect()) { connection.sync().ping(); } catch (Exception e) { return false; } finally { redisClient.shutdown(Duration.ZERO, Duration.ZERO); } return true; }
Example 11
Source File: RequiresRedisServer.java From spring-data-examples with Apache License 2.0 | 5 votes |
@Override protected void before() throws Throwable { try (Socket socket = new Socket()) { socket.setTcpNoDelay(true); socket.setSoLinger(true, 0); socket.connect(new InetSocketAddress(host, port), timeout); } catch (Exception e) { throw new AssumptionViolatedException(String.format("Seems as Redis is not running at %s:%s.", host, port), e); } if (NO_VERSION.equals(requiredVersion)) { return; } RedisClient redisClient = RedisClient.create(ManagedClientResources.getClientResources(), RedisURI.create(host, port)); try (StatefulRedisConnection<String, String> connection = redisClient.connect()) { String infoServer = connection.sync().info("server"); String redisVersion = LettuceConverters.stringToProps().convert(infoServer).getProperty("redis_version"); Version runningVersion = Version.parse(redisVersion); if (runningVersion.isLessThan(requiredVersion)) { throw new AssumptionViolatedException(String .format("This test requires Redis version %s but you run version %s", requiredVersion, runningVersion)); } } finally { redisClient.shutdown(Duration.ZERO, Duration.ZERO); } }
Example 12
Source File: TracingLettuce51Test.java From java-redis-client with Apache License 2.0 | 5 votes |
@Test public void async_continue_span() throws Exception { final MockSpan parent = mockTracer.buildSpan("test").start(); try (Scope ignored = mockTracer.activateSpan(parent)) { Span activeSpan = mockTracer.activeSpan(); RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisAsyncCommands<String, String> commands = connection.async(); assertEquals("OK", commands.set("key2", "value2").toCompletableFuture().thenApply(s -> { assertSame(activeSpan, mockTracer.activeSpan()); return s; }).get(15, TimeUnit.SECONDS)); connection.close(); client.shutdown(); } parent.finish(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 13
Source File: TracingLettuce50Test.java From java-redis-client with Apache License 2.0 | 5 votes |
@Test public void async_continue_span() throws Exception { final MockSpan parent = mockTracer.buildSpan("test").start(); try (Scope ignored = mockTracer.activateSpan(parent)) { Span activeSpan = mockTracer.activeSpan(); RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisAsyncCommands<String, String> commands = connection.async(); assertEquals("OK", commands.set("key2", "value2").toCompletableFuture().thenApply(s -> { assertSame(activeSpan, mockTracer.activeSpan()); return s; }).get(15, TimeUnit.SECONDS)); connection.close(); client.shutdown(); } parent.finish(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 14
Source File: TracingLettuce52Test.java From java-redis-client with Apache License 2.0 | 5 votes |
@Test public void async_continue_span() throws Exception { final MockSpan parent = mockTracer.buildSpan("test").start(); try (Scope ignored = mockTracer.activateSpan(parent)) { Span activeSpan = mockTracer.activeSpan(); RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisAsyncCommands<String, String> commands = connection.async(); assertEquals("OK", commands.set("key2", "value2").toCompletableFuture().thenApply(s -> { assertSame(activeSpan, mockTracer.activeSpan()); return s; }).get(15, TimeUnit.SECONDS)); connection.close(); client.shutdown(); } parent.finish(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 15
Source File: TracingLettuce51Test.java From java-redis-client with Apache License 2.0 | 4 votes |
@Test public void async() throws Exception { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisAsyncCommands<String, String> commands = connection.async(); assertEquals("OK", commands.set("key2", "value2").get(15, TimeUnit.SECONDS)); assertEquals("value2", commands.get("key2").get(15, TimeUnit.SECONDS)); connection.close(); client.shutdown(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 16
Source File: TracingLettuce50Test.java From java-redis-client with Apache License 2.0 | 4 votes |
@Test public void async() throws Exception { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisAsyncCommands<String, String> commands = connection.async(); assertEquals("OK", commands.set("key2", "value2").get(15, TimeUnit.SECONDS)); assertEquals("value2", commands.get("key2").get(15, TimeUnit.SECONDS)); connection.close(); client.shutdown(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }
Example 17
Source File: TracingLettuce52Test.java From java-redis-client with Apache License 2.0 | 4 votes |
@Test public void async() throws Exception { RedisClient client = RedisClient.create("redis://localhost"); StatefulRedisConnection<String, String> connection = new TracingStatefulRedisConnection<>(client.connect(), new TracingConfiguration.Builder(mockTracer).build()); RedisAsyncCommands<String, String> commands = connection.async(); assertEquals("OK", commands.set("key2", "value2").get(15, TimeUnit.SECONDS)); assertEquals("value2", commands.get("key2").get(15, TimeUnit.SECONDS)); connection.close(); client.shutdown(); List<MockSpan> spans = mockTracer.finishedSpans(); assertEquals(2, spans.size()); }