forked from valkey-io/valkey-glide-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalkey_glide.stub.php
More file actions
4170 lines (3891 loc) · 174 KB
/
valkey_glide.stub.php
File metadata and controls
4170 lines (3891 loc) · 174 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @generate-function-entries
* @generate-legacy-arginfo
* @generate-class-entries
*/
/*
* --------------------------------------------------------------------
* The PHP License, version 3.01
* Copyright (c) 1999 - 2010 The PHP Group. All rights reserved.
* --------------------------------------------------------------------
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The name "PHP" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact group@php.net.
*
* 4. Products derived from this software may not be called "PHP", nor
* may "PHP" appear in their name, without prior written permission
* from group@php.net. You may indicate that your software works in
* conjunction with PHP by saying "Foo for PHP" instead of calling
* it "PHP Foo" or "phpfoo"
*
* 5. The PHP Group may publish revised and/or new versions of the
* license from time to time. Each version will be given a
* distinguishing version number.
* Once covered code has been published under a particular version
* of the license, you may always continue to use it under the terms
* of that version. You may also choose to use such covered code
* under the terms of any subsequent version of the license
* published by the PHP Group. No one other than the PHP Group has
* the right to modify the terms applicable to covered code created
* under this License.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes PHP software, freely available from
* <http://www.php.net/software/>".
*
* THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
* DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* --------------------------------------------------------------------
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the PHP Group.
*
* The PHP Group can be contacted via Email at group@php.net.
*
* For more information on the PHP Group and the PHP project,
* please see <http://www.php.net>.
*
* PHP includes the Zend Engine, freely available at
* <http://www.zend.com>.
*/
class ValkeyGlide
{
/**
* Hash field condition constants
* @var string
*/
public const CONDITION_NX = "NX"; // Only if field doesn't exist
/**
* @var string
*/
public const CONDITION_XX = "XX"; // Only if field exists
/**
* Time unit constants for hash field expiration
* @var string
*/
public const TIME_UNIT_SECONDS = "EX"; // Expire in seconds
/**
* @var string
*/
public const TIME_UNIT_MILLISECONDS = "PX"; // Expire in milliseconds
/**
* @var string
*/
public const TIME_UNIT_TIMESTAMP_SECONDS = "EXAT"; // Expire at timestamp (seconds)
/**
* @var string
*/
public const TIME_UNIT_TIMESTAMP_MILLISECONDS = "PXAT"; // Expire at timestamp (milliseconds)
/**
*
* @var int
* @cvalue VALKEY_GLIDE_NOT_FOUND
*
*/
public const VALKEY_GLIDE_NOT_FOUND = UNKNOWN;
/**
*
* @var int
* @cvalue VALKEY_GLIDE_STRING
*
*/
public const VALKEY_GLIDE_STRING = UNKNOWN;
/**
*
* @var int
* @cvalue VALKEY_GLIDE_SET
*
*/
public const VALKEY_GLIDE_SET = UNKNOWN;
/**
*
* @var int
* @cvalue VALKEY_GLIDE_LIST
*
*/
public const VALKEY_GLIDE_LIST = UNKNOWN;
/**
*
* @var int
* @cvalue VALKEY_GLIDE_ZSET
*
*/
public const VALKEY_GLIDE_ZSET = UNKNOWN;
/**
*
* @var int
* @cvalue VALKEY_GLIDE_HASH
*
*/
public const VALKEY_GLIDE_HASH = UNKNOWN;
/**
*
* @var int
* @cvalue VALKEY_GLIDE_STREAM
*
*/
public const VALKEY_GLIDE_STREAM = UNKNOWN;
/**
* @var int
* Always get from primary, in order to get the freshest data.
*/
public const READ_FROM_PRIMARY = 0;
/**
* @var int
* Spread the requests between all replicas in a round robin manner.
* If no replica is available, route the requests to the primary.
*/
public const READ_FROM_PREFER_REPLICA = 1;
/**
* @var int
* Spread the read requests between replicas in the same client's AZ (Availability zone)
* in a round robin manner, falling back to other replicas or the primary if needed.
*/
public const READ_FROM_AZ_AFFINITY = 2;
/**
* @var int
* Spread the read requests among nodes within the client's Availability Zone (AZ)
* in a round robin manner, prioritizing local replicas, then the local primary,
* and falling back to any replica or the primary if needed.
*/
public const READ_FROM_AZ_AFFINITY_REPLICAS_AND_PRIMARY = 3;
/**
* @var string
* COPY command option key for replacing existing destination key
*/
public const COPY_REPLACE = 'REPLACE';
/**
* @var string
* COPY command option key for specifying destination database
*/
public const COPY_DB = 'DB';
/**
* IAM Authentication Constants
*/
/**
* @var string
* IAM service type for AWS ElastiCache
*/
public const IAM_SERVICE_ELASTICACHE = 'Elasticache';
/**
* @var string
* IAM service type for AWS MemoryDB
*/
public const IAM_SERVICE_MEMORYDB = 'MemoryDB';
/**
* @var string
* IAM config key for cluster name
*/
public const IAM_CONFIG_CLUSTER_NAME = 'clusterName';
/**
* @var string
* IAM config key for AWS region
*/
public const IAM_CONFIG_REGION = 'region';
/**
* @var string
* IAM config key for service type
*/
public const IAM_CONFIG_SERVICE = 'service';
/**
* @var string
* IAM config key for token refresh interval in seconds
*/
public const IAM_CONFIG_REFRESH_INTERVAL = 'refreshIntervalSeconds';
/**
*
* @var string
*
*/
public const BEFORE = "before";
/**
*
* @var string
*
*/
public const AFTER = "after";
/**
*
* @var string
*
*/
public const LEFT = "left";
/**
*
* @var string
*
*/
public const RIGHT = "right";
/**
*
* @var int
* @cvalue MULTI
*
*/
public const MULTI = UNKNOWN;
/**
*
* @var int
* @cvalue PIPELINE
*
*/
public const PIPELINE = UNKNOWN;
/**
* Create a new ValkeyGlide instance with the provided configuration.
*
* @param array $addresses Array of server addresses [['host' => 'localhost', 'port' => 6379], ...].
* @param bool $use_tls Whether to use TLS encryption.
* @param array|null $credentials Authentication credentials. Can be either:
* - Password auth: ['password' => 'xxx', 'username' => 'yyy']
* - IAM auth: ['username' => 'yyy', 'iamConfig' => [
* ValkeyGlide::IAM_CONFIG_CLUSTER_NAME => 'my-cluster',
* ValkeyGlide::IAM_CONFIG_REGION => 'us-east-1',
* ValkeyGlide::IAM_CONFIG_SERVICE => ValkeyGlide::IAM_SERVICE_ELASTICACHE,
* ValkeyGlide::IAM_CONFIG_REFRESH_INTERVAL => 300 // optional, defaults to 300
* ]]
* Note: username is REQUIRED for IAM authentication.
* @param int $read_from Read strategy for the client.
* @param int|null $request_timeout Request timeout in milliseconds.
* @param array|null $reconnect_strategy Reconnection strategy ['num_of_retries' => 3, 'factor' => 2,
* 'exponent_base' => 10, 'jitter_percent' => 15].
* @param int|null $database_id Database ID to select (0 or higher)
* @param string|null $client_name Client name identifier.
* @param string|null $client_az Client availability zone.
* @param array|null $advanced_config Advanced configuration ['connection_timeout' => 5000,
* 'tls_config' => ['use_insecure_tls' => false],
* 'otel' => OpenTelemetryConfig::builder()
* ->traces(TracesConfig::builder()
* ->endpoint('grpc://localhost:4317')
* ->samplePercentage(1)
* ->build())
* ->metrics(MetricsConfig::builder()
* ->endpoint('grpc://localhost:4317')
* ->build())
* ->flushIntervalMs(5000)
* ->build()].
* connection_timeout is in milliseconds.
* @param bool|null $lazy_connect Whether to use lazy connection.
*/
public function __construct(
array $addresses,
bool $use_tls = false,
?array $credentials = null,
int $read_from = ValkeyGlide::READ_FROM_PRIMARY,
?int $request_timeout = null,
?array $reconnect_strategy = null,
?int $database_id = null,
?string $client_name = null,
?string $client_az = null,
?array $advanced_config = null,
?bool $lazy_connect = null
);
public function __destruct();
/**
* Append data to a ValkeyGlide STRING key.
*
* @param string $key The key in question
* @param mixed $value The data to append to the key.
*
* @return ValkeyGlide|int|false The new string length of the key or false on failure.
*
* @see https://valkey.io/commands/append
*
* @example
* $valkey_glide->set('foo', 'hello);
* $valkey_glide->append('foo', 'world');
*/
public function append(string $key, mixed $value): ValkeyGlide|int|false;
/**
* Count the number of set bits in a ValkeyGlide string.
*
* @see https://valkey.io/commands/bitcount/
*
* @param string $key The key in question (must be a string key)
* @param int $start The index where ValkeyGlide should start counting. If omitted it
* defaults to zero, which means the start of the string.
* @param int $end The index where ValkeyGlide should stop counting. If omitted it
* defaults to -1, meaning the very end of the string.
*
* @param bool $bybit Whether or not ValkeyGlide should treat $start and $end as bit
* positions, rather than bytes.
*
* @return ValkeyGlide|int|false The number of bits set in the requested range.
*
*/
public function bitcount(string $key, int $start = 0, int $end = -1, bool $bybit = false): ValkeyGlide|int|false;
public function bitop(string $operation, string $deskey, string $srckey, string ...$other_keys): ValkeyGlide|int|false;
/**
* Return the position of the first bit set to 0 or 1 in a string.
*
* @see https://valkey.io/commands/bitpos/
*
* @param string $key The key to check (must be a string)
* @param bool $bit Whether to look for an unset (0) or set (1) bit.
* @param int $start Where in the string to start looking.
* @param int $end Where in the string to stop looking.
* @param bool $bybit If true, ValkeyGlide will treat $start and $end as BIT values and not bytes, so if start
* was 0 and end was 2, ValkeyGlide would only search the first two bits.
*
* @return ValkeyGlide|int|false The position of the first set or unset bit.
**/
public function bitpos(string $key, bool $bit, int $start = 0, int $end = -1, bool $bybit = false): ValkeyGlide|int|false;
/**
* Pop an element off the beginning of a ValkeyGlide list or lists, potentially blocking up to a specified
* timeout. This method may be called in two distinct ways, of which examples are provided below.
*
* @see https://valkey.io/commands/blpop/
*
* @param string|array $key_or_keys This can either be a string key or an array of one or more
* keys.
* @param string|float|int $timeout_or_key If the previous argument was a string key, this can either
* be an additional key, or the timeout you wish to send to
* the command.
*
* @return ValkeyGlide|array|null|false Can return various things depending on command and data in ValkeyGlide.
*
* @example
* $valkey_glide->blPop('list1', 'list2', 'list3', 1.5);
* $relay->blPop(['list1', 'list2', 'list3'], 1.5);
*/
public function blPop(string|array $key_or_keys, string|float|int $timeout_or_key, mixed ...$extra_args): ValkeyGlide|array|null|false;
/**
* Pop an element off of the end of a ValkeyGlide list or lists, potentially blocking up to a specified timeout.
* The calling convention is identical to ValkeyGlide::blPop() so see that documentation for more details.
*
* @see https://valkey.io/commands/brpop/
* @see ValkeyGlide::blPop()
*
*/
public function brPop(string|array $key_or_keys, string|float|int $timeout_or_key, mixed ...$extra_args): ValkeyGlide|array|null|false;
/**
* POP the maximum scoring element off of one or more sorted sets, blocking up to a specified
* timeout if no elements are available.
*
* Following are examples of the two main ways to call this method.
*
* **NOTE**: We recommend calling this function with an array and a timeout as the other strategy
* may be deprecated in future versions of PhpValkeyGlide
*
* @see https://valkey.io/commands/bzpopmax
*
* @param string|array $key_or_keys Either a string key or an array of one or more keys.
* @param string|int $timeout_or_key If the previous argument was an array, this argument
* must be a timeout value. Otherwise it could also be
* another key.
* @param mixed $extra_args Can consist of additional keys, until the last argument
* which needs to be a timeout.
*
* @return ValkeyGlide|array|false The popped elements.
*
* @example
* $valkey_glide->bzPopMax('key1', 'key2', 'key3', 1.5);
* $valkey_glide->bzPopMax(['key1', 'key2', 'key3'], 1.5);
*/
public function bzPopMax(string|array $key, string|int $timeout_or_key, mixed ...$extra_args): ValkeyGlide|array|false;
/**
* POP the minimum scoring element off of one or more sorted sets, blocking up to a specified timeout
* if no elements are available
*
* This command is identical in semantics to bzPopMax so please see that method for more information.
*
* @see https://valkey.io/commands/bzpopmin
* @see ValkeyGlide::bzPopMax()
*
*/
public function bzPopMin(string|array $key, string|int $timeout_or_key, mixed ...$extra_args): ValkeyGlide|array|false;
/**
* POP one or more elements from one or more sorted sets, blocking up to a specified amount of time
* when no elements are available.
*
* @param float $timeout How long to block if there are no element available
* @param array $keys The sorted sets to pop from
* @param string $from The string 'MIN' or 'MAX' (case insensitive) telling ValkeyGlide whether you wish to
* pop the lowest or highest scoring members from the set(s).
* @param int $count Pop up to how many elements.
*
* @return ValkeyGlide|array|null|false This function will return an array of popped elements, or false
* depending on whether any elements could be popped within the
* specified timeout.
*
*/
public function bzmpop(float $timeout, array $keys, string $from, int $count = 1): ValkeyGlide|array|null|false;
/**
* POP one or more of the highest or lowest scoring elements from one or more sorted sets.
*
* @see https://valkey.io/commands/zmpop
*
* @param array $keys One or more sorted sets
* @param string $from The string 'MIN' or 'MAX' (case insensitive) telling ValkeyGlide whether you want to
* pop the lowest or highest scoring elements.
* @param int $count Pop up to how many elements at once.
*
* @return ValkeyGlide|array|null|false An array of popped elements or false if none could be popped.
*/
public function zmpop(array $keys, string $from, int $count = 1): ValkeyGlide|array|null|false;
/**
* Pop one or more elements from one or more ValkeyGlide LISTs, blocking up to a specified timeout when
* no elements are available.
*
* @see https://valkey.io/commands/blmpop
*
* @param float $timeout The number of seconds ValkeyGlide will block when no elements are available.
* @param array $keys One or more ValkeyGlide LISTs to pop from.
* @param string $from The string 'LEFT' or 'RIGHT' (case insensitive), telling ValkeyGlide whether
* to pop elements from the beginning or end of the LISTs.
* @param int $count Pop up to how many elements at once.
*
* @return ValkeyGlide|array|null|false One or more elements popped from the list(s) or false if all LISTs
* were empty.
*/
public function blmpop(float $timeout, array $keys, string $from, int $count = 1): ValkeyGlide|array|null|false;
/**
* Pop one or more elements off of one or more ValkeyGlide LISTs.
*
* @see https://valkey.io/commands/lmpop
*
* @param array $keys An array with one or more ValkeyGlide LIST key names.
* @param string $from The string 'LEFT' or 'RIGHT' (case insensitive), telling ValkeyGlide whether to pop\
* elements from the beginning or end of the LISTs.
* @param int $count The maximum number of elements to pop at once.
*
* @return ValkeyGlide|array|null|false One or more elements popped from the LIST(s) or false if all the LISTs
* were empty.
*
*/
public function lmpop(array $keys, string $from, int $count = 1): ValkeyGlide|array|null|false;
public function client(string $opt, mixed ...$args): mixed;
public function close(): bool;
/**
* Set the OpenTelemetry sample percentage at runtime.
*
* @param int $percentage The sample percentage (0-100)
* @throws Exception if OpenTelemetry is not initialized or percentage is invalid
*/
public static function setOtelSamplePercentage(int $percentage): void;
/**
* Get the current OpenTelemetry sample percentage.
*
* @return int|null The sample percentage (0-100), or null if not initialized
*/
public static function getOtelSamplePercentage(): ?int;
/**
* Update the connection password.
*
* @param string $password The new password to set
* @param bool $immediateAuth If true, re-authenticate immediately after updating password
* @return string Returns "OK" on success
* @throws Exception if the operation fails or IAM authentication is enabled
*/
public function updateConnectionPassword(string $password, bool $immediateAuth = false): string;
/**
* Clear the connection password.
*
* @param bool $immediateAuth If true, re-authenticate immediately after clearing password
* @return string Returns "OK" on success
* @throws Exception if the operation fails or IAM authentication is enabled
*/
public function clearConnectionPassword(bool $immediateAuth = false): string;
/**
* Execute the ValkeyGlide CONFIG command in a variety of ways.
*
* What the command does in particular depends on the `$operation` qualifier.
* Operations that PhpValkeyGlide supports are: RESETSTAT, REWRITE, GET, and SET.
*
* @param string $operation The CONFIG operation to execute (e.g. GET, SET, REWRITE).
* @param array|string|null $key_or_settings One or more keys or values.
* @param string $value The value if this is a `CONFIG SET` operation.
* @see https://valkey.io/commands/config
*
* @example
* $valkey_glide->config('GET', 'timeout');
* $valkey_glide->config('GET', ['timeout', 'databases']);
* $valkey_glide->config('SET', 'timeout', 30);
* $valkey_glide->config('SET', ['timeout' => 30, 'loglevel' => 'warning']);
*/
public function config(string $operation, array|string|null $key_or_settings = null, ?string $value = null): mixed;
/**
* Make a copy of a key.
*
* $valkey_glide = new ValkeyGlide(['host' => 'localhost']);
*
* @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.
* <code>
* $options = [
* ValkeyGlide::COPY_REPLACE => true|false # Whether to replace an existing key.
* ValkeyGlide::COPY_DB => int # Copy key to specific database.
* ];
* // Or using string keys:
* $options = [
* 'REPLACE' => true|false # Whether to replace an existing key.
* 'DB' => int # Copy key to specific database.
* ];
* </code>
*
* @return ValkeyGlide|bool True if the copy was completed and false if not.
*
* @see https://valkey.io/commands/copy
*
* @example
* $valkey_glide->pipeline()
* ->select(1)
* ->del('newkey')
* ->select(0)
* ->del('newkey')
* ->mset(['source1' => 'value1', 'exists' => 'old_value'])
* ->exec();
*
* var_dump($valkey_glide->copy('source1', 'newkey'));
* var_dump($valkey_glide->copy('source1', 'newkey', [ValkeyGlide::COPY_DB => 1]));
* var_dump($valkey_glide->copy('source1', 'exists'));
* var_dump($valkey_glide->copy('source1', 'exists', [ValkeyGlide::COPY_REPLACE => true]));
*/
public function copy(string $src, string $dst, ?array $options = null): ValkeyGlide|bool;
/**
* Return the number of keys in the currently selected ValkeyGlide database.
*
* @see https://valkey.io/commands/dbsize
*
* @return ValkeyGlide|int The number of keys or false on failure.
*
* @example
* $valkey_glide = new ValkeyGlide(['host' => 'localhost']);
* $valkey_glide->flushdb();
* $valkey_glide->set('foo', 'bar');
* var_dump($valkey_glide->dbsize());
* $valkey_glide->mset(['a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd']);
* var_dump($valkey_glide->dbsize());
*/
public function dbSize(): ValkeyGlide|int|false;
/**
* Decrement a ValkeyGlide integer by 1 or a provided value.
*
* @param string $key The key to decrement
* @param int $by How much to decrement the key. Note that if this value is
* not sent or is set to `1`, PhpValkeyGlide will actually invoke
* the 'DECR' command. If it is any value other than `1`
* PhpValkeyGlide will actually send the `DECRBY` command.
*
* @return ValkeyGlide|int|false The new value of the key or false on failure.
*
* @see https://valkey.io/commands/decr
* @see https://valkey.io/commands/decrby
*
* @example $valkey_glide->decr('counter');
* @example $valkey_glide->decr('counter', 2);
*/
public function decr(string $key, int $by = 1): ValkeyGlide|int|false;
/**
* Decrement a valkey integer by a value
*
* @param string $key The integer key to decrement.
* @param int $value How much to decrement the key.
*
* @return ValkeyGlide|int|false The new value of the key or false on failure.
*
* @see https://valkey.io/commands/decrby
*
* @example $valkey_glide->decrby('counter', 1);
* @example $valkey_glide->decrby('counter', 2);
*/
public function decrBy(string $key, int $value): ValkeyGlide|int|false;
/**
* Delete one or more keys from ValkeyGlide.
*
* This method can be called in two distinct ways. The first is to pass a single array
* of keys to delete, and the second is to pass N arguments, all names of keys. See
* below for an example of both strategies.
*
* @param array|string $key_or_keys Either an array with one or more key names or a string with
* the name of a key.
* @param string $other_keys One or more additional keys passed in a variadic fashion.
*
* @return ValkeyGlide|int|false The number of keys that were deleted
*
* @see https://valkey.io/commands/del
*
* @example $valkey_glide->del('key:0', 'key:1');
* @example $valkey_glide->del(['key:2', 'key:3', 'key:4']);
*/
public function del(array|string $key, string ...$other_keys): ValkeyGlide|int|false;
/**
* Discard a transaction currently in progress.
*
* @return ValkeyGlide|bool True if we could discard the transaction.
*
* @example
* $valkey_glide->set('foo', 'bar');
* $valkey_glide->discard();
*/
public function discard(): ValkeyGlide|bool;
/**
* Dump ValkeyGlide' internal binary representation of a key.
*
* <code>
* $valkey_glide->zRange('new-zset', 0, -1, true);
* </code>
*
* @param string $key The key to dump.
*
* @return ValkeyGlide|string A binary string representing the key's value.
*
* @see https://valkey.io/commands/dump
*
* @example
* $valkey_glide->zadd('zset', 0, 'zero', 1, 'one', 2, 'two');
* $binary = $valkey_glide->dump('zset');
* $valkey_glide->restore('new-zset', 0, $binary);
*/
public function dump(string $key): ValkeyGlide|string|false;
/**
* Have ValkeyGlide repeat back an arbitrary string to the client.
*
* @param string $str The string to echo
*
* @return ValkeyGlide|string|false The string sent to ValkeyGlide or false on failure.
*
* @see https://valkey.io/commands/echo
*
* @example $valkey_glide->echo('Hello, World');
*/
public function echo(string $str): ValkeyGlide|string|false;
/**
* Execute a LUA script on the valkey server.
*
* @see https://valkey.io/commands/eval/
*
* @param string $script A string containing the LUA script
* @param array $args An array of arguments to pass to this script
* @param int $num_keys How many of the arguments are keys. This is needed
* as valkey distinguishes between key name arguments
* and other data.
*
* @return mixed LUA scripts may return arbitrary data so this method can return
* strings, arrays, nested arrays, etc.
*/
/*TODO public function eval(string $script, array $args = [], int $num_keys = 0): mixed;*/
/**
* This is simply the read-only variant of eval, meaning the underlying script
* may not modify data in valkey.
*
* @see ValkeyGlide::eval_ro()
*/
/* TODO public function eval_ro(string $script_sha, array $args = [], int $num_keys = 0): mixed; */
/**
* Execute a LUA script on the server but instead of sending the script, send
* the SHA1 hash of the script.
*
* @param string $script_sha The SHA1 hash of the lua code. Note that the script
* must already exist on the server, either having been
* loaded with `SCRIPT LOAD` or having been executed directly
* with `EVAL` first.
* @param array $args Arguments to send to the script.
* @param int $num_keys The number of arguments that are keys
*
* @return mixed Returns whatever the specific script does.
*
* @see https://valkey.io/commands/evalsha/
* @see ValkeyGlide::eval();
*
*/
/* TODO public function evalsha(string $sha1, array $args = [], int $num_keys = 0): mixed; */
/**
* This is simply the read-only variant of evalsha, meaning the underlying script
* may not modify data in valkey.
*
* @see ValkeyGlide::evalsha()
*/
/* TODO public function evalsha_ro(string $sha1, array $args = [], int $num_keys = 0): mixed; */
/**
* Execute either a MULTI or PIPELINE block and return the array of replies.
*
* @return ValkeyGlide|array|false The array of pipeline'd or multi replies or false on failure.
*
* @see https://valkey.io/commands/exec
* @see https://valkey.io/commands/multi
* @see ValkeyGlide::pipeline()
* @see ValkeyGlide::multi()
*
* @example
* $res = $valkey_glide->multi()
* ->set('foo', 'bar')
* ->get('foo')
* ->del('list')
* ->rpush('list', 'one', 'two', 'three')
* ->exec();
*/
public function exec(): ValkeyGlide|array|false;
/**
* Test if one or more keys exist.
*
* @param mixed $key Either an array of keys or a string key
* @param mixed $other_keys If the previous argument was a string, you may send any number of
* additional keys to test.
*
* @return ValkeyGlide|int|bool The number of keys that do exist and false on failure
*
* @see https://valkey.io/commands/exists
*
* @example $valkey_glide->exists(['k1', 'k2', 'k3']);
* @example $valkey_glide->exists('k4', 'k5', 'notakey');
*/
public function exists(mixed $key, mixed ...$other_keys): ValkeyGlide|int|bool;
/**
* Sets an expiration in seconds on the key in question. If connected to
* valkey-server >= 7.0.0 you may send an additional "mode" argument which
* modifies how the command will execute.
*
* @param string $key The key to set an expiration on.
* @param int $timeout The number of seconds after which key will be automatically deleted.
* @param string|null $mode A two character modifier that changes how the
* command works.
* <code>
* NX - Set expiry only if key has no expiry
* XX - Set expiry only if key has an expiry
* LT - Set expiry only when new expiry is < current expiry
* GT - Set expiry only when new expiry is > current expiry
* </code>
*
* @return ValkeyGlide|bool True if an expiration was set and false otherwise.
* @see https://valkey.io/commands/expire
*
*/
public function expire(string $key, int $timeout, ?string $mode = null): ValkeyGlide|bool;
/*
* Set a key's expiration to a specific Unix timestamp in seconds.
*
* If connected to ValkeyGlide >= 7.0.0 you can pass an optional 'mode' argument.
* @see ValkeyGlide::expire() For a description of the mode argument.
*
* @param string $key The key to set an expiration on.
*
* @return ValkeyGlide|bool True if an expiration was set, false if not.
*
*/
/**
* Set a key to expire at an exact unix timestamp.
*
* @param string $key The key to set an expiration on.
* @param int $timestamp The unix timestamp to expire at.
* @param string|null $mode An option 'mode' that modifies how the command acts (see {@link ValkeyGlide::expire}).
* @return ValkeyGlide|bool True if an expiration was set, false if not.
*
* @see https://valkey.io/commands/expireat
* @see https://valkey.io/commands/expire
* @see ValkeyGlide::expire()
*/
public function expireAt(string $key, int $timestamp, ?string $mode = null): ValkeyGlide|bool;
/**
* Get the expiration of a given key as a unix timestamp
*
* @param string $key The key to check.
*
* @return ValkeyGlide|int|false The timestamp when the key expires, or -1 if the key has no expiry
* and -2 if the key doesn't exist.
*
* @see https://valkey.io/commands/expiretime
*
* @example
* $valkey_glide->setEx('mykey', 60, 'myval');
* $valkey_glide->expiretime('mykey');
*/
public function expiretime(string $key): ValkeyGlide|int|false;
/**
* Get the expiration timestamp of a given ValkeyGlide key but in milliseconds.
*
* @see https://valkey.io/commands/pexpiretime
* @see ValkeyGlide::expiretime()
*
* @param string $key The key to check
*
* @return ValkeyGlide|int|false The expiration timestamp of this key (in milliseconds) or -1 if the
* key has no expiration, and -2 if it does not exist.
*/
public function pexpiretime(string $key): ValkeyGlide|int|false;
/**
* Invoke a function.
*
* @param string $fn The name of the function
* @param array $keys Optional list of keys
* @param array $args Optional list of args
*
* @return mixed Function may return arbitrary data so this method can return
* strings, arrays, nested arrays, etc.
*
* @see https://valkey.io/commands/fcall
*/
public function fcall(string $fn, array $keys = [], array $args = []): mixed;
/**
* This is a read-only variant of the FCALL command that cannot execute commands that modify data.
*
* @param string $fn The name of the function
* @param array $keys Optional list of keys
* @param array $args Optional list of args
*
* @return mixed Function may return arbitrary data so this method can return
* strings, arrays, nested arrays, etc.
*
* @see https://valkey.io/commands/fcall_ro
*/
public function fcall_ro(string $fn, array $keys = [], array $args = []): mixed;
/**
* Deletes every key in all ValkeyGlide databases
*
* @param bool $sync Whether to perform the task in a blocking or non-blocking way.
* @return bool
*
* @see https://valkey.io/commands/flushall
*/
public function flushAll(?bool $sync = null): ValkeyGlide|bool;
/**
* Deletes all the keys of the currently selected database.
*
* @param bool $sync Whether to perform the task in a blocking or non-blocking way.
* @return bool
*
* @see https://valkey.io/commands/flushdb
*/
public function flushDB(?bool $sync = null): ValkeyGlide|bool;
/**
* Functions is an API for managing code to be executed on the server.
*
* @param string $operation The subcommand you intend to execute. Valid options are as follows
* 'LOAD' - Create a new library with the given library name and code.
* 'DELETE' - Delete the given library.
* 'LIST' - Return general information on all the libraries
* 'STATS' - Return information about the current function running
* 'KILL' - Kill the current running function
* 'FLUSH' - Delete all the libraries
* 'DUMP' - Return a serialized payload representing the current libraries
* 'RESTORE' - Restore the libraries represented by the given payload
* @param member $args Additional arguments
*
* @return ValkeyGlide|bool|string|array Depends on subcommand.
*
* @see https://valkey.io/commands/function
*/
public function function(string $operation, mixed ...$args): ValkeyGlide|bool|string|array;
/**
* Add one or more members to a geospacial sorted set
*
* @param string $key The sorted set to add data to.
* @param float $lng The longitude of the first member
* @param float $lat The latitude of the first member.
* @param member $other_triples_and_options You can continue to pass longitude, latitude, and member
* arguments to add as many members as you wish. Optionally, the final argument may be
* a string with options for the command @see ValkeyGlide documentation for the options.
*
* @return ValkeyGlide|int|false The number of added elements is returned. If the 'CH' option is specified,
* the return value is the number of members *changed*.
*
* @example $valkey_glide->geoAdd('cities', -121.8374, 39.7284, 'Chico', -122.03218, 37.322, 'Cupertino');
* @example $valkey_glide->geoadd('cities', -121.837478, 39.728494, 'Chico', ['XX', 'CH']);
*
* @see https://valkey.io/commands/geoadd
*/