Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 84b025f

Browse files
authored
Merge pull request #78 from launchdarkly/dr/updateJedis
Update Jedis, unwatch
2 parents b542a6d + 996ca3b commit 84b025f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repositories {
1919

2020
allprojects {
2121
group = 'com.launchdarkly'
22-
version = "2.0.5"
22+
version = "2.0.6-SNAPSHOT"
2323
sourceCompatibility = 1.7
2424
targetCompatibility = 1.7
2525
}
@@ -33,7 +33,7 @@ dependencies {
3333
compile "joda-time:joda-time:2.9.3"
3434
compile "org.slf4j:slf4j-api:1.7.21"
3535
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "1.0.0", changing: true
36-
compile "redis.clients:jedis:2.8.1"
36+
compile "redis.clients:jedis:2.9.0"
3737
testCompile "org.easymock:easymock:3.4"
3838
testCompile 'junit:junit:4.12'
3939
testRuntime "ch.qos.logback:logback-classic:1.1.7"

src/main/java/com/launchdarkly/client/RedisFeatureStore.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,17 @@ public void init(Map<String, FeatureFlag> features) {
281281
*/
282282
@Override
283283
public void delete(String key, int version) {
284-
try (Jedis jedis = pool.getResource()) {
284+
Jedis jedis = null;
285+
try {
285286
Gson gson = new Gson();
287+
jedis = pool.getResource();
286288
jedis.watch(featuresKey());
287289

288290
FeatureFlag feature = getRedis(key);
289291

290292
if (feature != null && feature.getVersion() >= version) {
293+
logger.warn("Attempted to delete flag: " + key + " version: " + feature.getVersion() +
294+
" with a version that is the same or older: " + version);
291295
return;
292296
}
293297

@@ -300,6 +304,12 @@ public void delete(String key, int version) {
300304
cache.invalidate(key);
301305
}
302306
}
307+
finally {
308+
if (jedis != null) {
309+
jedis.unwatch();
310+
jedis.close();
311+
}
312+
}
303313
}
304314

305315
/**
@@ -311,13 +321,17 @@ public void delete(String key, int version) {
311321
*/
312322
@Override
313323
public void upsert(String key, FeatureFlag feature) {
314-
try (Jedis jedis = pool.getResource()) {
324+
Jedis jedis = null;
325+
try {
326+
jedis = pool.getResource();
315327
Gson gson = new Gson();
316328
jedis.watch(featuresKey());
317329

318330
FeatureFlag f = getRedis(key);
319331

320332
if (f != null && f.getVersion() >= feature.getVersion()) {
333+
logger.warn("Attempted to update flag: " + key + " version: " + f.getVersion() +
334+
" with a version that is the same or older: " + feature.getVersion());
321335
return;
322336
}
323337

@@ -326,6 +340,11 @@ public void upsert(String key, FeatureFlag feature) {
326340
if (cache != null) {
327341
cache.invalidate(key);
328342
}
343+
} finally {
344+
if (jedis != null) {
345+
jedis.unwatch();
346+
jedis.close();
347+
}
329348
}
330349
}
331350

0 commit comments

Comments
 (0)