All Downloads are FREE. Search and download functionalities are using the official Maven repository.

money.rave.common.backend.redis.lettuce.RedisQueue.kt Maven / Gradle / Ivy

package money.rave.common.backend.redis.lettuce

import com.google.gson.Gson
import money.rave.common.backend.fromJson
import money.rave.common.backend.gson.commonGson
import money.rave.common.backend.toJson

open class RedisQueue(
    private val redis: StringRedis,
    private val key: String,
    private val refClass: Class,
    private val gson: Gson = commonGson,
) {

    suspend fun push(value: T) {
        redis.execute { lpush(key, value!!.toJson(gson)) }
    }

    suspend fun pop(): T = redis.execute { rpop(key) }.fromJson(gson, refClass)

    suspend fun isEmpty() = redis.execute { llen(key) } == 0L
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy