Implementations of the Discord4J Store (Discord entity cache) including an extensive test suite.
An implementation backed by everyone's favorite open sauce database PostgreSQL.
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation "dev.capybaralabs.d4j-store:postgres:x.y.z"
}
fun connectionFactory(): ConnectionFactory {
return ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(ConnectionFactoryOptions.DRIVER, "postgresql")
.option(ConnectionFactoryOptions.HOST, "127.0.0.1")
.option(ConnectionFactoryOptions.PORT, 5432)
.option(ConnectionFactoryOptions.USER, "cache")
.option(ConnectionFactoryOptions.PASSWORD, "cache")
.option(ConnectionFactoryOptions.DATABASE, "cache")
.build()
)
}
fun connectionPool(): ConnectionPool {
val configuration = ConnectionPoolConfiguration.builder(connectionFactory())
.maxIdleTime(Duration.ofMillis(1000))
.maxSize(20)
.maxAcquireTime(Duration.ofSeconds(5))
.build()
return ConnectionPool(configuration)
}
fun postgresStoreLayout(): StoreLayout {
return PostgresStoreLayout(connectionPool())
}
fun store(): Store {
return Store.fromLayout(postgresStoreLayout())
}
fun gatewayBootstrap(discordClient: DiscordClient): GatewayBootstrap<GatewayOptions> {
return discordClient
.gateway()
.setStore(store())
.withEventDispatcher { ed ->
ed.on(Event::class.java)
.doOnNext { logger().trace("Event received ${it.javaClass.simpleName}") }
.retry()
}
}
An implementation backed by everyone's second favorite open sauce database Redis.
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation "dev.capybaralabs.d4j-store:redis:x.y.z"
}
fun connectionFactory(): ReactiveRedisConnectionFactory {
val redisUri = RedisURI.create("redis:https://localhost:6379/0")
val redisConfiguration = LettuceConnectionFactory.createRedisConfiguration(redisUri)
val connectionFactory = LettuceConnectionFactory(redisConfiguration)
connectionFactory.afterPropertiesSet()
return connectionFactory
}
fun redisStoreLayout(): StoreLayout {
return RedisStoreLayout(connectionFactory)
}
fun store(): Store {
return Store.fromLayout(redisStoreLayout())
}
fun gatewayBootstrap(discordClient: DiscordClient): GatewayBootstrap<GatewayOptions> {
return discordClient
.gateway()
.setStore(store())
.withEventDispatcher { ed ->
ed.on(Event::class.java)
.doOnNext { logger().trace("Event received ${it.javaClass.simpleName}") }
.retry()
}
}