-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support full set of redis hash commands #20
- Loading branch information
John Loehrer
committed
Aug 7, 2024
1 parent
476ad06
commit 846a0b1
Showing
4 changed files
with
455 additions
and
4 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
...les/api/src/main/scala/com/github/scoquelin/arugula/commands/RedisHashAsyncCommands.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,165 @@ | ||
package com.github.scoquelin.arugula.commands | ||
|
||
import scala.collection.immutable.ListMap | ||
import scala.concurrent.Future | ||
|
||
import com.github.scoquelin.arugula.commands.RedisKeyAsyncCommands.ScanCursor | ||
|
||
/** | ||
* Asynchronous commands for manipulating/querying Hashes (key/value pairs) | ||
* | ||
* @tparam K The key type | ||
* @tparam V The value type | ||
*/ | ||
trait RedisHashAsyncCommands[K, V] { | ||
/** | ||
* Delete one or more hash fields | ||
* @param key The key | ||
* @param fields The fields to delete | ||
* @return The number of fields that were removed from the hash | ||
*/ | ||
def hDel(key: K, fields: K*): Future[Long] | ||
|
||
/** | ||
* Determine if a hash field exists | ||
* @param key The key | ||
* @param field The field | ||
* @return True if the field exists, false otherwise | ||
*/ | ||
def hExists(key: K, field: K): Future[Boolean] | ||
|
||
/** | ||
* Get the value of a hash field | ||
* @param key The key | ||
* @param field The field | ||
* @return The value of the field, or None if the field does not exist | ||
*/ | ||
def hGet(key: K, field: K): Future[Option[V]] | ||
|
||
/** | ||
* get all the keys in a hash | ||
* @param key The key | ||
* @return A list of all the keys in the hash | ||
*/ | ||
def hKeys(key: K): Future[Seq[K]] | ||
|
||
/** | ||
* Get the number of fields in a hash | ||
* @param key The key | ||
* @return The number of fields in the hash | ||
*/ | ||
def hLen(key: K): Future[Long] | ||
|
||
/** | ||
* Get the values of all the fields in a hash | ||
* @param key The key | ||
* @return A list of all the values in the hash | ||
*/ | ||
def hGetAll(key: K): Future[Map[K, V]] | ||
|
||
/** | ||
* Set the value of a hash field | ||
* @param key The key | ||
* @param field The field | ||
* @param value The value | ||
* @return True if the field is new, false if it was updated | ||
*/ | ||
def hSet(key: K, field: K, value: V): Future[Boolean] | ||
|
||
/** | ||
* Get the values of multiple hash fields | ||
* @param key The key | ||
* @param fields The fields | ||
* @return A map of field -> value for each field that exists or None if the field does not exist | ||
*/ | ||
def hMGet(key: K, fields: K*): Future[ListMap[K, Option[V]]] | ||
|
||
/** | ||
* Get the values of multiple hash fields | ||
* @param key The key | ||
* @param fields The fields | ||
* @return A map of field -> value for each field that exists or None if the field does not exist | ||
*/ | ||
def hMGet(key: K, fields: => Seq[K]): Future[Map[K, Option[V]]] | ||
|
||
/** | ||
* Set the values of multiple hash fields | ||
* @param key The key | ||
* @param values A map of field -> value | ||
*/ | ||
def hMSet(key: K, values: Map[K, V]): Future[Unit] | ||
|
||
/** | ||
* Set the value of a hash field, only if the field does not exist | ||
* @param key The key | ||
* @param field The field | ||
* @param value The value | ||
* @return True if the field was set, false if the field already existed | ||
*/ | ||
def hSetNx(key: K, field: K, value: V): Future[Boolean] | ||
|
||
/** | ||
* Increment the integer value of a hash field by the given number | ||
* @param key The key | ||
* @param field The field | ||
* @param amount The amount to increment by | ||
* @return The new value of the field | ||
*/ | ||
def hIncrBy(key: K, field: K, amount: Long): Future[Long] | ||
|
||
/** | ||
* Get a random field from a hash | ||
* @param key The key | ||
* @return A random field from the hash, or None if the hash is empty | ||
*/ | ||
def hRandField(key: K): Future[Option[K]] | ||
|
||
/** | ||
* Get multiple random fields from a hash | ||
* @param key The key | ||
* @param count The number of fields to get | ||
* @return A list of random fields from the hash | ||
*/ | ||
def hRandField(key: K, count: Long): Future[Seq[K]] | ||
|
||
/** | ||
* Get a random field and its value from a hash | ||
* @param key The key | ||
* @return A random field and its value from the hash, or None if the hash is empty | ||
*/ | ||
def hRandFieldWithValues(key: K): Future[Option[(K, V)]] | ||
|
||
/** | ||
* Get multiple random fields and their values from a hash | ||
* @param key The key | ||
* @param count The number of fields to get | ||
* @return A map of random fields and their values from the hash | ||
*/ | ||
def hRandFieldWithValues(key: K, count: Long): Future[Map[K, V]] | ||
|
||
/** | ||
* scan the fields of a hash, returning the cursor and a map of field -> value | ||
* Repeat calls with the returned cursor to get all fields until the cursor is finished | ||
* @param key The key | ||
* @param cursor The cursor | ||
* @param limit The maximum number of fields to return | ||
* @param matchPattern A glob-style pattern to match fields against | ||
* @return The next cursor and a map of field -> value | ||
*/ | ||
def hScan(key: K, cursor: ScanCursor = ScanCursor.Initial, limit: Option[Long] = None, matchPattern: Option[String] = None): Future[(ScanCursor, Map[K, V])] | ||
|
||
/** | ||
* Get the length of a hash field value | ||
* @param key The key | ||
* @param field The field | ||
* @return The length of the field value | ||
*/ | ||
def hStrLen(key: K, field: K): Future[Long] | ||
|
||
/** | ||
* Get the values of all the fields in a hash | ||
* @param key The key | ||
* @return A list of all the values in the hash | ||
*/ | ||
def hVals(key: K): Future[Seq[V]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.