nbcp.myoql.db.redis.entity.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktmyoql Show documentation
Show all versions of ktmyoql Show documentation
kotlin orm -- mysql,mongo , just like ktorm
The newest version!
package nbcp.myoql.db.redis
import nbcp.base.extend.HasValue
import nbcp.myoql.db.db
import nbcp.myoql.db.redis.proxy.RedisHashProxy
import nbcp.myoql.db.redis.proxy.RedisStringProxy
/**
* 缓存
* 如果封装方法,会有数据库操作
*/
class RedisBaseGroup {
// val sqlCacheBroker = RedisSetProxy("sc-broker")
// class SqlCacheGroup {
// val cacheSqlData get() = RedisStringProxy("")
// fun brokeKeys(table: String) = RedisSetProxy("broke-keys:${table}")
// val borkeKeysChangedVersion get() = RedisNumberProxy("borke-keys-changed-version")
// val brokingTable get() = RedisStringProxy("broking-table")
// }
//城市数据,缓存两个小时
fun cityCodeName(code: String) = RedisStringProxy("city-name:${code}", 3600, true)
fun nacosInstance(key: String) = RedisHashProxy("nacos-ins:${key}")
fun taskLock(key: String) = RedisStringProxy("lock:${key}", defaultCacheSeconds = 60)
/**
* 获取城市
*/
fun getCityNameByCode(code: Int): String {
var name = cityCodeName(code.toString()).get()
if (name.HasValue) {
return name;
}
//如果是 mongo, 如果是 mysql
name = db.morBase.sysCity.queryByCode(code)
.select { it.name }
.toEntity(String::class.java) ?: "";
if (name.HasValue) {
cityCodeName(code.toString()).set(name);
}
return name;
}
// val sqlCache = SqlCacheGroup()
}