Home

Awesome

SwayDB.kotlin.examples Slack Chat Gitter Chat Build status Maven central

Implements examples demoing SwayDB's API.

Quick start example.

See full QuickStart.kt.

val map =
  MapConfig
    .functionsOff(intSerializer(), intSerializer())
    .get()

map.put(1, 1) //basic put
map[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 { KeyVal.create(it) })

//Create a stream that updates all values within range 10 to 90.
val updatedKeyValues =
  map
    .from(10)
    .stream()
    .takeWhile { it.key() <= 90 }
    .map { KeyVal.create(it.key(), it.value() + 5000000) }

//submit the stream to update the key-values as a single transaction.
map.put(updatedKeyValues)

//print all key-values to view the update.
map
  .stream()
  .forEach(::println)