Skip to content

Instantly share code, notes, and snippets.

@barinek
Created February 26, 2018 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barinek/62223089e9b5dbaa2c23c2dc104ee5b6 to your computer and use it in GitHub Desktop.
Save barinek/62223089e9b5dbaa2c23c2dc104ee5b6 to your computer and use it in GitHub Desktop.
class InstanceDataGateway(val pool: JedisPool, val timeToLiveInMillis: Long) {
fun heartbeat(appId: String, url: String): InstanceRecord {
val resource = pool.resource
resource.psetex("$appId:$url", timeToLiveInMillis, url)
resource.close()
return InstanceRecord(appId, url)
}
fun findBy(appId: String): List<InstanceRecord> {
val list = mutableListOf<InstanceRecord>()
val resource = pool.resource
resource.keys("$appId:*")
.map { pool.resource.get(it) }
.mapTo(list) { InstanceRecord(appId, it) }
resource.close()
return list
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment