diff options
author | michael-grunder <michael.grunder@gmail.com> | 2022-10-31 01:38:22 +0300 |
---|---|---|
committer | Michael Grunder <michael.grunder@gmail.com> | 2022-10-31 02:19:22 +0300 |
commit | fb3fb6f83f1e2b41a1f3054be1a2128b2d2b43b8 (patch) | |
tree | e34279c64f24be3a31f5d4a9d0aaac373c4cbd51 | |
parent | df50b2ad2d443c19b90a5000f6e0a976b07382b3 (diff) |
Copy docblock and fix DB option.
-rw-r--r-- | redis.stub.php | 50 | ||||
-rw-r--r-- | redis_arginfo.h | 2 | ||||
-rw-r--r-- | redis_commands.c | 2 | ||||
-rw-r--r-- | redis_legacy_arginfo.h | 2 |
4 files changed, 53 insertions, 3 deletions
diff --git a/redis.stub.php b/redis.stub.php index 2593f367..bfad44f7 100644 --- a/redis.stub.php +++ b/redis.stub.php @@ -462,6 +462,56 @@ class Redis { public function connect(string $host, int $port = 6379, float $timeout = 0, string $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array $context = null): bool; + /** + * Make a copy of a redis key. + * + * @see https://redis.io/commands/copy + * + * @param string $src The key to copy + * @param string $dst The name of the new key created from the source key. + * @param array $options An array with modifiers on how COPY should operate. + * + * Available Options: + * + * $options = [ + * 'REPLACE' => true|false // Whether Redis should replace an existing key. + * 'DB' => int // Copy the key to a specific DB. + * ]; + * + * @return Redis|bool True if the copy was completed and false if not. + * + * <code> + * <?php + * $redis = new Redis(['host' => 'localhost']); + * + * $redis->pipeline() + * ->select(1) + * ->del('newkey') + * ->select(0) + * ->del('newkey') + * ->mset(['source1' => 'value1', 'exists' => 'old_value']) + * ->exec(); + * + * // Will succeed, as 'newkey' doesn't exist + * var_dump($redis->copy('source1', 'newkey')); + * + * // Will succeed, because 'newkey' doesn't exist in DB 1 + * var_dump($redis->copy('source1', 'newkey', ['db' => 1])); + * + * // Will fail, because 'exists' does exist + * var_dump($redis->copy('source1', 'exists')); + * + * // Will succeed, because even though 'exists' is a key, we sent the REPLACE option. + * var_dump($redis->copy('source1', 'exists', ['REPLACE' => true])); + * + * // --- OUTPUT --- + * // bool(true) + * // bool(true) + * // bool(false) + * // bool(true) + * ?> + * </code> + */ public function copy(string $src, string $dst, array $options = null): Redis|bool; /** diff --git a/redis_arginfo.h b/redis_arginfo.h index 1d09f27e..d7d9e5d8 100644 --- a/redis_arginfo.h +++ b/redis_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d9cbe3fdc3c4cd1b079427a54ff2b24ac1c21adc */ + * Stub hash: 1e5a8c3e8d885354e26185e651b0f7ee0dbf8374 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null") diff --git a/redis_commands.c b/redis_commands.c index 7a9812fc..b17c7d59 100644 --- a/redis_commands.c +++ b/redis_commands.c @@ -5178,7 +5178,7 @@ redis_copy_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } ZEND_HASH_FOREACH_END(); } - REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, 2 + (db > -1) + replace, "COPY"); + REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, 2 + (db > -1 ? 2 : 0) + replace, "COPY"); redis_cmd_append_sstr(&cmdstr, src, src_len); redis_cmd_append_sstr(&cmdstr, dst, dst_len); diff --git a/redis_legacy_arginfo.h b/redis_legacy_arginfo.h index c8c5d4bf..0865c1bb 100644 --- a/redis_legacy_arginfo.h +++ b/redis_legacy_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d9cbe3fdc3c4cd1b079427a54ff2b24ac1c21adc */ + * Stub hash: 1e5a8c3e8d885354e26185e651b0f7ee0dbf8374 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) ZEND_ARG_INFO(0, options) |