Skip to content

simerplaha/SwayDB.kotlin.examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Implements examples demoing SwayDB's Java API.

Requirements

Kotlin 1.3 and later.

Quick start example.

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) }

About

Kotlin examples for SwayDB

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 3

  •  
  •  
  •  

Languages