-
Notifications
You must be signed in to change notification settings - Fork 10
/
adapter.go
5593 lines (4974 loc) · 212 KB
/
adapter.go
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
// Copyright (c) 2013 The github.com/go-redis/redis Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * 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.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS 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 COPYRIGHT
// OWNER OR 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.
package valkeycompat
import (
"context"
"encoding"
"fmt"
"reflect"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/valkey-io/valkey-go"
"github.com/valkey-io/valkey-go/internal/cmds"
"github.com/valkey-io/valkey-go/internal/util"
)
const (
KeepTTL = -1
BitCountIndexByte = "BYTE"
BitCountIndexBit = "BIT"
)
var Nil = valkey.Nil
type Cmdable interface {
CoreCmdable
Cache(ttl time.Duration) CacheCompat
Subscribe(ctx context.Context, channels ...string) PubSub
PSubscribe(ctx context.Context, patterns ...string) PubSub
SSubscribe(ctx context.Context, channels ...string) PubSub
Watch(ctx context.Context, fn func(Tx) error, keys ...string) error
}
type CoreCmdable interface {
Command(ctx context.Context) *CommandsInfoCmd
CommandList(ctx context.Context, filter FilterBy) *StringSliceCmd
CommandGetKeys(ctx context.Context, commands ...any) *StringSliceCmd
CommandGetKeysAndFlags(ctx context.Context, commands ...any) *KeyFlagsCmd
ClientGetName(ctx context.Context) *StringCmd
Echo(ctx context.Context, message any) *StringCmd
Ping(ctx context.Context) *StatusCmd
Quit(ctx context.Context) *StatusCmd
Del(ctx context.Context, keys ...string) *IntCmd
Unlink(ctx context.Context, keys ...string) *IntCmd
Dump(ctx context.Context, key string) *StringCmd
Exists(ctx context.Context, keys ...string) *IntCmd
Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
ExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
ExpireTime(ctx context.Context, key string) *DurationCmd
ExpireNX(ctx context.Context, key string, expiration time.Duration) *BoolCmd
ExpireXX(ctx context.Context, key string, expiration time.Duration) *BoolCmd
ExpireGT(ctx context.Context, key string, expiration time.Duration) *BoolCmd
ExpireLT(ctx context.Context, key string, expiration time.Duration) *BoolCmd
Keys(ctx context.Context, pattern string) *StringSliceCmd
Migrate(ctx context.Context, host string, port int64, key string, db int64, timeout time.Duration) *StatusCmd
Move(ctx context.Context, key string, db int64) *BoolCmd
ObjectRefCount(ctx context.Context, key string) *IntCmd
ObjectEncoding(ctx context.Context, key string) *StringCmd
ObjectIdleTime(ctx context.Context, key string) *DurationCmd
Persist(ctx context.Context, key string) *BoolCmd
PExpire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
PExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
PExpireTime(ctx context.Context, key string) *DurationCmd
PTTL(ctx context.Context, key string) *DurationCmd
RandomKey(ctx context.Context) *StringCmd
Rename(ctx context.Context, key, newkey string) *StatusCmd
RenameNX(ctx context.Context, key, newkey string) *BoolCmd
Restore(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
Sort(ctx context.Context, key string, sort Sort) *StringSliceCmd
SortRO(ctx context.Context, key string, sort Sort) *StringSliceCmd
SortStore(ctx context.Context, key, store string, sort Sort) *IntCmd
SortInterfaces(ctx context.Context, key string, sort Sort) *SliceCmd
Touch(ctx context.Context, keys ...string) *IntCmd
TTL(ctx context.Context, key string) *DurationCmd
Type(ctx context.Context, key string) *StatusCmd
Append(ctx context.Context, key, value string) *IntCmd
Decr(ctx context.Context, key string) *IntCmd
DecrBy(ctx context.Context, key string, decrement int64) *IntCmd
Get(ctx context.Context, key string) *StringCmd
GetRange(ctx context.Context, key string, start, end int64) *StringCmd
GetSet(ctx context.Context, key string, value any) *StringCmd
GetEx(ctx context.Context, key string, expiration time.Duration) *StringCmd
GetDel(ctx context.Context, key string) *StringCmd
Incr(ctx context.Context, key string) *IntCmd
IncrBy(ctx context.Context, key string, value int64) *IntCmd
IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd
MGet(ctx context.Context, keys ...string) *SliceCmd
MSet(ctx context.Context, values ...any) *StatusCmd
MSetNX(ctx context.Context, values ...any) *BoolCmd
Set(ctx context.Context, key string, value any, expiration time.Duration) *StatusCmd
SetArgs(ctx context.Context, key string, value any, a SetArgs) *StatusCmd
SetEX(ctx context.Context, key string, value any, expiration time.Duration) *StatusCmd
SetNX(ctx context.Context, key string, value any, expiration time.Duration) *BoolCmd
SetXX(ctx context.Context, key string, value any, expiration time.Duration) *BoolCmd
SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd
StrLen(ctx context.Context, key string) *IntCmd
Copy(ctx context.Context, sourceKey string, destKey string, db int64, replace bool) *IntCmd
GetBit(ctx context.Context, key string, offset int64) *IntCmd
SetBit(ctx context.Context, key string, offset int64, value int64) *IntCmd
BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd
BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd
BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd
BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd
BitOpNot(ctx context.Context, destKey string, key string) *IntCmd
BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd
BitPosSpan(ctx context.Context, key string, bit int64, start, end int64, span string) *IntCmd
BitField(ctx context.Context, key string, args ...any) *IntSliceCmd
// TODO BitFieldRO(ctx context.Context, key string, values ...interface{}) *IntSliceCmd
Scan(ctx context.Context, cursor uint64, match string, count int64) *ScanCmd
ScanType(ctx context.Context, cursor uint64, match string, count int64, keyType string) *ScanCmd
SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
// TODO HScanNoValues(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
HDel(ctx context.Context, key string, fields ...string) *IntCmd
HExists(ctx context.Context, key, field string) *BoolCmd
HGet(ctx context.Context, key, field string) *StringCmd
HGetAll(ctx context.Context, key string) *StringStringMapCmd
HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
HKeys(ctx context.Context, key string) *StringSliceCmd
HLen(ctx context.Context, key string) *IntCmd
HMGet(ctx context.Context, key string, fields ...string) *SliceCmd
HSet(ctx context.Context, key string, values ...any) *IntCmd
HMSet(ctx context.Context, key string, values ...any) *BoolCmd
HSetNX(ctx context.Context, key, field string, value any) *BoolCmd
HVals(ctx context.Context, key string) *StringSliceCmd
HRandField(ctx context.Context, key string, count int64) *StringSliceCmd
HRandFieldWithValues(ctx context.Context, key string, count int64) *KeyValueSliceCmd
HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
HPExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
HPExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
HExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd
HExpireAtWithArgs(ctx context.Context, key string, tm time.Time, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
HPExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd
HPExpireAtWithArgs(ctx context.Context, key string, tm time.Time, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
HPersist(ctx context.Context, key string, fields ...string) *IntSliceCmd
HExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd
HPExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd
HTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd
HPTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd
BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
BLMPop(ctx context.Context, timeout time.Duration, direction string, count int64, keys ...string) *KeyValuesCmd
BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd
// TODO LCS(ctx context.Context, q *LCSQuery) *LCSCmd
LIndex(ctx context.Context, key string, index int64) *StringCmd
LInsert(ctx context.Context, key, op string, pivot, value any) *IntCmd
LInsertBefore(ctx context.Context, key string, pivot, value any) *IntCmd
LInsertAfter(ctx context.Context, key string, pivot, value any) *IntCmd
LLen(ctx context.Context, key string) *IntCmd
LMPop(ctx context.Context, direction string, count int64, keys ...string) *KeyValuesCmd
LPop(ctx context.Context, key string) *StringCmd
LPopCount(ctx context.Context, key string, count int64) *StringSliceCmd
LPos(ctx context.Context, key string, value string, args LPosArgs) *IntCmd
LPosCount(ctx context.Context, key string, value string, count int64, args LPosArgs) *IntSliceCmd
LPush(ctx context.Context, key string, values ...any) *IntCmd
LPushX(ctx context.Context, key string, values ...any) *IntCmd
LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
LRem(ctx context.Context, key string, count int64, value any) *IntCmd
LSet(ctx context.Context, key string, index int64, value any) *StatusCmd
LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd
RPop(ctx context.Context, key string) *StringCmd
RPopCount(ctx context.Context, key string, count int64) *StringSliceCmd
RPopLPush(ctx context.Context, source, destination string) *StringCmd
RPush(ctx context.Context, key string, values ...any) *IntCmd
RPushX(ctx context.Context, key string, values ...any) *IntCmd
LMove(ctx context.Context, source, destination, srcpos, destpos string) *StringCmd
BLMove(ctx context.Context, source, destination, srcpos, destpos string, timeout time.Duration) *StringCmd
SAdd(ctx context.Context, key string, members ...any) *IntCmd
SCard(ctx context.Context, key string) *IntCmd
SDiff(ctx context.Context, keys ...string) *StringSliceCmd
SDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd
SInter(ctx context.Context, keys ...string) *StringSliceCmd
SInterCard(ctx context.Context, limit int64, keys ...string) *IntCmd
SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd
SIsMember(ctx context.Context, key string, member any) *BoolCmd
SMIsMember(ctx context.Context, key string, members ...any) *BoolSliceCmd
SMembers(ctx context.Context, key string) *StringSliceCmd
SMembersMap(ctx context.Context, key string) *StringStructMapCmd
SMove(ctx context.Context, source, destination string, member any) *BoolCmd
SPop(ctx context.Context, key string) *StringCmd
SPopN(ctx context.Context, key string, count int64) *StringSliceCmd
SRandMember(ctx context.Context, key string) *StringCmd
SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd
SRem(ctx context.Context, key string, members ...any) *IntCmd
SUnion(ctx context.Context, keys ...string) *StringSliceCmd
SUnionStore(ctx context.Context, destination string, keys ...string) *IntCmd
XAdd(ctx context.Context, a XAddArgs) *StringCmd
XDel(ctx context.Context, stream string, ids ...string) *IntCmd
XLen(ctx context.Context, stream string) *IntCmd
XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd
XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd
XRevRange(ctx context.Context, stream string, start, stop string) *XMessageSliceCmd
XRevRangeN(ctx context.Context, stream string, start, stop string, count int64) *XMessageSliceCmd
XRead(ctx context.Context, a XReadArgs) *XStreamSliceCmd
XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd
XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd
XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd
XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd
XGroupDestroy(ctx context.Context, stream, group string) *IntCmd
XGroupCreateConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
XReadGroup(ctx context.Context, a XReadGroupArgs) *XStreamSliceCmd
XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd
XPending(ctx context.Context, stream, group string) *XPendingCmd
XPendingExt(ctx context.Context, a XPendingExtArgs) *XPendingExtCmd
XClaim(ctx context.Context, a XClaimArgs) *XMessageSliceCmd
XClaimJustID(ctx context.Context, a XClaimArgs) *StringSliceCmd
XAutoClaim(ctx context.Context, a XAutoClaimArgs) *XAutoClaimCmd
XAutoClaimJustID(ctx context.Context, a XAutoClaimArgs) *XAutoClaimJustIDCmd
XTrimMaxLen(ctx context.Context, key string, maxLen int64) *IntCmd
XTrimMaxLenApprox(ctx context.Context, key string, maxLen, limit int64) *IntCmd
XTrimMinID(ctx context.Context, key string, minID string) *IntCmd
XTrimMinIDApprox(ctx context.Context, key string, minID string, limit int64) *IntCmd
XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd
XInfoStream(ctx context.Context, key string) *XInfoStreamCmd
XInfoStreamFull(ctx context.Context, key string, count int64) *XInfoStreamFullCmd
XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd
BZPopMax(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd
BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd
BZMPop(ctx context.Context, timeout time.Duration, order string, count int64, keys ...string) *ZSliceWithKeyCmd
ZAdd(ctx context.Context, key string, members ...Z) *IntCmd
ZAddLT(ctx context.Context, key string, members ...Z) *IntCmd
ZAddGT(ctx context.Context, key string, members ...Z) *IntCmd
ZAddNX(ctx context.Context, key string, members ...Z) *IntCmd
ZAddXX(ctx context.Context, key string, members ...Z) *IntCmd
ZAddArgs(ctx context.Context, key string, args ZAddArgs) *IntCmd
ZAddArgsIncr(ctx context.Context, key string, args ZAddArgs) *FloatCmd
ZCard(ctx context.Context, key string) *IntCmd
ZCount(ctx context.Context, key, min, max string) *IntCmd
ZLexCount(ctx context.Context, key, min, max string) *IntCmd
ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd
ZInter(ctx context.Context, store ZStore) *StringSliceCmd
ZInterWithScores(ctx context.Context, store ZStore) *ZSliceCmd
ZInterCard(ctx context.Context, limit int64, keys ...string) *IntCmd
ZInterStore(ctx context.Context, destination string, store ZStore) *IntCmd
ZMPop(ctx context.Context, order string, count int64, keys ...string) *ZSliceWithKeyCmd
ZMScore(ctx context.Context, key string, members ...string) *FloatSliceCmd
ZPopMax(ctx context.Context, key string, count ...int64) *ZSliceCmd
ZPopMin(ctx context.Context, key string, count ...int64) *ZSliceCmd
ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd
ZRangeByScore(ctx context.Context, key string, opt ZRangeBy) *StringSliceCmd
ZRangeByLex(ctx context.Context, key string, opt ZRangeBy) *StringSliceCmd
ZRangeByScoreWithScores(ctx context.Context, key string, opt ZRangeBy) *ZSliceCmd
ZRangeArgs(ctx context.Context, z ZRangeArgs) *StringSliceCmd
ZRangeArgsWithScores(ctx context.Context, z ZRangeArgs) *ZSliceCmd
ZRangeStore(ctx context.Context, dst string, z ZRangeArgs) *IntCmd
ZRank(ctx context.Context, key, member string) *IntCmd
ZRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd
ZRem(ctx context.Context, key string, members ...any) *IntCmd
ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd
ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd
ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd
ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd
ZRevRangeByScore(ctx context.Context, key string, opt ZRangeBy) *StringSliceCmd
ZRevRangeByLex(ctx context.Context, key string, opt ZRangeBy) *StringSliceCmd
ZRevRangeByScoreWithScores(ctx context.Context, key string, opt ZRangeBy) *ZSliceCmd
ZRevRank(ctx context.Context, key, member string) *IntCmd
ZRevRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd
ZScore(ctx context.Context, key, member string) *FloatCmd
ZUnionStore(ctx context.Context, dest string, store ZStore) *IntCmd
ZRandMember(ctx context.Context, key string, count int64) *StringSliceCmd
ZRandMemberWithScores(ctx context.Context, key string, count int64) *ZSliceCmd
ZUnion(ctx context.Context, store ZStore) *StringSliceCmd
ZUnionWithScores(ctx context.Context, store ZStore) *ZSliceCmd
ZDiff(ctx context.Context, keys ...string) *StringSliceCmd
ZDiffWithScores(ctx context.Context, keys ...string) *ZSliceCmd
ZDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd
PFAdd(ctx context.Context, key string, els ...any) *IntCmd
PFCount(ctx context.Context, keys ...string) *IntCmd
PFMerge(ctx context.Context, dest string, keys ...string) *StatusCmd
BgRewriteAOF(ctx context.Context) *StatusCmd
BgSave(ctx context.Context) *StatusCmd
ClientKill(ctx context.Context, ipPort string) *StatusCmd
ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd
ClientList(ctx context.Context) *StringCmd
// TODO ClientInfo(ctx context.Context) *ClientInfoCmd
ClientPause(ctx context.Context, dur time.Duration) *BoolCmd
ClientUnpause(ctx context.Context) *BoolCmd
ClientID(ctx context.Context) *IntCmd
ClientUnblock(ctx context.Context, id int64) *IntCmd
ClientUnblockWithError(ctx context.Context, id int64) *IntCmd
ConfigGet(ctx context.Context, parameter string) *StringStringMapCmd
ConfigResetStat(ctx context.Context) *StatusCmd
ConfigSet(ctx context.Context, parameter, value string) *StatusCmd
ConfigRewrite(ctx context.Context) *StatusCmd
DBSize(ctx context.Context) *IntCmd
FlushAll(ctx context.Context) *StatusCmd
FlushAllAsync(ctx context.Context) *StatusCmd
FlushDB(ctx context.Context) *StatusCmd
FlushDBAsync(ctx context.Context) *StatusCmd
Info(ctx context.Context, section ...string) *StringCmd
LastSave(ctx context.Context) *IntCmd
Save(ctx context.Context) *StatusCmd
Shutdown(ctx context.Context) *StatusCmd
ShutdownSave(ctx context.Context) *StatusCmd
ShutdownNoSave(ctx context.Context) *StatusCmd
// TODO SlaveOf(ctx context.Context, host, port string) *StatusCmd
// TODO SlowLogGet(ctx context.Context, num int64) *SlowLogCmd
Time(ctx context.Context) *TimeCmd
DebugObject(ctx context.Context, key string) *StringCmd
ReadOnly(ctx context.Context) *StatusCmd
ReadWrite(ctx context.Context) *StatusCmd
MemoryUsage(ctx context.Context, key string, samples ...int64) *IntCmd
Eval(ctx context.Context, script string, keys []string, args ...any) *Cmd
EvalSha(ctx context.Context, sha1 string, keys []string, args ...any) *Cmd
EvalRO(ctx context.Context, script string, keys []string, args ...any) *Cmd
EvalShaRO(ctx context.Context, sha1 string, keys []string, args ...any) *Cmd
ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd
ScriptFlush(ctx context.Context) *StatusCmd
ScriptKill(ctx context.Context) *StatusCmd
ScriptLoad(ctx context.Context, script string) *StringCmd
FunctionLoad(ctx context.Context, code string) *StringCmd
FunctionLoadReplace(ctx context.Context, code string) *StringCmd
FunctionDelete(ctx context.Context, libName string) *StringCmd
FunctionFlush(ctx context.Context) *StringCmd
FunctionKill(ctx context.Context) *StringCmd
FunctionFlushAsync(ctx context.Context) *StringCmd
FunctionList(ctx context.Context, q FunctionListQuery) *FunctionListCmd
FunctionDump(ctx context.Context) *StringCmd
FunctionRestore(ctx context.Context, libDump string) *StringCmd
// TODO FunctionStats(ctx context.Context) *FunctionStatsCmd
FCall(ctx context.Context, function string, keys []string, args ...any) *Cmd
FCallRO(ctx context.Context, function string, keys []string, args ...any) *Cmd
Publish(ctx context.Context, channel string, message any) *IntCmd
SPublish(ctx context.Context, channel string, message any) *IntCmd
PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd
PubSubNumSub(ctx context.Context, channels ...string) *StringIntMapCmd
PubSubNumPat(ctx context.Context) *IntCmd
PubSubShardChannels(ctx context.Context, pattern string) *StringSliceCmd
PubSubShardNumSub(ctx context.Context, channels ...string) *StringIntMapCmd
// TODO ClusterMyShardID(ctx context.Context) *StringCmd
ClusterSlots(ctx context.Context) *ClusterSlotsCmd
ClusterShards(ctx context.Context) *ClusterShardsCmd
// TODO ClusterLinks(ctx context.Context) *ClusterLinksCmd
ClusterNodes(ctx context.Context) *StringCmd
ClusterMeet(ctx context.Context, host string, port int64) *StatusCmd
ClusterForget(ctx context.Context, nodeID string) *StatusCmd
ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd
ClusterResetSoft(ctx context.Context) *StatusCmd
ClusterResetHard(ctx context.Context) *StatusCmd
ClusterInfo(ctx context.Context) *StringCmd
ClusterKeySlot(ctx context.Context, key string) *IntCmd
ClusterGetKeysInSlot(ctx context.Context, slot int64, count int64) *StringSliceCmd
ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd
ClusterCountKeysInSlot(ctx context.Context, slot int64) *IntCmd
ClusterDelSlots(ctx context.Context, slots ...int64) *StatusCmd
ClusterDelSlotsRange(ctx context.Context, min, max int64) *StatusCmd
ClusterSaveConfig(ctx context.Context) *StatusCmd
ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd
ClusterFailover(ctx context.Context) *StatusCmd
ClusterAddSlots(ctx context.Context, slots ...int64) *StatusCmd
ClusterAddSlotsRange(ctx context.Context, min, max int64) *StatusCmd
// TODO ReadOnly(ctx context.Context) *StatusCmd
// TODO ReadWrite(ctx context.Context) *StatusCmd
GeoAdd(ctx context.Context, key string, geoLocation ...GeoLocation) *IntCmd
GeoPos(ctx context.Context, key string, members ...string) *GeoPosCmd
GeoRadius(ctx context.Context, key string, longitude, latitude float64, query GeoRadiusQuery) *GeoLocationCmd
GeoRadiusStore(ctx context.Context, key string, longitude, latitude float64, query GeoRadiusQuery) *IntCmd
GeoRadiusByMember(ctx context.Context, key, member string, query GeoRadiusQuery) *GeoLocationCmd
GeoRadiusByMemberStore(ctx context.Context, key, member string, query GeoRadiusQuery) *IntCmd
GeoSearch(ctx context.Context, key string, q GeoSearchQuery) *StringSliceCmd
GeoSearchLocation(ctx context.Context, key string, q GeoSearchLocationQuery) *GeoLocationCmd
GeoSearchStore(ctx context.Context, key, store string, q GeoSearchStoreQuery) *IntCmd
GeoDist(ctx context.Context, key string, member1, member2, unit string) *FloatCmd
GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd
ACLDryRun(ctx context.Context, username string, command ...any) *StringCmd
// TODO ACLLog(ctx context.Context, count int64) *ACLLogCmd
// TODO ACLLogReset(ctx context.Context) *StatusCmd
// TODO ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd
GearsCmdable
ProbabilisticCmdable
TimeseriesCmdable
JSONCmdable
// TODO SearchCmdable
}
// TODO SearchCmdable
//type SearchCmdable interface {
// FT_List(ctx context.Context) *StringSliceCmd
// FTAggregate(ctx context.Context, index string, query string) *MapStringInterfaceCmd
// FTAggregateWithArgs(ctx context.Context, index string, query string, options *FTAggregateOptions) *AggregateCmd
// FTAliasAdd(ctx context.Context, index string, alias string) *StatusCmd
// FTAliasDel(ctx context.Context, alias string) *StatusCmd
// FTAliasUpdate(ctx context.Context, index string, alias string) *StatusCmd
// FTAlter(ctx context.Context, index string, skipInitalScan bool, definition []interface{}) *StatusCmd
// FTConfigGet(ctx context.Context, option string) *MapMapStringInterfaceCmd
// FTConfigSet(ctx context.Context, option string, value interface{}) *StatusCmd
// FTCreate(ctx context.Context, index string, options *FTCreateOptions, schema ...*FieldSchema) *StatusCmd
// FTCursorDel(ctx context.Context, index string, cursorId int) *StatusCmd
// FTCursorRead(ctx context.Context, index string, cursorId int, count int) *MapStringInterfaceCmd
// FTDictAdd(ctx context.Context, dict string, term ...interface{}) *IntCmd
// FTDictDel(ctx context.Context, dict string, term ...interface{}) *IntCmd
// FTDictDump(ctx context.Context, dict string) *StringSliceCmd
// FTDropIndex(ctx context.Context, index string) *StatusCmd
// FTDropIndexWithArgs(ctx context.Context, index string, options *FTDropIndexOptions) *StatusCmd
// FTExplain(ctx context.Context, index string, query string) *StringCmd
// FTExplainWithArgs(ctx context.Context, index string, query string, options *FTExplainOptions) *StringCmd
// FTInfo(ctx context.Context, index string) *FTInfoCmd
// FTSpellCheck(ctx context.Context, index string, query string) *FTSpellCheckCmd
// FTSpellCheckWithArgs(ctx context.Context, index string, query string, options *FTSpellCheckOptions) *FTSpellCheckCmd
// FTSearch(ctx context.Context, index string, query string) *FTSearchCmd
// FTSearchWithArgs(ctx context.Context, index string, query string, options *FTSearchOptions) *FTSearchCmd
// FTSynDump(ctx context.Context, index string) *FTSynDumpCmd
// FTSynUpdate(ctx context.Context, index string, synGroupId interface{}, terms []interface{}) *StatusCmd
// FTSynUpdateWithArgs(ctx context.Context, index string, synGroupId interface{}, options *FTSynUpdateOptions, terms []interface{}) *StatusCmd
// FTTagVals(ctx context.Context, index string, field string) *StringSliceCmd
//}
// https://github.com/redis/go-redis/blob/af4872cbd0de349855ce3f0978929c2f56eb995f/probabilistic.go#L10
type ProbabilisticCmdable interface {
BFAdd(ctx context.Context, key string, element interface{}) *BoolCmd
BFCard(ctx context.Context, key string) *IntCmd
BFExists(ctx context.Context, key string, element interface{}) *BoolCmd
BFInfo(ctx context.Context, key string) *BFInfoCmd
BFInfoArg(ctx context.Context, key, option string) *BFInfoCmd
BFInfoCapacity(ctx context.Context, key string) *BFInfoCmd
BFInfoSize(ctx context.Context, key string) *BFInfoCmd
BFInfoFilters(ctx context.Context, key string) *BFInfoCmd
BFInfoItems(ctx context.Context, key string) *BFInfoCmd
BFInfoExpansion(ctx context.Context, key string) *BFInfoCmd
BFInsert(ctx context.Context, key string, options *BFInsertOptions, elements ...interface{}) *BoolSliceCmd
BFMAdd(ctx context.Context, key string, elements ...interface{}) *BoolSliceCmd
BFMExists(ctx context.Context, key string, elements ...interface{}) *BoolSliceCmd
BFReserve(ctx context.Context, key string, errorRate float64, capacity int64) *StatusCmd
BFReserveExpansion(ctx context.Context, key string, errorRate float64, capacity, expansion int64) *StatusCmd
BFReserveNonScaling(ctx context.Context, key string, errorRate float64, capacity int64) *StatusCmd
BFReserveWithArgs(ctx context.Context, key string, options *BFReserveOptions) *StatusCmd
BFScanDump(ctx context.Context, key string, iterator int64) *ScanDumpCmd
BFLoadChunk(ctx context.Context, key string, iterator int64, data interface{}) *StatusCmd
CFAdd(ctx context.Context, key string, element interface{}) *BoolCmd
CFAddNX(ctx context.Context, key string, element interface{}) *BoolCmd
CFCount(ctx context.Context, key string, element interface{}) *IntCmd
CFDel(ctx context.Context, key string, element interface{}) *BoolCmd
CFExists(ctx context.Context, key string, element interface{}) *BoolCmd
CFInfo(ctx context.Context, key string) *CFInfoCmd
CFInsert(ctx context.Context, key string, options *CFInsertOptions, elements ...interface{}) *BoolSliceCmd
CFInsertNX(ctx context.Context, key string, options *CFInsertOptions, elements ...interface{}) *IntSliceCmd
CFMExists(ctx context.Context, key string, elements ...interface{}) *BoolSliceCmd
CFReserve(ctx context.Context, key string, capacity int64) *StatusCmd
CFReserveWithArgs(ctx context.Context, key string, options *CFReserveOptions) *StatusCmd
CFReserveExpansion(ctx context.Context, key string, capacity int64, expansion int64) *StatusCmd
CFReserveBucketSize(ctx context.Context, key string, capacity int64, bucketsize int64) *StatusCmd
CFReserveMaxIterations(ctx context.Context, key string, capacity int64, maxiterations int64) *StatusCmd
CFScanDump(ctx context.Context, key string, iterator int64) *ScanDumpCmd
CFLoadChunk(ctx context.Context, key string, iterator int64, data interface{}) *StatusCmd
CMSIncrBy(ctx context.Context, key string, elements ...interface{}) *IntSliceCmd
CMSInfo(ctx context.Context, key string) *CMSInfoCmd
CMSInitByDim(ctx context.Context, key string, width, height int64) *StatusCmd
CMSInitByProb(ctx context.Context, key string, errorRate, probability float64) *StatusCmd
CMSMerge(ctx context.Context, destKey string, sourceKeys ...string) *StatusCmd
CMSMergeWithWeight(ctx context.Context, destKey string, sourceKeys map[string]int64) *StatusCmd
CMSQuery(ctx context.Context, key string, elements ...interface{}) *IntSliceCmd
TopKAdd(ctx context.Context, key string, elements ...interface{}) *StringSliceCmd
TopKCount(ctx context.Context, key string, elements ...interface{}) *IntSliceCmd
TopKIncrBy(ctx context.Context, key string, elements ...interface{}) *StringSliceCmd
TopKInfo(ctx context.Context, key string) *TopKInfoCmd
TopKList(ctx context.Context, key string) *StringSliceCmd
TopKListWithCount(ctx context.Context, key string) *MapStringIntCmd
TopKQuery(ctx context.Context, key string, elements ...interface{}) *BoolSliceCmd
TopKReserve(ctx context.Context, key string, k int64) *StatusCmd
TopKReserveWithOptions(ctx context.Context, key string, k int64, width, depth int64, decay float64) *StatusCmd
TDigestAdd(ctx context.Context, key string, elements ...float64) *StatusCmd
TDigestByRank(ctx context.Context, key string, rank ...uint64) *FloatSliceCmd
TDigestByRevRank(ctx context.Context, key string, rank ...uint64) *FloatSliceCmd
TDigestCDF(ctx context.Context, key string, elements ...float64) *FloatSliceCmd
TDigestCreate(ctx context.Context, key string) *StatusCmd
TDigestCreateWithCompression(ctx context.Context, key string, compression int64) *StatusCmd
TDigestInfo(ctx context.Context, key string) *TDigestInfoCmd
TDigestMax(ctx context.Context, key string) *FloatCmd
TDigestMin(ctx context.Context, key string) *FloatCmd
TDigestMerge(ctx context.Context, destKey string, options *TDigestMergeOptions, sourceKeys ...string) *StatusCmd
TDigestQuantile(ctx context.Context, key string, elements ...float64) *FloatSliceCmd
TDigestRank(ctx context.Context, key string, values ...float64) *IntSliceCmd
TDigestReset(ctx context.Context, key string) *StatusCmd
TDigestRevRank(ctx context.Context, key string, values ...float64) *IntSliceCmd
TDigestTrimmedMean(ctx context.Context, key string, lowCutQuantile, highCutQuantile float64) *FloatCmd
Pipeline() Pipeliner
Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)
TxPipeline() Pipeliner
TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)
}
// Align with go-redis
// https://github.com/redis/go-redis/blob/f994ff1cd96299a5c8029ae3403af7b17ef06e8a/gears_commands.go#L9-L19
type GearsCmdable interface {
TFunctionLoad(ctx context.Context, lib string) *StatusCmd
TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd
TFunctionDelete(ctx context.Context, libName string) *StatusCmd
TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd
TFunctionListArgs(ctx context.Context, options *TFunctionListOptions) *MapStringInterfaceSliceCmd
TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd
TFCallArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd
TFCallASYNC(ctx context.Context, libName string, funcName string, numKeys int) *Cmd
TFCallASYNCArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd
}
type TimeseriesCmdable interface {
TSAdd(ctx context.Context, key string, timestamp interface{}, value float64) *IntCmd
TSAddWithArgs(ctx context.Context, key string, timestamp interface{}, value float64, options *TSOptions) *IntCmd
TSCreate(ctx context.Context, key string) *StatusCmd
TSCreateWithArgs(ctx context.Context, key string, options *TSOptions) *StatusCmd
TSAlter(ctx context.Context, key string, options *TSAlterOptions) *StatusCmd
TSCreateRule(ctx context.Context, sourceKey string, destKey string, aggregator Aggregator, bucketDuration int) *StatusCmd
TSCreateRuleWithArgs(ctx context.Context, sourceKey string, destKey string, aggregator Aggregator, bucketDuration int, options *TSCreateRuleOptions) *StatusCmd
TSIncrBy(ctx context.Context, Key string, timestamp float64) *IntCmd
TSIncrByWithArgs(ctx context.Context, key string, timestamp float64, options *TSIncrDecrOptions) *IntCmd
TSDecrBy(ctx context.Context, Key string, timestamp float64) *IntCmd
TSDecrByWithArgs(ctx context.Context, key string, timestamp float64, options *TSIncrDecrOptions) *IntCmd
TSDel(ctx context.Context, Key string, fromTimestamp int, toTimestamp int) *IntCmd
TSDeleteRule(ctx context.Context, sourceKey string, destKey string) *StatusCmd
TSGet(ctx context.Context, key string) *TSTimestampValueCmd
TSGetWithArgs(ctx context.Context, key string, options *TSGetOptions) *TSTimestampValueCmd
TSInfo(ctx context.Context, key string) *MapStringInterfaceCmd
TSInfoWithArgs(ctx context.Context, key string, options *TSInfoOptions) *MapStringInterfaceCmd
TSMAdd(ctx context.Context, ktvSlices [][]interface{}) *IntSliceCmd
TSQueryIndex(ctx context.Context, filterExpr []string) *StringSliceCmd
TSRevRange(ctx context.Context, key string, fromTimestamp int, toTimestamp int) *TSTimestampValueSliceCmd
TSRevRangeWithArgs(ctx context.Context, key string, fromTimestamp int, toTimestamp int, options *TSRevRangeOptions) *TSTimestampValueSliceCmd
TSRange(ctx context.Context, key string, fromTimestamp int, toTimestamp int) *TSTimestampValueSliceCmd
TSRangeWithArgs(ctx context.Context, key string, fromTimestamp int, toTimestamp int, options *TSRangeOptions) *TSTimestampValueSliceCmd
TSMRange(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string) *MapStringSliceInterfaceCmd
TSMRangeWithArgs(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string, options *TSMRangeOptions) *MapStringSliceInterfaceCmd
TSMRevRange(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string) *MapStringSliceInterfaceCmd
TSMRevRangeWithArgs(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string, options *TSMRevRangeOptions) *MapStringSliceInterfaceCmd
TSMGet(ctx context.Context, filters []string) *MapStringSliceInterfaceCmd
TSMGetWithArgs(ctx context.Context, filters []string, options *TSMGetOptions) *MapStringSliceInterfaceCmd
}
type JSONCmdable interface {
JSONArrAppend(ctx context.Context, key, path string, values ...interface{}) *IntSliceCmd
JSONArrIndex(ctx context.Context, key, path string, value ...interface{}) *IntSliceCmd
JSONArrIndexWithArgs(ctx context.Context, key, path string, options *JSONArrIndexArgs, value ...interface{}) *IntSliceCmd
JSONArrInsert(ctx context.Context, key, path string, index int64, values ...interface{}) *IntSliceCmd
JSONArrLen(ctx context.Context, key, path string) *IntSliceCmd
JSONArrPop(ctx context.Context, key, path string, index int) *StringSliceCmd
JSONArrTrim(ctx context.Context, key, path string) *IntSliceCmd
JSONArrTrimWithArgs(ctx context.Context, key, path string, options *JSONArrTrimArgs) *IntSliceCmd
JSONClear(ctx context.Context, key, path string) *IntCmd
JSONDebugMemory(ctx context.Context, key, path string) *IntCmd
JSONDel(ctx context.Context, key, path string) *IntCmd
JSONForget(ctx context.Context, key, path string) *IntCmd
JSONGet(ctx context.Context, key string, paths ...string) *JSONCmd
JSONGetWithArgs(ctx context.Context, key string, options *JSONGetArgs, paths ...string) *JSONCmd
JSONMerge(ctx context.Context, key, path string, value string) *StatusCmd
JSONMSetArgs(ctx context.Context, docs []JSONSetArgs) *StatusCmd
JSONMSet(ctx context.Context, params ...interface{}) *StatusCmd
JSONMGet(ctx context.Context, path string, keys ...string) *JSONSliceCmd
JSONNumIncrBy(ctx context.Context, key, path string, value float64) *JSONCmd
JSONObjKeys(ctx context.Context, key, path string) *SliceCmd
JSONObjLen(ctx context.Context, key, path string) *IntPointerSliceCmd
JSONSet(ctx context.Context, key, path string, value interface{}) *StatusCmd
JSONSetMode(ctx context.Context, key, path string, value interface{}, mode string) *StatusCmd
JSONStrAppend(ctx context.Context, key, path, value string) *IntPointerSliceCmd
JSONStrLen(ctx context.Context, key, path string) *IntPointerSliceCmd
JSONToggle(ctx context.Context, key, path string) *IntPointerSliceCmd
JSONType(ctx context.Context, key, path string) *JSONSliceCmd
}
var _ Cmdable = (*Compat)(nil)
type Compat struct {
client valkey.Client
maxp int
pOnly bool
}
// CacheCompat implements commands that support client-side caching.
type CacheCompat struct {
client valkey.Client
ttl time.Duration
}
func NewAdapter(client valkey.Client) Cmdable {
return &Compat{client: client, maxp: runtime.GOMAXPROCS(0)}
}
func (c *Compat) Cache(ttl time.Duration) CacheCompat {
return CacheCompat{client: c.client, ttl: ttl}
}
func (c *Compat) Command(ctx context.Context) *CommandsInfoCmd {
cmd := c.client.B().Command().Build()
resp := c.client.Do(ctx, cmd)
return newCommandsInfoCmd(resp)
}
type FilterBy struct {
Module string
ACLCat string
Pattern string
}
func (c *Compat) CommandList(ctx context.Context, filter FilterBy) *StringSliceCmd {
var resp valkey.ValkeyResult
if filter.Module != "" {
resp = c.client.Do(ctx, c.client.B().CommandList().FilterbyModuleName(filter.Module).Build())
} else if filter.Pattern != "" {
resp = c.client.Do(ctx, c.client.B().CommandList().FilterbyPatternPattern(filter.Pattern).Build())
} else if filter.ACLCat != "" {
resp = c.client.Do(ctx, c.client.B().CommandList().FilterbyAclcatCategory(filter.ACLCat).Build())
} else {
resp = c.client.Do(ctx, c.client.B().CommandList().Build())
}
return newStringSliceCmd(resp)
}
func (c *Compat) CommandGetKeys(ctx context.Context, commands ...any) *StringSliceCmd {
cmd := c.client.B().CommandGetkeys().Command(commands[0].(string)).Arg(argsToSlice(commands[1:])...).Build()
resp := c.client.Do(ctx, cmd)
return newStringSliceCmd(resp)
}
func (c *Compat) CommandGetKeysAndFlags(ctx context.Context, commands ...any) *KeyFlagsCmd {
cmd := c.client.B().CommandGetkeysandflags().Command(commands[0].(string)).Arg(argsToSlice(commands[1:])...).Build()
resp := c.client.Do(ctx, cmd)
return newKeyFlagsCmd(resp)
}
func (c *Compat) ClientGetName(ctx context.Context) *StringCmd {
cmd := c.client.B().ClientGetname().Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) Echo(ctx context.Context, message any) *StringCmd {
cmd := c.client.B().Echo().Message(str(message)).Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) Ping(ctx context.Context) *StatusCmd {
cmd := c.client.B().Ping().Build()
resp := c.client.Do(ctx, cmd)
return newStatusCmd(resp)
}
func (c *Compat) Quit(ctx context.Context) *StatusCmd {
cmd := c.client.B().Quit().Build()
resp := c.client.Do(ctx, cmd)
return newStatusCmd(resp)
}
func (c *Compat) Del(ctx context.Context, keys ...string) *IntCmd {
cmd := c.client.B().Del().Key(keys...).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) Unlink(ctx context.Context, keys ...string) *IntCmd {
cmd := c.client.B().Unlink().Key(keys...).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) Dump(ctx context.Context, key string) *StringCmd {
cmd := c.client.B().Dump().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) Exists(ctx context.Context, keys ...string) *IntCmd {
cmd := c.client.B().Exists().Key(keys...).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) Expire(ctx context.Context, key string, seconds time.Duration) *BoolCmd {
cmd := c.client.B().Expire().Key(key).Seconds(formatSec(seconds)).Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) ExpireAt(ctx context.Context, key string, timestamp time.Time) *BoolCmd {
cmd := c.client.B().Expireat().Key(key).Timestamp(timestamp.Unix()).Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) ExpireTime(ctx context.Context, key string) *DurationCmd {
cmd := c.client.B().Expiretime().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newDurationCmd(resp, time.Second)
}
func (c *Compat) ExpireNX(ctx context.Context, key string, seconds time.Duration) *BoolCmd {
cmd := c.client.B().Expire().Key(key).Seconds(formatSec(seconds)).Nx().Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) ExpireXX(ctx context.Context, key string, seconds time.Duration) *BoolCmd {
cmd := c.client.B().Expire().Key(key).Seconds(formatSec(seconds)).Xx().Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) ExpireGT(ctx context.Context, key string, seconds time.Duration) *BoolCmd {
cmd := c.client.B().Expire().Key(key).Seconds(formatSec(seconds)).Gt().Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) ExpireLT(ctx context.Context, key string, seconds time.Duration) *BoolCmd {
cmd := c.client.B().Expire().Key(key).Seconds(formatSec(seconds)).Lt().Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) Keys(ctx context.Context, pattern string) *StringSliceCmd {
var mu sync.Mutex
ret := &StringSliceCmd{}
ret.err = c.doPrimaries(ctx, func(c valkey.Client) error {
res, err := c.Do(ctx, c.B().Keys().Pattern(pattern).Build()).AsStrSlice()
if err == nil {
mu.Lock()
ret.val = append(ret.val, res...)
mu.Unlock()
}
return err
})
return ret
}
func (c *Compat) Migrate(ctx context.Context, host string, port int64, key string, db int64, timeout time.Duration) *StatusCmd {
cmd := c.client.B().Migrate().Host(host).Port(port).Key(key).DestinationDb(db).Timeout(formatSec(timeout)).Build()
resp := c.client.Do(ctx, cmd)
return newStatusCmd(resp)
}
func (c *Compat) Move(ctx context.Context, key string, db int64) *BoolCmd {
cmd := c.client.B().Move().Key(key).Db(db).Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) ObjectRefCount(ctx context.Context, key string) *IntCmd {
cmd := c.client.B().ObjectRefcount().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) ObjectEncoding(ctx context.Context, key string) *StringCmd {
cmd := c.client.B().ObjectEncoding().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) ObjectIdleTime(ctx context.Context, key string) *DurationCmd {
cmd := c.client.B().ObjectIdletime().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newDurationCmd(resp, time.Second)
}
func (c *Compat) Persist(ctx context.Context, key string) *BoolCmd {
cmd := c.client.B().Persist().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) PExpire(ctx context.Context, key string, milliseconds time.Duration) *BoolCmd {
cmd := c.client.B().Pexpire().Key(key).Milliseconds(formatMs(milliseconds)).Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) PExpireAt(ctx context.Context, key string, millisecondsTimestamp time.Time) *BoolCmd {
cmd := c.client.B().Pexpireat().Key(key).MillisecondsTimestamp(millisecondsTimestamp.UnixNano() / int64(time.Millisecond)).Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) PExpireTime(ctx context.Context, key string) *DurationCmd {
cmd := c.client.B().Pexpiretime().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newDurationCmd(resp, time.Millisecond)
}
func (c *Compat) PTTL(ctx context.Context, key string) *DurationCmd {
cmd := c.client.B().Pttl().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newDurationCmd(resp, time.Millisecond)
}
func (c *Compat) RandomKey(ctx context.Context) *StringCmd {
cmd := c.client.B().Randomkey().Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) Rename(ctx context.Context, key, newkey string) *StatusCmd {
cmd := c.client.B().Rename().Key(key).Newkey(newkey).Build()
resp := c.client.Do(ctx, cmd)
return newStatusCmd(resp)
}
func (c *Compat) RenameNX(ctx context.Context, key, newkey string) *BoolCmd {
cmd := c.client.B().Renamenx().Key(key).Newkey(newkey).Build()
resp := c.client.Do(ctx, cmd)
return newBoolCmd(resp)
}
func (c *Compat) Restore(ctx context.Context, key string, ttl time.Duration, serializedValue string) *StatusCmd {
cmd := c.client.B().Restore().Key(key).Ttl(formatMs(ttl)).SerializedValue(serializedValue).Build()
resp := c.client.Do(ctx, cmd)
return newStatusCmd(resp)
}
func (c *Compat) RestoreReplace(ctx context.Context, key string, ttl time.Duration, serializedValue string) *StatusCmd {
cmd := c.client.B().Restore().Key(key).Ttl(formatMs(ttl)).SerializedValue(serializedValue).Replace().Build()
resp := c.client.Do(ctx, cmd)
return newStatusCmd(resp)
}
func (c *Compat) sort(command, key string, sort Sort) cmds.Arbitrary {
cmd := c.client.B().Arbitrary(command).Keys(key)
if sort.By != "" {
cmd = cmd.Args("BY", sort.By)
}
if sort.Offset != 0 || sort.Count != 0 {
cmd = cmd.Args("LIMIT", strconv.FormatInt(sort.Offset, 10), strconv.FormatInt(sort.Count, 10))
}
for _, get := range sort.Get {
cmd = cmd.Args("GET").Args(get)
}
switch order := strings.ToUpper(sort.Order); order {
case "ASC", "DESC":
cmd = cmd.Args(order)
case "":
default:
panic(fmt.Sprintf("invalid sort order %s", sort.Order))
}
if sort.Alpha {
cmd = cmd.Args("ALPHA")
}
return cmd
}
func (c *Compat) Sort(ctx context.Context, key string, sort Sort) *StringSliceCmd {
resp := c.client.Do(ctx, c.sort("SORT", key, sort).Build())
return newStringSliceCmd(resp)
}
func (c *Compat) SortRO(ctx context.Context, key string, sort Sort) *StringSliceCmd {
resp := c.client.Do(ctx, c.sort("SORT_RO", key, sort).Build())
return newStringSliceCmd(resp)
}
func (c *Compat) SortStore(ctx context.Context, key, store string, sort Sort) *IntCmd {
resp := c.client.Do(ctx, c.sort("SORT", key, sort).Args("STORE", store).Build())
return newIntCmd(resp)
}
func (c *Compat) SortInterfaces(ctx context.Context, key string, sort Sort) *SliceCmd {
resp := c.client.Do(ctx, c.sort("SORT", key, sort).Build())
return newSliceCmd(resp, false)
}
func (c *Compat) Touch(ctx context.Context, keys ...string) *IntCmd {
cmd := c.client.B().Touch().Key(keys...).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) TTL(ctx context.Context, key string) *DurationCmd {
cmd := c.client.B().Ttl().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newDurationCmd(resp, time.Second)
}
func (c *Compat) Type(ctx context.Context, key string) *StatusCmd {
cmd := c.client.B().Type().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newStatusCmd(resp)
}
func (c *Compat) Append(ctx context.Context, key, value string) *IntCmd {
cmd := c.client.B().Append().Key(key).Value(value).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) Decr(ctx context.Context, key string) *IntCmd {
cmd := c.client.B().Decr().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) DecrBy(ctx context.Context, key string, decrement int64) *IntCmd {
cmd := c.client.B().Decrby().Key(key).Decrement(decrement).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) Get(ctx context.Context, key string) *StringCmd {
cmd := c.client.B().Get().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) GetRange(ctx context.Context, key string, start, end int64) *StringCmd {
cmd := c.client.B().Getrange().Key(key).Start(start).End(end).Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) GetSet(ctx context.Context, key string, value any) *StringCmd {
cmd := c.client.B().Getset().Key(key).Value(str(value)).Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
// GetEx An expiration of zero removes the TTL associated with the key (i.e. GETEX key persist).
// Requires Valkey >= 6.2.0.
func (c *Compat) GetEx(ctx context.Context, key string, expiration time.Duration) *StringCmd {
var resp valkey.ValkeyResult
if expiration > 0 {
if usePrecise(expiration) {
resp = c.client.Do(ctx, c.client.B().Getex().Key(key).PxMilliseconds(formatMs(expiration)).Build())
} else {
resp = c.client.Do(ctx, c.client.B().Getex().Key(key).ExSeconds(formatSec(expiration)).Build())
}
} else {
resp = c.client.Do(ctx, c.client.B().Getex().Key(key).Build())
}
return newStringCmd(resp)
}
func (c *Compat) GetDel(ctx context.Context, key string) *StringCmd {
cmd := c.client.B().Getdel().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newStringCmd(resp)
}
func (c *Compat) Incr(ctx context.Context, key string) *IntCmd {
cmd := c.client.B().Incr().Key(key).Build()
resp := c.client.Do(ctx, cmd)
return newIntCmd(resp)
}
func (c *Compat) IncrBy(ctx context.Context, key string, increment int64) *IntCmd {
cmd := c.client.B().Incrby().Key(key).Increment(increment).Build()
resp := c.client.Do(ctx, cmd)