io.lettuce.core.codec.ByteArrayCodec Java Examples

The following examples show how to use io.lettuce.core.codec.ByteArrayCodec. 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: WrapperTests.java    From sherlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testBaseAccessorUsesProducer() {
    inject(Client.class, "client", null);
    ConnectionProducer stringProducer = mock(ConnectionProducer.class);
    ConnectionProducer byteProducer = mock(ConnectionProducer.class);
    RedisConnection<String> strConn = (RedisConnection<String>) mock(RedisConnection.class);
    RedisConnection<byte[]> binConn = (RedisConnection<byte[]>) mock(RedisConnection.class);
    when(stringProducer.produce(any())).thenAnswer(iom -> {
            assertTrue(iom.getArguments()[0] instanceof StringCodec);
            return strConn;
        }
    );
    when(byteProducer.produce(any())).thenAnswer(iom -> {
            assertTrue(iom.getArguments()[0] instanceof ByteArrayCodec);
            return binConn;
        }
    );
    BaseAccessor acc = new BaseAccessorTestImpl();
    inject(acc, BaseAccessor.class, "producer", stringProducer);
    assertEquals(strConn, acc.connect());
    verify(stringProducer).produce(any(StringCodec.class));
    inject(acc, BaseAccessor.class, "producer", byteProducer);
    assertEquals(binConn, acc.binary());
    verify(byteProducer).produce(any(ByteArrayCodec.class));
    inject(Client.class, "client", null);
}
 
Example #3
Source File: RedisBackedJobService.java    From feast with Apache License 2.0 5 votes vote down vote up
public RedisBackedJobService(FeastProperties.JobStoreProperties jobStoreProperties) {
  RedisURI uri =
      RedisURI.create(jobStoreProperties.getRedisHost(), jobStoreProperties.getRedisPort());

  this.syncCommand =
      RedisClient.create(DefaultClientResources.create(), uri)
          .connect(new ByteArrayCodec())
          .sync();
}
 
Example #4
Source File: RedisStandaloneIngestionClient.java    From feast with Apache License 2.0 5 votes vote down vote up
@Override
public void connect() {
  if (!isConnected()) {
    this.connection = this.redisclient.connect(new ByteArrayCodec());
    this.commands = connection.async();
  }
}
 
Example #5
Source File: RedisClusterIngestionClient.java    From feast with Apache License 2.0 5 votes vote down vote up
@Override
public void connect() {
  if (!isConnected()) {
    this.connection = clusterClient.connect(new ByteArrayCodec());
    this.commands = connection.async();
  }
}
 
Example #6
Source File: RedisClusterOnlineRetriever.java    From feast with Apache License 2.0 5 votes vote down vote up
public static OnlineRetriever create(Map<String, String> config) {
  List<RedisURI> redisURIList =
      Arrays.stream(config.get("connection_string").split(","))
          .map(
              hostPort -> {
                String[] hostPortSplit = hostPort.trim().split(":");
                return RedisURI.create(hostPortSplit[0], Integer.parseInt(hostPortSplit[1]));
              })
          .collect(Collectors.toList());

  StatefulRedisClusterConnection<byte[], byte[]> connection =
      RedisClusterClient.create(redisURIList).connect(new ByteArrayCodec());

  return new RedisClusterOnlineRetriever(connection);
}
 
Example #7
Source File: RedisOnlineRetriever.java    From feast with Apache License 2.0 5 votes vote down vote up
public static OnlineRetriever create(Map<String, String> config) {

    StatefulRedisConnection<byte[], byte[]> connection =
        RedisClient.create(
                RedisURI.create(config.get("host"), Integer.parseInt(config.get("port"))))
            .connect(new ByteArrayCodec());

    return new RedisOnlineRetriever(connection);
  }
 
Example #8
Source File: BaseAccessor.java    From sherlock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return a binary connection
 */
public RedisConnection<byte[]> binary() {
    return producer.produce(new ByteArrayCodec());
}
 
