io.lettuce.core.RedisClient Java Examples

The following examples show how to use io.lettuce.core.RedisClient. 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 vote down vote up
@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: LettuceController.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: RedisRateLimiterConfiguration.java    From daming with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(value = RequestRateLimiterFactory.class)
public RedisRateLimiterFactory redisRateLimiterFactory(ClientResources redisClientResources, RedisProperties redisProperties) {
    RedisURI.Builder builder = RedisURI.builder()
            .withHost(redisProperties.getHost())
            .withPort(redisProperties.getPort());
    if (!StringUtils.isEmpty(redisProperties.getPassword())) {
        builder = builder.withPassword(redisProperties.getPassword());
    }
    if (null != redisProperties.getTimeout()) {
        builder = builder.withTimeout(redisProperties.getTimeout());
    }
    builder = builder.withDatabase(redisProperties.getDatabase())
            .withSsl(redisProperties.isSsl());
    RedisURI redisUri = builder.build();
    return new RedisRateLimiterFactory(RedisClient.create(redisClientResources, redisUri));
}
 
Example #4
Source File: RedisLettuceCacheTest.java    From jetcache with Apache License 2.0 6 votes vote down vote up
@Test
public void testSentinel2() throws Exception {
    RedisURI redisUri = RedisURI.Builder
            .sentinel("127.0.0.1", 26379, "mymaster")
            .withSentinel("127.0.0.1", 26380)
            .withSentinel("127.0.0.1", 26381)
            .build();
    RedisClient client = RedisClient.create();
    StatefulRedisMasterSlaveConnection con = MasterSlave.connect(
            client, new JetCacheCodec(), redisUri);
    con.setReadFrom(ReadFrom.SLAVE_PREFERRED);
    cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder()
            .redisClient(client)
            .connection(con)
            .keyPrefix(new Random().nextInt() + "")
            .buildCache();
    cache.put("K1", "V1");
    Thread.sleep(100);
    Assert.assertEquals("V1", cache.get("K1"));
}
 
Example #5
Source File: StandaloneRedisDataSourceTest.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@Before
public void buildResource() {
    try {
        // Bind to a random port.
        server = RedisServer.newRedisServer();
        server.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
    client = RedisClient.create(RedisURI.create(server.getHost(), server.getBindPort()));
    RedisConnectionConfig config = RedisConnectionConfig.builder()
        .withHost(server.getHost())
        .withPort(server.getBindPort())
        .build();
    initRedisRuleData();
    ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(config,
        ruleKey, channel, flowConfigParser);
    FlowRuleManager.register2Property(redisDataSource.getProperty());
}
 
Example #6
Source File: RedisHelper.java    From cassandana with Apache License 2.0 6 votes vote down vote up
private RedisHelper(String host, int port, String password) {

		String connectionString = null;
		if(password == null)
			connectionString = "redis://" + host + ":" + port;
		else
			connectionString = "redis://" + password + "@" + host + ":" + port;
		
		redisClient = RedisClient.create(RedisURI.create(connectionString));
		connection = redisClient.connect();
		sync = connection.sync();
		async = connection.async();
		
		asyncKey = connection.async();
		syncKey = connection.sync();

		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				close();
			}
		});
	}
 
Example #7
Source File: StandaloneRedisDataSourceTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
@Before
public void buildResource() {
    try {
        // Bind to a random port.
        server = RedisServer.newRedisServer();
        server.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
    client = RedisClient.create(RedisURI.create(server.getHost(), server.getBindPort()));
    RedisConnectionConfig config = RedisConnectionConfig.builder()
        .withHost(server.getHost())
        .withPort(server.getBindPort())
        .build();
    initRedisRuleData();
    ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(config,
        ruleKey, channel, flowConfigParser);
    FlowRuleManager.register2Property(redisDataSource.getProperty());
}
 
Example #8
Source File: RedisDataSource.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
private RedisClient getRedisSentinelClient(RedisConnectionConfig connectionConfig) {
    char[] password = connectionConfig.getPassword();
    String clientName = connectionConfig.getClientName();
    RedisURI.Builder sentinelRedisUriBuilder = RedisURI.builder();
    for (RedisConnectionConfig config : connectionConfig.getRedisSentinels()) {
        sentinelRedisUriBuilder.withSentinel(config.getHost(), config.getPort());
    }
    if (password != null) {
        sentinelRedisUriBuilder.withPassword(connectionConfig.getPassword());
    }
    if (StringUtil.isNotEmpty(connectionConfig.getClientName())) {
        sentinelRedisUriBuilder.withClientName(clientName);
    }
    sentinelRedisUriBuilder.withSentinelMasterId(connectionConfig.getRedisSentinelMasterId())
        .withTimeout(connectionConfig.getTimeout(), TimeUnit.MILLISECONDS);
    return RedisClient.create(sentinelRedisUriBuilder.build());
}
 
Example #9
Source File: RedisDataSource.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
private RedisClient getRedisStandaloneClient(RedisConnectionConfig connectionConfig) {
    char[] password = connectionConfig.getPassword();
    String clientName = connectionConfig.getClientName();
    RedisURI.Builder redisUriBuilder = RedisURI.builder();
    redisUriBuilder.withHost(connectionConfig.getHost())
        .withPort(connectionConfig.getPort())
        .withDatabase(connectionConfig.getDatabase())
        .withTimeout(Duration.ofMillis(connectionConfig.getTimeout()));
    if (password != null) {
        redisUriBuilder.withPassword(connectionConfig.getPassword());
    }
    if (StringUtil.isNotEmpty(connectionConfig.getClientName())) {
        redisUriBuilder.withClientName(clientName);
    }
    return RedisClient.create(redisUriBuilder.build());
}
 
Example #10
Source File: RedisDataSource.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
private RedisClient getRedisSentinelClient(RedisConnectionConfig connectionConfig) {
    char[] password = connectionConfig.getPassword();
    String clientName = connectionConfig.getClientName();
    RedisURI.Builder sentinelRedisUriBuilder = RedisURI.builder();
    for (RedisConnectionConfig config : connectionConfig.getRedisSentinels()) {
        sentinelRedisUriBuilder.withSentinel(config.getHost(), config.getPort());
    }
    if (password != null) {
        sentinelRedisUriBuilder.withPassword(connectionConfig.getPassword());
    }
    if (StringUtil.isNotEmpty(connectionConfig.getClientName())) {
        sentinelRedisUriBuilder.withClientName(clientName);
    }
    sentinelRedisUriBuilder.withSentinelMasterId(connectionConfig.getRedisSentinelMasterId())
        .withTimeout(connectionConfig.getTimeout(), TimeUnit.MILLISECONDS);
    return RedisClient.create(sentinelRedisUriBuilder.build());
}
 
Example #11
Source File: MultiLevelCacheMixTest.java    From jetcache with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLettuce() {
    l1Cache = CaffeineCacheBuilder.createCaffeineCacheBuilder()
            .limit(10)
            .expireAfterWrite(1000, TimeUnit.MILLISECONDS)
            .keyConvertor(FastjsonKeyConvertor.INSTANCE)
            .buildCache();
    RedisClient client = RedisClient.create("redis://127.0.0.1");
    l2Cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder()
            .redisClient(client)
            .keyConvertor(FastjsonKeyConvertor.INSTANCE)
            .valueEncoder(JavaValueEncoder.INSTANCE)
            .valueDecoder(JavaValueDecoder.INSTANCE)
            .keyPrefix(new Random().nextInt() + "")
            .expireAfterWrite(1000, TimeUnit.MILLISECONDS)
            .buildCache();
    cache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder().addCache(l1Cache, l2Cache).buildCache();
    testImpl();
}
 
Example #12
Source File: TracingLettuce52Test.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: RedisDataSource.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
private RedisClient getRedisStandaloneClient(RedisConnectionConfig connectionConfig) {
    char[] password = connectionConfig.getPassword();
    String clientName = connectionConfig.getClientName();
    RedisURI.Builder redisUriBuilder = RedisURI.builder();
    redisUriBuilder.withHost(connectionConfig.getHost())
        .withPort(connectionConfig.getPort())
        .withDatabase(connectionConfig.getDatabase())
        .withTimeout(Duration.ofMillis(connectionConfig.getTimeout()));
    if (password != null) {
        redisUriBuilder.withPassword(connectionConfig.getPassword());
    }
    if (StringUtil.isNotEmpty(connectionConfig.getClientName())) {
        redisUriBuilder.withClientName(clientName);
    }
    return RedisClient.create(redisUriBuilder.build());
}
 
Example #14
Source File: RedisFeatureSink.java    From feast with Apache License 2.0 6 votes vote down vote up
@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 #15
Source File: TracingLettuce50Test.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@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 #16
Source File: TracingLettuce51Test.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@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 #17
Source File: TracingLettuce51Test.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@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 #18
Source File: TracingLettuce52Test.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: RedisLettuceStarterTest.java    From jetcache with Apache License 2.0 5 votes vote down vote up
public void test() throws Exception {
    Assert.assertNotNull(c1.unwrap(RedisClient.class));
    RedisLettuceCacheConfig cc1 = (RedisLettuceCacheConfig) c1.config();
    Assert.assertEquals(20000, cc1.getExpireAfterWriteInMillis());
    Assert.assertSame(FastjsonKeyConvertor.INSTANCE, cc1.getKeyConvertor());

    a1SlaveCache.put("K1", "V1");
    Thread.sleep(200);
    Assert.assertEquals("V1", a1SlaveCache.get("K1"));
}
 
Example #20
Source File: RedisLettuceStarterTest.java    From jetcache with Apache License 2.0 5 votes vote down vote up
@Test
public void tests() throws Exception {
    if (RedisLettuceCacheTest.checkOS()) {
        System.setProperty("spring.profiles.active", "redislettuce-cluster");
    } else {
        System.setProperty("spring.profiles.active", "redislettuce");
    }
    context = SpringApplication.run(RedisLettuceStarterTest.class);
    doTest();
    A bean = context.getBean(A.class);
    bean.test();

    RedisClient t1 = (RedisClient) context.getBean("defaultClient");
    RedisClient t2 = (RedisClient) context.getBean("a1Client");
    Assert.assertNotNull(t1);
    Assert.assertNotNull(t2);
    Assert.assertNotSame(t1, t2);

    AutoConfigureBeans acb = context.getBean(AutoConfigureBeans.class);

    String key = "remote.A1";
    Assert.assertTrue(new LettuceFactory(acb, key, StatefulRedisConnection.class).getObject() instanceof StatefulRedisConnection);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisCommands.class).getObject() instanceof RedisCommands);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisAsyncCommands.class).getObject() instanceof RedisAsyncCommands);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisReactiveCommands.class).getObject() instanceof RedisReactiveCommands);

    if (RedisLettuceCacheTest.checkOS()) {
        key = "remote.A2";
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterCommands.class).getObject() instanceof RedisClusterCommands);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterAsyncCommands.class).getObject() instanceof RedisClusterAsyncCommands);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterReactiveCommands.class).getObject() instanceof RedisClusterReactiveCommands);

        key = "remote.A2_slave";
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
    }
}
 
