Skip to content

Commit

Permalink
fix(queue): stop leaking all the redis connections (#1321)
Browse files Browse the repository at this point in the history
It turns out that `use` is more than just a scope function.
  • Loading branch information
robfletcher authored May 5, 2017
1 parent c486f5b commit 737e0d9
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ class RedisExecutionLogRepository(
val serializedEntry = objectMapper.writeValueAsString(entry)
val key = "executionLog.${entry.executionId}"

pool.resource.apply {
zadd(key, entry.timestamp.toEpochMilli().toDouble(), serializedEntry)
expire(key, ttlSeconds)
pool.resource.use { redis ->
redis.zadd(key, entry.timestamp.toEpochMilli().toDouble(), serializedEntry)
redis.expire(key, ttlSeconds)
}
}

override fun getAllByExecutionId(executionId: String) =
pool.resource.run {
zrangeByScore("executionLog.$executionId", "-inf", "+inf")
pool.resource.use { redis ->
redis
.zrangeByScore("executionLog.$executionId", "-inf", "+inf")
.map { objectMapper.readValue(it, ExecutionLogEntry::class.java) }
}
}

0 comments on commit 737e0d9

Please sign in to comment.