File tree Expand file tree Collapse file tree 2 files changed +42
-60
lines changed
src/main/kotlin/quickstart Expand file tree Collapse file tree 2 files changed +42
-60
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments