blob: 67547778ed01dbb1c1a25baf38dc92bef9ba7f59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()
}
}
|