diff options
| author | mjkwiatkowski <mati.rewa@gmail.com> | 2026-02-23 12:05:58 +0100 |
|---|---|---|
| committer | mjkwiatkowski <mati.rewa@gmail.com> | 2026-02-23 12:05:58 +0100 |
| commit | 4f816318b6672d40f23b22ca44cc06b77cadf961 (patch) | |
| tree | 40aa2cae25fee7a92eb36d1d471534a8b53fecd0 /opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt | |
| parent | daad473975cc3e6eba0536d5a8fe750cf8b2fa7d (diff) | |
Diffstat (limited to 'opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt')
| -rw-r--r-- | opendc-common/src/main/kotlin/org/opendc/common/utils/Redis.kt | 44 |
1 files changed, 44 insertions, 0 deletions
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 <a href=https://redis.io/docs/latest/>https://redis.io/docs/latest/</a> + * + * @see <a href=https://redis.io/docs/latest/develop/data-types/streams/>https://redis.io/docs/latest/develop/data-types/streams/</a> + */ + +@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<String?, StreamEntryID?>() { + 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 |
