Skip to content

Commit

Permalink
use new logging API introduced in Java SDK 5.10.0 (#10)
Browse files Browse the repository at this point in the history
* use new logging API introduced in Java SDK 5.10.0

* rm Logback which was only needed for SLF4J

* nicer format for Docker example, also don't need -d
  • Loading branch information
eli-darkly authored Jul 29, 2022
1 parent a9b8f0b commit a515d86
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 29 deletions.
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ To build the library and run all unit tests:
./gradlew test
```

The tests expect you to have Redis running locally on the default port, 6379. One way to do this is with Docker: `docker run -d -p 6379:6379 redis`
The tests expect you to have Redis running locally on the default port, 6379. One way to do this is with Docker:

```shell
docker run -p 6379:6379 redis
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

This library provides a Redis-backed persistence mechanism (feature store) for the [LaunchDarkly Java SDK](https://github.com/launchdarkly/java-server-sdk), replacing the default in-memory feature store. The Redis API implementation it uses is [Jedis](https://github.com/xetorthio/jedis).

This version of the library requires at least version 5.0.0 of the LaunchDarkly Java SDK. The minimum Java version is 8.
This version of the library requires at least version 5.10.0 of the LaunchDarkly Java SDK; for earlier 5.x versions of the Java SDK, use the 1.x version of this library. The minimum Java version is 8.

For more information, see also: [Using Redis as a persistent feature store](https://docs.launchdarkly.com/sdk/features/storing-data/redis#java).

Expand Down
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,18 @@ ext {
}

ext.versions = [
"sdk": "5.7.0", // the *lowest* version we're compatible with
"jedis": "2.9.0",
"slf4j": "1.7.21"
"sdk": "5.10.0", // the *lowest* version we're compatible with
"jedis": "2.9.0"
]

ext.libraries = [:]

dependencies {
api "com.launchdarkly:launchdarkly-java-server-sdk:${versions.sdk}"
api "redis.clients:jedis:${versions.jedis}"
api "org.slf4j:slf4j-api:${versions.slf4j}"
testImplementation "org.hamcrest:hamcrest-all:1.3"
testImplementation "junit:junit:4.12"
testImplementation "com.launchdarkly:launchdarkly-java-server-sdk:${versions.sdk}:test" // our unit tests use helper classes from the SDK
testImplementation "ch.qos.logback:logback-classic:1.1.7"
testImplementation "com.google.guava:guava:28.2-jre" // required by SDK tests, not used in this library itself
testImplementation "com.google.code.gson:gson:2.7" // same as above
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.launchdarkly.sdk.server.integrations;

import com.launchdarkly.logging.LDLogger;
import com.launchdarkly.sdk.server.interfaces.BigSegmentStore;
import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreTypes;

Expand All @@ -14,8 +15,8 @@ final class RedisBigSegmentStoreImpl extends RedisStoreImplBase implements BigSe
private final String includedKeyPrefix;
private final String excludedKeyPrefix;

RedisBigSegmentStoreImpl(RedisDataStoreBuilder builder) {
super(builder, LOGGER_NAME);
RedisBigSegmentStoreImpl(RedisDataStoreBuilder builder, LDLogger baseLogger) {
super(builder, baseLogger.subLogger("BigSegments").subLogger("Redis"));
syncTimeKey = prefix + ":big_segments_synchronized_on";
includedKeyPrefix = prefix + ":big_segment_include:";
excludedKeyPrefix = prefix + ":big_segment_exclude:";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ public RedisDataStoreBuilder socketTimeout(Duration socketTimeout) {

@Override
public PersistentDataStore createPersistentDataStore(ClientContext context) {
return new RedisDataStoreImpl(this);
return new RedisDataStoreImpl(this, context.getBasic().getBaseLogger());
}

@Override
public BigSegmentStore createBigSegmentStore(ClientContext context) {
return new RedisBigSegmentStoreImpl(this);
return new RedisBigSegmentStoreImpl(this, context.getBasic().getBaseLogger());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.launchdarkly.sdk.server.integrations;

import com.launchdarkly.logging.LDLogger;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.DataKind;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.FullDataSet;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.ItemDescriptor;
Expand All @@ -16,12 +17,10 @@
import redis.clients.jedis.Transaction;

final class RedisDataStoreImpl extends RedisStoreImplBase implements PersistentDataStore {
private static final String LOGGER_NAME = "com.launchdarkly.sdk.server.LDClient.DataStore.Redis";

private UpdateListener updateListener;

RedisDataStoreImpl(RedisDataStoreBuilder builder) {
super(builder, LOGGER_NAME);
RedisDataStoreImpl(RedisDataStoreBuilder builder, LDLogger baseLogger) {
super(builder, baseLogger.subLogger("DataStore").subLogger("Redis"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.launchdarkly.sdk.server.integrations;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.launchdarkly.logging.LDLogger;

import java.io.Closeable;
import java.io.IOException;
Expand All @@ -10,12 +9,13 @@
import redis.clients.jedis.JedisPoolConfig;

abstract class RedisStoreImplBase implements Closeable {
protected final Logger logger;
protected final LDLogger logger;
protected final JedisPool pool;
protected final String prefix;

protected RedisStoreImplBase(RedisDataStoreBuilder builder, String loggerName) {
logger = LoggerFactory.getLogger(loggerName);
protected RedisStoreImplBase(RedisDataStoreBuilder builder, LDLogger logger) {
this.logger = logger;

// There is no builder for JedisPool, just a large number of constructor overloads. Unfortunately,
// the overloads that accept a URI do not accept the other parameters we need to set, so we need
// to decompose the URI.
Expand All @@ -29,7 +29,7 @@ protected RedisStoreImplBase(RedisDataStoreBuilder builder, String loggerName) {
if (password != null) {
extra = extra + (extra.isEmpty() ? " with" : " and") + " password";
}
logger.info(String.format("Using Redis data store at %s:%d/%d%s", host, port, database, extra));
logger.info("Using Redis data store at {}:{}/{}{}", host, port, database, extra);

JedisPoolConfig poolConfig = (builder.poolConfig != null) ? builder.poolConfig : new JedisPoolConfig();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreFactory;
import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreTypes;
import com.launchdarkly.sdk.server.interfaces.ClientContext;

import redis.clients.jedis.Jedis;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testUriConfigured() {
@Test
public void testDatabaseConfigured() {
RedisDataStoreBuilder conf = Redis.dataStore().database(3);
assertEquals(new Integer(3), conf.database);
assertEquals(Integer.valueOf(3), conf.database);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.launchdarkly.sdk.server.integrations;

import com.launchdarkly.sdk.server.integrations.RedisDataStoreImpl.UpdateListener;
import com.launchdarkly.sdk.server.interfaces.PersistentDataStoreFactory;

import java.net.URI;

Expand All @@ -12,13 +13,8 @@ public class RedisDataStoreImplTest extends PersistentDataStoreTestBase<RedisDat
private static final URI REDIS_URI = URI.create("redis://localhost:6379");

@Override
protected RedisDataStoreImpl makeStore() {
return (RedisDataStoreImpl)Redis.dataStore().uri(REDIS_URI).createPersistentDataStore(null);
}

@Override
protected RedisDataStoreImpl makeStoreWithPrefix(String prefix) {
return (RedisDataStoreImpl)Redis.dataStore().uri(REDIS_URI).prefix(prefix).createPersistentDataStore(null);
protected PersistentDataStoreFactory buildStore(String prefix) {
return Redis.dataStore().uri(REDIS_URI).prefix(prefix);
}

@Override
Expand Down

0 comments on commit a515d86

Please sign in to comment.