@@ -47,6 +47,7 @@ It enables you to set and query its data or use its PubSub topics to react to in
47
47
* [ RedisClient] ( #redisclient )
48
48
* [ __ construct()] ( #__construct )
49
49
* [ __ call()] ( #__call )
50
+ * [ callAsync()] ( #callasync )
50
51
* [ end()] ( #end )
51
52
* [ close()] ( #close )
52
53
* [ error event] ( #error-event )
@@ -124,7 +125,8 @@ Each method call matches the respective [Redis command](https://redis.io/command
124
125
For example, the ` $redis->get() ` method will invoke the [ ` GET ` command] ( https://redis.io/commands/get ) .
125
126
126
127
All [ Redis commands] ( https://redis.io/commands ) are automatically available as
127
- public methods via the magic [ ` __call() ` method] ( #__call ) .
128
+ public methods via the magic [ ` __call() ` method] ( #__call ) or through the more
129
+ explicit [ ` callAsync() ` method] .
128
130
Listing all available commands is out of scope here, please refer to the
129
131
[ Redis command reference] ( https://redis.io/commands ) .
130
132
@@ -432,6 +434,8 @@ $redis->get($key)->then(function (?string $value) {
432
434
433
435
All [ Redis commands] ( https://redis.io/commands ) are automatically available as
434
436
public methods via this magic ` __call() ` method.
437
+ Note that some static analysis tools may not understand this magic method, so
438
+ you may also the [ ` callAsync() ` method] ( #callasync ) as a more explicit alternative.
435
439
Listing all available commands is out of scope here, please refer to the
436
440
[ Redis command reference] ( https://redis.io/commands ) .
437
441
@@ -445,6 +449,43 @@ Each of these commands supports async operation and returns a [Promise](#promise
445
449
that eventually * fulfills* with its * results* on success or * rejects* with an
446
450
` Exception ` on error. See also [ promises] ( #promises ) for more details.
447
451
452
+ #### callAsync()
453
+
454
+ The ` callAsync(string $command, string ...$args): PromiseInterface<mixed> ` method can be used to
455
+ invoke a Redis command.
456
+
457
+ ``` php
458
+ $redis->callAsync('GET', 'name')->then(function (?string $name): void {
459
+ echo 'Name: ' . ($name ?? 'Unknown') . PHP_EOL;
460
+ }, function (Throwable $e): void {
461
+ echo 'Error: ' . $e->getMessage() . PHP_EOL;
462
+ });
463
+ ```
464
+
465
+ The ` string $command ` parameter can be any valid Redis command. All
466
+ [ Redis commands] ( https://redis.io/commands/ ) are available through this
467
+ method. As an alternative, you may also use the magic
468
+ [ ` __call() ` method] ( #__call ) , but note that not all static analysis tools
469
+ may understand this magic method. Listing all available commands is out
470
+ of scope here, please refer to the
471
+ [ Redis command reference] ( https://redis.io/commands ) .
472
+
473
+ The optional ` string ...$args ` parameter can be used to pass any
474
+ additional arguments to the Redis command. Some commands may require or
475
+ support additional arguments that this method will simply forward as is.
476
+ Internally, Redis requires all arguments to be coerced to ` string ` values,
477
+ but you may also rely on PHP's type-juggling semantics and pass ` int ` or
478
+ ` float ` values:
479
+
480
+ ``` php
481
+ $redis->callAsync('SET', 'name', 'Alice', 'EX', 600);
482
+ ```
483
+
484
+ This method supports async operation and returns a [ Promise] ( #promises )
485
+ that eventually * fulfills* with its * results* on success or * rejects*
486
+ with an ` Exception ` on error. See also [ promises] ( #promises ) for more
487
+ details.
488
+
448
489
#### end()
449
490
450
491
The ` end():void ` method can be used to
0 commit comments