Implements examples demoing SwayDB's Java API.
Kotlin 1.3 and later.
See full QuickStart.kt.
val map =
MapConfig
.withFunctions(intSerializer(), intSerializer())
.registerFunction(function)
.init()
map.put(1, 1) //basic put
map.get(1).get() //basic get
map.expire(1, Duration.ofSeconds(1)) //basic expire
map.remove(1) //basic remove
//atomic write a Stream of key-value
map.put(Stream.range(1, 100).map { item -> KeyVal.create(item) })
//create a read stream from 10th key-value to 90th, increment values by 1000000 and insert.
val updatedKeyValuesStream =
map
.from(10)
.stream()
.takeWhile { keyVal -> keyVal.key() <= 90 }
.map { keyVal -> KeyVal.create(keyVal.key(), keyVal.value() + 5000000) }
map.put(updatedKeyValuesStream)
map.applyFunction(1, 100, function) //apply the function to all key-values ranging 1 to 100.
//print all key-values to view the update.
map
.stream()
.forEach { println(it) }