@@ -46,6 +46,7 @@ It enables you to set and query its data or use its PubSub topics to react to in
46
46
* [ API] ( #api )
47
47
* [ RedisClient] ( #redisclient )
48
48
* [ __ construct()] ( #__construct )
49
+ * [ __ clone()] ( #__clone )
49
50
* [ __ call()] ( #__call )
50
51
* [ callAsync()] ( #callasync )
51
52
* [ end()] ( #end )
@@ -415,6 +416,42 @@ $connector = new React\Socket\Connector([
415
416
$redis = new Clue\React\Redis\RedisClient('localhost', $connector);
416
417
```
417
418
419
+ #### __ clone()
420
+
421
+ The ` __clone() ` method is a magic method in PHP that is called
422
+ automatically when a ` RedisClient ` instance is being cloned:
423
+
424
+ ``` php
425
+ $original = new Clue\React\Redis\RedisClient($uri);
426
+ $redis = clone $original;
427
+ ```
428
+
429
+ This method ensures the cloned client is created in a "fresh" state and
430
+ any connection state is reset on the clone, matching how a new instance
431
+ would start after returning from its constructor. Accordingly, the clone
432
+ will always start in an unconnected and unclosed state, with no event
433
+ listeners attached and ready to accept commands. Invoking any of the
434
+ [ commands] ( #commands ) will establish a new connection as usual:
435
+
436
+ ``` php
437
+ $redis = clone $original;
438
+ $redis->set('name', 'Alice');
439
+ ```
440
+
441
+ This can be especially useful if the original connection is used for a
442
+ [ PubSub subscription] ( #pubsub ) or when using blocking commands or similar
443
+ and you need a control connection that is not affected by any of this.
444
+ Both instances will not be directly affected by any operations performed,
445
+ for example you can [ ` close() ` ] ( #close ) either instance without also
446
+ closing the other. Similarly, you can also clone a fresh instance from a
447
+ closed state or overwrite a dead connection:
448
+
449
+ ``` php
450
+ $redis->close();
451
+ $redis = clone $redis;
452
+ $redis->set('name', 'Alice');
453
+ ```
454
+
418
455
#### __ call()
419
456
420
457
The ` __call(string $name, list<string|int|float> $args): PromiseInterface<mixed> ` method can be used to
0 commit comments