Skip to content

simerplaha/SwayDB.java.examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Implements examples demoing SwayDB's Java API.

Requirements

Java 1.8 and later.

Quick start example.

See QuickStart.java.

Map<Integer, Integer, Void> map =
  MemoryMap
    .functionsOff(intSerializer(), intSerializer())
    .get();

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(KeyVal::of));

//Create a stream that updates all values within range 10 to 90.
Stream<KeyVal<Integer, Integer>> updatedKeyValues =
  map
    .stream()
    .from(10)
    .takeWhile(keyVal -> keyVal.key() <= 90)
    .map(keyVal -> KeyVal.of(keyVal.key(), keyVal.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(System.out::println);