Example #21
Source File: RedisServerExtensionTest.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
@Test
void shouldHaveAccessToARedisServer(@RedisPort Integer port) {
  assertNotNull(port);
  assertTrue(port >= 32768, "Port must be more than 32768, was:" + port);
  RedisClient client = RedisClient.create(RedisURI.create(InetAddress.getLoopbackAddress().getHostAddress(), port));
  try (StatefulRedisConnection<String, String> conn = client.connect()) {
    assertTrue(conn.isOpen());
  }
}
 
Example #22
Source File: RedisLettuceCacheTest.java    From jetcache with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithMultiLevelCache() throws Exception {
    Cache l1Cache = CaffeineCacheBuilder.createCaffeineCacheBuilder()
            .limit(10)
            .expireAfterWrite(500, TimeUnit.MILLISECONDS)
            .keyConvertor(FastjsonKeyConvertor.INSTANCE)
            .buildCache();
    RedisClient client = RedisClient.create("redis://127.0.0.1");
    Cache l2Cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder()
            .redisClient(client)
            .keyConvertor(FastjsonKeyConvertor.INSTANCE)
            .valueEncoder(JavaValueEncoder.INSTANCE)
            .valueDecoder(JavaValueDecoder.INSTANCE)
            .keyPrefix(new Random().nextInt() + "")
            .expireAfterWrite(500, TimeUnit.MILLISECONDS)
            .buildCache();
    cache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder()
            .expireAfterWrite(500, TimeUnit.MILLISECONDS)
            .addCache(l1Cache, l2Cache)
            .buildCache();
    baseTest();
    expireAfterWriteTest(500);

    LoadingCacheTest.loadingCacheTest(MultiLevelCacheBuilder.createMultiLevelCacheBuilder()
            .expireAfterWrite(5000, TimeUnit.MILLISECONDS)
            .addCache(l1Cache, l2Cache), 50);

    LettuceConnectionManager.defaultManager().removeAndClose(client);
}
 
Example #23
Source File: RequiresRedisSentinel.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
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 #24
Source File: RedisDataSource.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 * Build Redis client fromm {@code RedisConnectionConfig}.
 *
 * @return a new {@link RedisClient}
 */
private RedisClient getRedisClient(RedisConnectionConfig connectionConfig) {
    if (connectionConfig.getRedisSentinels().size() == 0) {
        RecordLog.info("[RedisDataSource] Creating stand-alone mode Redis client");
        return getRedisStandaloneClient(connectionConfig);
    } else {
        RecordLog.info("[RedisDataSource] Creating Redis Sentinel mode Redis client");
        return getRedisSentinelClient(connectionConfig);
    }
}
 
Example #25
Source File: ProtobufRedisLoadingCache.java    From curiostack with MIT License 5 votes vote down vote up
@Inject
public Factory(
    Lazy<RedisClusterClient> redisClusterClient,
    Lazy<RedisClient> redisClient,
    RedisConfig config,
    MeterRegistry meterRegistry) {
  this.redisClusterClient = redisClusterClient;
  this.redisClient = redisClient;
  this.config = config;
  this.meterRegistry = meterRegistry;
}
 
Example #26
Source File: RedisPriorityQueue.java    From NetDiscovery with Apache License 2.0 5 votes vote down vote up
public RedisPriorityQueue(RedisClient redisClient,RedisKeyConfig redisKeyConfig) {
    super(redisClient,redisKeyConfig);

    if (redisKeyConfig!=null) { // 自定义 redis key 的前缀,以免跟自身业务的前缀不统一
        this.ZSET_PREFIX = redisKeyConfig.ZSET_PREFIX;
        this.QUEUE_PREFIX = redisKeyConfig.QUEUE_PREFIX;
        this.NORMAL_SUFFIX = redisKeyConfig.NORMAL_SUFFIX;
        this.PRIORITY_SUFFIX = redisKeyConfig.PRIORITY_SUFFIX;
    }
}
 
Example #27
Source File: RedisQueue.java    From NetDiscovery with Apache License 2.0 5 votes vote down vote up
public RedisQueue(RedisClient redisClient,RedisKeyConfig redisKeyConfig) {

        if (redisKeyConfig!=null) { // 自定义 redis key 的前缀,以免跟自身业务的前缀不统一

            this.QUEUE_PREFIX = redisKeyConfig.QUEUE_PREFIX;
            this.SET_PREFIX = redisKeyConfig.SET_PREFIX;
            this.ITEM_PREFIX = redisKeyConfig.ITEM_PREFIX;
        }

        this.redisClient = redisClient;
        setFilter(this);
    }
 
Example #28
Source File: RateLimitApplication.java    From ratelimitj with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<Configuration> bootstrap) {
    redisClient = RedisClient.create("redis://localhost:7006");
    RequestRateLimiterFactory factory = new RedisRateLimiterFactory(redisClient);

    //RequestRateLimiterFactory factory = new InMemoryRateLimiterFactory();

    bootstrap.addBundle(new RateLimitBundle(factory));
}
 
Example #29
Source File: RedisPipeline.java    From NetDiscovery with Apache License 2.0 5 votes vote down vote up
public RedisPipeline(ClientResources resources, RedisURI redisURI, String key, long pipelineDelay) {

        super(pipelineDelay);
        if (null != resources) {
            this.redisClient = RedisClient.create(resources, redisURI);
        } else {
            this.redisClient = RedisClient.create(redisURI);
        }
        this.key = key;
    }
 
Example #30
Source File: Lettuce5Driver.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@Override
public void startVendorInstance() throws Exception {
    String workerType = get("WORKER_TYPE");
    if ("javaclient".equals(workerType)) {
         client = RedisClient.create(get("URI"));
    }
}