Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

给alkaid-redis扩展添加了哈希表字段赋值等操作 #443

Open
wants to merge 3 commits into
base: dev/6.2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,20 @@ class ClusterRedisConnection(val connector: ClusterRedisConnector) : Closeable,
}
}
}

override fun hset(key: String, field: String, value: String) {
connector.cluster.hset(key, field, value)
}

override fun hget(key: String, field: String): String? {
return connector.cluster.hget(key, field)
}

override fun hdel(key: String, vararg fields: String) {
connector.cluster.hdel(key, *fields)
}

override fun hexists(key: String, field: String): Boolean {
return connector.cluster.hexists(key, field)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,39 @@ interface IRedisConnection {
fun subscribe(vararg channel: String, patternMode: Boolean = false, func: RedisMessage.() -> Unit)

fun createPubSub(patternMode: Boolean, func: RedisMessage.() -> Unit): JedisPubSub

/**
* 向哈希表设置值
*
* @param key 哈希表键
* @param field 哈希表字段
* @param value 字段值
*/
fun hset(key: String, field: String, value: String)

/**
* 获取哈希表中的值
*
* @param key 哈希表键
* @param field 哈希表字段
* @return 字段值
*/
fun hget(key: String, field: String): String?

/**
* 删除哈希表中的字段
*
* @param key 哈希表键
* @param fields 要删除的字段
*/
fun hdel(key: String, vararg fields: String)

/**
* 检查哈希表中是否存在字段
*
* @param key 哈希表键
* @param field 哈希表字段
* @return 是否存在
*/
fun hexists(key: String, field: String): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

class SingleRedisConnection(internal var pool: JedisPool, internal val connector: SingleRedisConnector): Closeable, IRedisConnection {
class SingleRedisConnection(internal var pool: JedisPool, internal val connector: SingleRedisConnector) : Closeable,
IRedisConnection {

private val service: ExecutorService = Executors.newCachedThreadPool()

Expand Down Expand Up @@ -189,6 +190,51 @@ class SingleRedisConnection(internal var pool: JedisPool, internal val connector
}
}


/**
* 设置哈希键值
*
* @param key 哈希键
* @param field 哈希字段
* @param value 哈希值
*/
override fun hset(key: String, field: String, value: String) {
exec { it.hset(key, field, value) }
}

/**
* 获取哈希值
*
* @param key 哈希键
* @param field 哈希字段
* @return 哈希值
*/
override fun hget(key: String, field: String): String? {
return exec { it.hget(key, field) }
}

/**
* 删除哈希键值
*
* @param key 哈希键
* @param field 哈希字段
* @return 哈希值
*/
override fun hdel(key: String, vararg fields: String) {
exec { it.hdel(key, *fields) }
}

/**
* 查询哈希键是否存在
*
* @param key 哈希键
* @param field 哈希字段
* @return 布尔值
*/
override fun hexists(key: String, field: String): Boolean {
return exec { it.hexists(key, field) }
}

@Inject
internal companion object {

Expand Down