Skip to content

Commit 8afdfba

Browse files
committed
QuickStartMapSimple
1 parent 1d8ac6c commit 8afdfba

File tree

2 files changed

+42
-60
lines changed

2 files changed

+42
-60
lines changed

src/main/kotlin/quickstart/QuickStart.kt

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package quickstart
2+
3+
import swaydb.KeyVal
4+
import swaydb.java.Stream
5+
import swaydb.java.memory.MapConfig
6+
import swaydb.java.serializers.Default
7+
import java.time.Duration
8+
9+
internal object QuickStartMapSimple {
10+
11+
@JvmStatic
12+
fun main(args: Array<String>) {
13+
val map =
14+
MapConfig
15+
.functionsOff(Default.intSerializer(), Default.intSerializer())
16+
.get()
17+
18+
map.put(1, 1) //basic put
19+
map[1].get() //basic get
20+
map.expire(1, Duration.ofSeconds(1)) //basic expire
21+
map.remove(1) //basic remove
22+
23+
//atomic write a Stream of key-value
24+
map.put(Stream.range(1, 100).map { KeyVal.create(it) })
25+
26+
//Create a stream that updates all values within range 10 to 90.
27+
val updatedKeyValues =
28+
map
29+
.from(10)
30+
.stream()
31+
.takeWhile { it.key() <= 90 }
32+
.map { KeyVal.create(it.key(), it.value() + 5000000) }
33+
34+
//submit the stream to update the key-values as a single transaction.
35+
map.put(updatedKeyValues)
36+
37+
//print all key-values to view the update.
38+
map
39+
.stream()
40+
.forEach(::println)
41+
}
42+
}

0 commit comments

Comments
 (0)