Skip to content

Commit c51138c

Browse files
asafpamznjduo
andauthored
Function support (#23)
* update CI Signed-off-by: asafpamzn <[email protected]> Signed-off-by: asafpamzn <[email protected]> * Update ValkeyGlideClusterFeaturesTest.php Reduce loop count Signed-off-by: Asaf Porat Stoler <[email protected]> Signed-off-by: asafpamzn <[email protected]> Signed-off-by: asafpamzn <[email protected]> * revert test change Signed-off-by: asafpamzn <[email protected]> Signed-off-by: asafpamzn <[email protected]> * Enable logger Signed-off-by: asafpamzn <[email protected]> * Update error handling Signed-off-by: asafpamzn <[email protected]> * Update request timeout exceeded test (#21) Fix testing request timeout in cluster tests to evaluate an error code instead of expecting an exception. Signed-off-by: James Duong <[email protected]> Signed-off-by: asafpamzn <[email protected]> * Function support Signed-off-by: asafpamzn <[email protected]> * Function support Signed-off-by: asafpamzn <[email protected]> * Fixed function based on comment on PR Signed-off-by: asafpamzn <[email protected]> --------- Signed-off-by: asafpamzn <[email protected]> Signed-off-by: asafpamzn <[email protected]> Signed-off-by: Asaf Porat Stoler <[email protected]> Signed-off-by: James Duong <[email protected]> Co-authored-by: James Duong <[email protected]>
1 parent 684324b commit c51138c

File tree

5 files changed

+172
-175
lines changed

5 files changed

+172
-175
lines changed

command_response.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,32 @@ int command_response_to_zval(CommandResponse* response,
691691
}
692692
// printf("%s:%d - DEBUG: Finished processing array response\n", __FILE__, __LINE__);
693693
return 1;
694-
#if 1
694+
695695
case Map:
696696
// printf("%s:%d - CommandResponse is Map with length: %ld\n", __FILE__, __LINE__,
697697
// response->array_value_len);
698698
array_init(output);
699+
700+
// Special handling for FUNCTION command - skip server address wrapper
701+
if (use_associative_array == COMMAND_RESPONSE_ASSOSIATIVE_ARRAY_MAP_FUNCTION &&
702+
response->array_value_len == 1) {
703+
CommandResponse* element = &response->array_value[0];
704+
// Remove the first field of server address (contains ":")
705+
if (element->map_key != NULL && element->map_key->response_type == String) {
706+
char* key_str = element->map_key->string_value;
707+
if (strchr(key_str, ':') != NULL) {
708+
// Skip the server key and process only the value
709+
if (element->map_value != NULL) {
710+
return command_response_to_zval(element->map_value,
711+
output,
712+
use_associative_array,
713+
use_false_if_null);
714+
}
715+
}
716+
}
717+
}
718+
719+
// Normal Map processing
699720
for (int i = 0; i < response->array_value_len; i++) {
700721
zval key, value;
701722
CommandResponse* element = &response->array_value[i];
@@ -733,7 +754,7 @@ int command_response_to_zval(CommandResponse* response,
733754
}
734755
// php_var_dump(output, 2); // No need to modify this as it's not printf
735756
return 1;
736-
#endif
757+
737758
case Sets:
738759
array_init(output);
739760
for (int i = 0; i < response->sets_value_len; i++) {

command_response.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ enum CommandResponseToZvalFlags {
2929
COMMAND_RESPONSE_ASSOSIATIVE_ARRAY_MAP = 1, // Use associative array format for Map elements
3030
COMMAND_RESPONSE_STREAM_ARRAY_ASSOCIATIVE =
3131
2, // Use associative array format for stream entries
32-
COMMAND_RESPONSE_SCAN_ASSOSIATIVE_ARRAY = 3
32+
COMMAND_RESPONSE_SCAN_ASSOSIATIVE_ARRAY = 3,
33+
COMMAND_RESPONSE_ASSOSIATIVE_ARRAY_MAP_FUNCTION =
34+
4 // Use associative array format for FUNCTION command responses
3335
};
3436
/*
3537
* Execute a command and handle common error checking

tests/ValkeyGlideTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7073,12 +7073,6 @@ protected function testRequiresMode(string $mode)
70737073
}
70747074
}
70757075

7076-
7077-
7078-
7079-
7080-
7081-
70827076
public function testCopy()
70837077
{
70847078
if (version_compare($this->version, '6.2.0') < 0) {
@@ -7102,7 +7096,6 @@ public function testCopy()
71027096

71037097
public function testFunction()
71047098
{
7105-
$this->markTestSkipped();// TODO support for functions is not implemented yet
71067099
if (version_compare($this->version, '7.0') < 0) {
71077100
$this->markTestSkipped();
71087101
}

valkey_glide.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ public function pexpiretime(string $key): ValkeyGlide|int|false;
789789
*
790790
* @see https://valkey.io/commands/fcall
791791
*/
792-
/* TODO public function fcall(string $fn, array $keys = [], array $args = []): mixed; */
792+
public function fcall(string $fn, array $keys = [], array $args = []): mixed;
793793

794794
/**
795795
* This is a read-only variant of the FCALL command that cannot execute commands that modify data.
@@ -803,7 +803,7 @@ public function pexpiretime(string $key): ValkeyGlide|int|false;
803803
*
804804
* @see https://valkey.io/commands/fcall_ro
805805
*/
806-
/* TODO public function fcall_ro(string $fn, array $keys = [], array $args = []): mixed; */
806+
public function fcall_ro(string $fn, array $keys = [], array $args = []): mixed;
807807

808808
/**
809809
* Deletes every key in all ValkeyGlide databases
@@ -843,7 +843,7 @@ public function flushDB(?bool $sync = null): ValkeyGlide|bool;
843843
*
844844
* @see https://valkey.io/commands/function
845845
*/
846-
/* TODO public function function(string $operation, mixed ...$args): ValkeyGlide|bool|string|array; */
846+
public function function(string $operation, mixed ...$args): ValkeyGlide|bool|string|array;
847847

848848
/**
849849
* Add one or more members to a geospacial sorted set

0 commit comments

Comments
 (0)