| Command | Description | Supported | Tested | Class/Trait | Method |
|---|---|---|---|---|---|
| hDel | Delete one or more hash fields | ✅ | ✅ | Hashes | hDel |
| hExists | Determine if a hash field exists | ✅ | ✅ | Hashes | hExists |
| hGet | Get the value of a hash field | ✅ | ✅ | Hashes | hGet |
| hGetAll | Get all the fields and values in a hash | ✅ | ✅ | Hashes | hGetAll |
| hIncrBy | Increment the integer value of a hash field by the given number | ✅ | ✅ | Hashes | hIncrBy |
| hIncrByFloat | Increment the float value of a hash field by the given amount | ✅ | ✅ | Hashes | hIncrByFloat |
| hKeys | Get all the fields in a hash | ✅ | ✅ | Hashes | hKeys |
| hLen | Get the number of fields in a hash | ✅ | ✅ | Hashes | hLen |
| hMGet | Get the values of all the given hash fields | ✅ | ✅ | Hashes | hMGet |
| hMSet | Set multiple hash fields to multiple values | ✅ | ✅ | Hashes | hMSet |
| hScan | Scan a hash key for members | ✅ | ✅ | Hashes | hScan |
| hSet | Set the string value of a hash field | ✅ | ✅ | Hashes | hSet |
| hSetNx | Set the value of a hash field, only if the field does not exist | ✅ | ✅ | Hashes | hSetNx |
| hStrLen | Get the string length of the value associated with field in the hash | ✅ | ✅ | Hashes | hStrLen |
| hVals | Get all the values in a hash | ✅ | ✅ | Hashes | hVals |
$valkey = new Valkey();
$valkey->connect('127.0.0.1', 6379);
$valkey->hSet('hash', 'key1', 'hello'); /* 1, 'key1' => 'hello' in the hash at "h" */
$valkey->hGet('hash', 'key1'); /* returns "hello" */
$valkey->hSetNx('hash', 'key1', 'hello'); /* TRUE, 'key1' => 'hello' in the hash at "hash" */
$valkey->hLen('hash'); /* returns 2 */
$valkey->hGetAll('hash');
$valkey->hKeys('hash');
$valkey->hVals('hash');Description: Adds a value to the hash stored at key.
key
hashKey
value
LONG 1 if value didn't exist and was added successfully, 0 if the value was already present and was replaced, FALSE if there was an error.
$valkey->del('hash')
$valkey->hSet('hash', 'key1', 'hello'); /* 1, 'key1' => 'hello' in the hash at "h" */
$valkey->hGet('hash', 'key1'); /* returns "hello" */
$valkey->hSet('hash', 'key1', 'plop'); /* 0, value was replaced. */
$valkey->hGet('hash', 'key1'); /* returns "plop" */Description: Adds a value to the hash stored at key only if this field isn't already in the hash.
BOOL TRUE if the field was set, FALSE if it was already present.
$valkey->del('hash')
$valkey->hSetNx('hash', 'key1', 'hello'); /* TRUE, 'key1' => 'hello' in the hash at "h" */
$valkey->hSetNx('hash', 'key1', 'world'); /* FALSE, 'key1' => 'hello' in the hash at "h". No change since the field wasn't replaced. */Description: Gets a value from the hash stored at key. If the hash table doesn't exist, or the key doesn't exist, FALSE is returned.
key
hashKey
STRING The value, if the command executed successfully
BOOL FALSE in case of failure
Description: Returns the length of a hash, in number of items
key
LONG the number of items in a hash, FALSE if the key doesn't exist or isn't a hash.
$valkey->del('hash')
$valkey->hSet('hash', 'key1', 'hello');
$valkey->hSet('hash', 'key2', 'plop');
$valkey->hLen('hash'); /* returns 2 */Description: Removes a value from the hash stored at key. If the hash table doesn't exist, or the key doesn't exist, FALSE is returned.
key
hashKey1
hashKey2
...
LONG the number of deleted keys, 0 if the key doesn't exist, FALSE if the key isn't a hash.
Description: Returns the keys in a hash, as an array of strings.
Key: key
An array of elements, the keys of the hash. This works like PHP's array_keys().
$valkey->del('hash');
$valkey->hSet('hash', 'a', 'x');
$valkey->hSet('hash', 'b', 'y');
$valkey->hSet('hash', 'c', 'z');
$valkey->hSet('hash', 'd', 't');
var_dump($valkey->hKeys('hash'));Output:
array(4) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
[3]=>
string(1) "d"
}
The order is random and corresponds to redis' own internal representation of the set structure.
Description: Returns the values in a hash, as an array of strings.
Key: key
An array of elements, the values of the hash. This works like PHP's array_values().
$valkey->del('hash');
$valkey->hSet('hash', 'a', 'x');
$valkey->hSet('hash', 'b', 'y');
$valkey->hSet('hash', 'c', 'z');
$valkey->hSet('hash', 'd', 't');
var_dump($valkey->hVals('hash'));Output:
array(4) {
[0]=>
string(1) "x"
[1]=>
string(1) "y"
[2]=>
string(1) "z"
[3]=>
string(1) "t"
}
The order is random and corresponds to redis' own internal representation of the set structure.
Description: Returns the whole hash, as an array of strings indexed by strings.
Key: key
An array of elements, the contents of the hash.
$valkey->del('hash');
$valkey->hSet('hash', 'a', 'x');
$valkey->hSet('hash', 'b', 'y');
$valkey->hSet('hash', 'c', 'z');
$valkey->hSet('hash', 'd', 't');
var_dump($valkey->hGetAll('hash'));Output:
array(4) {
["a"]=>
string(1) "x"
["b"]=>
string(1) "y"
["c"]=>
string(1) "z"
["d"]=>
string(1) "t"
}
The order is random and corresponds to redis' own internal representation of the set structure.
Description: Verify if the specified member exists in a key.
key
memberKey
BOOL: If the member exists in the hash table, return TRUE, otherwise return FALSE.
$valkey->hSet('hash', 'a', 'x');
$valkey->hExists('hash', 'a'); /* TRUE */
$valkey->hExists('hash', 'NonExistingKey'); /* FALSE */Description: Increments the value of a member from a hash by a given amount.
key
member
value: (integer) value that will be added to the member's value
LONG the new value
$valkey->del('hash');
$valkey->hIncrBy('hash', 'x', 2); /* returns 2: h[x] = 2 now. */
$valkey->hIncrBy('hash', 'x', 1); /* h[x] ← 2 + 1. Returns 3 */Description: Increments the value of a hash member by the provided float value
key
member
value: (float) value that will be added to the member's value
FLOAT the new value
$valkey->del('hash');
$valkey->hIncrByFloat('hash','x', 1.5); /* returns 1.5: h[x] = 1.5 now */
$valkey->hIncrByFloat('hash', 'x', 1.5); /* returns 3.0: h[x] = 3.0 now */
$valkey->hIncrByFloat('hash', 'x', -3.0); /* returns 0.0: h[x] = 0.0 now */Description: Fills in a whole hash. Non-string values are converted to string, using the standard (string) cast. NULL values are stored as empty strings.
key
members: key → value array
BOOL
$valkey->del('user:1');
$valkey->hMSet('user:1', ['name' => 'Joe', 'salary' => 2000]);
$valkey->hIncrBy('user:1', 'salary', 100); // Joe earns 100 more now.Description: Retrieve the values associated to the specified fields in the hash.
key
memberKeys Array
Array An array of elements, the values of the specified fields in the hash, with the hash keys as array keys.
$valkey->del('hash');
$valkey->hSet('hash', 'field1', 'value1');
$valkey->hSet('hash', 'field2', 'value2');
$valkey->hMGet('hash', ['field1', 'field2']); /* returns ['field1' => 'value1', 'field2' => 'value2'] */Description: Scan a HASH value for members, with an optional pattern and count
key: String
iterator: Long (reference)
pattern: Optional pattern to match against
count: How many keys to return in a go (only a suggestion to Valkey)
Array An array of members that match our pattern
$it = NULL;
/* Don't ever return an empty array until we're done iterating */
$valkey->setOption(Valkey::OPT_SCAN, Valkey::SCAN_RETRY);
while($arr_keys = $valkey->hScan('hash', $it)) {
foreach($arr_keys as $str_field => $str_value) {
echo "$str_field => $str_value\n"; /* Print the hash member and value */
}
}Description: Get the string length of the value associated with field in the hash stored at key.
key: String
field: String
LONG the string length of the value associated with field, or zero when field is not present in the hash or key does not exist at all.