From 4f816318b6672d40f23b22ca44cc06b77cadf961 Mon Sep 17 00:00:00 2001 From: mjkwiatkowski Date: Mon, 23 Feb 2026 12:05:58 +0100 Subject: feat: added a working connection to Redis, and a scaffolding for the RESTful API --- .../main/kotlin/org/opendc/common/utils/Redis.kt | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt (limited to 'opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt') diff --git a/opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt b/opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt new file mode 100644 index 00000000..67547778 --- /dev/null +++ b/opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt @@ -0,0 +1,44 @@ +package org.opendc.common.utils + +import com.fasterxml.jackson.dataformat.toml.TomlMapper +import redis.clients.jedis.RedisClient +import redis.clients.jedis.StreamEntryID +import redis.clients.jedis.params.XReadParams +import java.util.Properties + +/** + * This class represents the Redis server instance. + * @author Mateusz Kwiatkowski + * @see https://redis.io/docs/latest/ + * + * @see https://redis.io/docs/latest/develop/data-types/streams/ + */ + +@Suppress("DEPRECATION") +public class Redis { + private var properties : Properties + + init { + properties = TomlMapper().readerFor(Properties().javaClass) + .readValue(Kafka::class.java.getResource("/producer.toml")) + } + + public fun run() { + val jedis : RedisClient = RedisClient.create("redis://localhost:6379") + + val res5 = jedis.xread( + XReadParams.xReadParams().block(300).count(100), + object : HashMap() { + init { + put("${properties.getProperty("table")}", StreamEntryID()) + } + }) + + // in Redis you can subscribe to updates to a stream. + // you should base your application off this. + // you can listen for new items with XREAD + println(res5) + jedis.close() + } + +} \ No newline at end of file -- cgit v1.2.3