Example #9
Source File: RedisFeatureSinkTest.java    From feast with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws IOException {
  redis = new RedisServer(REDIS_PORT);
  redis.start();
  redisClient =
      RedisClient.create(new RedisURI(REDIS_HOST, REDIS_PORT, java.time.Duration.ofMillis(2000)));
  StatefulRedisConnection<byte[], byte[]> connection = redisClient.connect(new ByteArrayCodec());
  sync = connection.sync();

  FeatureSetSpec spec1 =
      FeatureSetSpec.newBuilder()
          .setName("fs")
          .setProject("myproject")
          .addEntities(EntitySpec.newBuilder().setName("entity").setValueType(Enum.INT64).build())
          .addFeatures(
              FeatureSpec.newBuilder().setName("feature").setValueType(Enum.STRING).build())
          .build();

  FeatureSetSpec spec2 =
      FeatureSetSpec.newBuilder()
          .setName("feature_set")
          .setProject("myproject")
          .addEntities(
              EntitySpec.newBuilder()
                  .setName("entity_id_primary")
                  .setValueType(Enum.INT32)
                  .build())
          .addEntities(
              EntitySpec.newBuilder()
                  .setName("entity_id_secondary")
                  .setValueType(Enum.STRING)
                  .build())
          .addFeatures(
              FeatureSpec.newBuilder().setName("feature_1").setValueType(Enum.STRING).build())
          .addFeatures(
              FeatureSpec.newBuilder().setName("feature_2").setValueType(Enum.INT64).build())
          .build();

  specMap =
      ImmutableMap.of(
          FeatureSetReference.of("myproject", "fs", 1), spec1,
          FeatureSetReference.of("myproject", "feature_set", 1), spec2);
  StoreProto.Store.RedisConfig redisConfig =
      StoreProto.Store.RedisConfig.newBuilder().setHost(REDIS_HOST).setPort(REDIS_PORT).build();

  redisFeatureSink = RedisFeatureSink.builder().setRedisConfig(redisConfig).build();
  redisFeatureSink.prepareWrite(p.apply("Specs-1", Create.of(specMap)));
}
 
Example #10
Source File: RedisClusterFeatureSinkTest.java    From feast with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws IOException {
  redisCluster = new RedisCluster(REDIS_CLUSTER_PORT1, REDIS_CLUSTER_PORT2, REDIS_CLUSTER_PORT3);
  redisCluster.start();
  redisClusterClient =
      RedisClusterClient.create(
          Arrays.asList(
              RedisURI.create(REDIS_CLUSTER_HOST, REDIS_CLUSTER_PORT1),
              RedisURI.create(REDIS_CLUSTER_HOST, REDIS_CLUSTER_PORT2),
              RedisURI.create(REDIS_CLUSTER_HOST, REDIS_CLUSTER_PORT3)));
  StatefulRedisClusterConnection<byte[], byte[]> connection =
      redisClusterClient.connect(new ByteArrayCodec());
  redisClusterCommands = connection.sync();
  redisClusterCommands.setTimeout(java.time.Duration.ofMillis(600000));

  FeatureSetSpec spec1 =
      FeatureSetSpec.newBuilder()
          .setName("fs")
          .setProject("myproject")
          .addEntities(EntitySpec.newBuilder().setName("entity").setValueType(Enum.INT64).build())
          .addFeatures(
              FeatureSpec.newBuilder().setName("feature").setValueType(Enum.STRING).build())
          .build();

  FeatureSetSpec spec2 =
      FeatureSetSpec.newBuilder()
          .setName("feature_set")
          .setProject("myproject")
          .addEntities(
              EntitySpec.newBuilder()
                  .setName("entity_id_primary")
                  .setValueType(Enum.INT32)
                  .build())
          .addEntities(
              EntitySpec.newBuilder()
                  .setName("entity_id_secondary")
                  .setValueType(Enum.STRING)
                  .build())
          .addFeatures(
              FeatureSpec.newBuilder().setName("feature_1").setValueType(Enum.STRING).build())
          .addFeatures(
              FeatureSpec.newBuilder().setName("feature_2").setValueType(Enum.INT64).build())
          .build();

  Map<FeatureSetReference, FeatureSetSpec> specMap =
      ImmutableMap.of(
          FeatureSetReference.of("myproject", "fs", 1), spec1,
          FeatureSetReference.of("myproject", "feature_set", 1), spec2);
  RedisClusterConfig redisClusterConfig =
      RedisClusterConfig.newBuilder()
          .setConnectionString(CONNECTION_STRING)
          .setInitialBackoffMs(2000)
          .setMaxRetries(4)
          .build();

  redisClusterFeatureSink =
      RedisFeatureSink.builder().setRedisClusterConfig(redisClusterConfig).build();
  redisClusterFeatureSink.prepareWrite(p.apply("Specs-1", Create.of(specMap)));
}
 
Example #11
Source File: LettuceRedisCacheManager.java    From AutoLoadCache with Apache License 2.0 4 votes vote down vote up
@Override
protected IRedis getRedis() {
    StatefulRedisConnection<byte[], byte[]> connection = redisClient.connect(ByteArrayCodec.INSTANCE);
    return new LettuceRedisClient(connection, this);
}
 
Example #12
Source File: LettuceRedisClusterCacheManager.java    From AutoLoadCache with Apache License 2.0 4 votes vote down vote up
@Override
protected IRedis getRedis() {
    StatefulRedisClusterConnection<byte[], byte[]> connection = redisClusterClient.connect(ByteArrayCodec.INSTANCE);
    return new LettuceRedisClusterClient(connection, this);
}