Skip to content

Commit c7ee978

Browse files
committed
everything except zscan
1 parent 34ca6a3 commit c7ee978

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed

src/RESPite.StackExchange.Redis/RedisCommands.SortedSetCommands.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,14 @@ public void Format(
546546
}
547547

548548
[RespCommand] // by rank
549-
private static partial RespOperation<RedisValue[]> ZRange(
549+
public static partial RespOperation<RedisValue[]> ZRange(
550550
this in SortedSetCommands context,
551551
RedisKey key,
552552
long min,
553553
long max);
554554

555555
[RespCommand(Formatter = "ZRangeFormatter.NoScores")] // flexible
556-
private static partial RespOperation<RedisValue[]> ZRange(
556+
public static partial RespOperation<RedisValue[]> ZRange(
557557
this in SortedSetCommands context,
558558
RedisKey key,
559559
SortedSetCommands.ZRangeRequest request);
@@ -566,14 +566,21 @@ internal static RespOperation<RedisValue[]> ZRange(
566566
Order order) => order == Order.Ascending ? context.ZRange(key, min, max) : context.ZRevRange(key, max, min);
567567

568568
[RespCommand(nameof(ZRange))] // by rank, with scores
569-
private static partial RespOperation<SortedSetEntry[]> ZRangeWithScores(
569+
public static partial RespOperation<SortedSetEntry[]> ZRangeWithScores(
570570
this in SortedSetCommands context,
571571
RedisKey key,
572572
long min,
573573
[RespSuffix("WITHSCORES")] long max);
574574

575+
internal static RespOperation<SortedSetEntry[]> ZRangeWithScores(
576+
this in SortedSetCommands context,
577+
RedisKey key,
578+
long min,
579+
long max,
580+
Order order) => order == Order.Ascending ? context.ZRangeWithScores(key, min, max) : context.ZRevRangeWithScores(key, max, min);
581+
575582
[RespCommand(nameof(ZRange), Formatter = "ZRangeFormatter.WithScores")] // flexible, with scores
576-
private static partial RespOperation<SortedSetEntry[]> ZRangeWithScores(
583+
public static partial RespOperation<SortedSetEntry[]> ZRangeWithScores(
577584
this in SortedSetCommands context,
578585
RedisKey key,
579586
SortedSetCommands.ZRangeRequest request);
@@ -584,8 +591,14 @@ public static partial RespOperation<RedisValue[]> ZRangeByLex(
584591
RedisKey key,
585592
SortedSetCommands.ZRangeRequest request);
586593

594+
internal static RespOperation<RedisValue[]> ZRangeByLex(
595+
this in SortedSetCommands context,
596+
RedisKey key,
597+
SortedSetCommands.ZRangeRequest request,
598+
Order order) => order == Order.Ascending ? context.ZRangeByLex(key, request) : context.ZRevRangeByLex(key, request);
599+
587600
[RespCommand(nameof(ZRangeByLex), Formatter = "ZRangeFormatter.ByLexWithScores")]
588-
public static partial RespOperation<RedisValue[]> ZRangeByLexWithScores(
601+
public static partial RespOperation<SortedSetEntry[]> ZRangeByLexWithScores(
589602
this in SortedSetCommands context,
590603
RedisKey key,
591604
SortedSetCommands.ZRangeRequest request);
@@ -596,12 +609,24 @@ public static partial RespOperation<RedisValue[]> ZRangeByScore(
596609
RedisKey key,
597610
SortedSetCommands.ZRangeRequest request);
598611

612+
internal static RespOperation<RedisValue[]> ZRangeByScore(
613+
this in SortedSetCommands context,
614+
RedisKey key,
615+
SortedSetCommands.ZRangeRequest request,
616+
Order order) => order == Order.Ascending ? context.ZRangeByScore(key, request) : context.ZRevRangeByScore(key, request);
617+
599618
[RespCommand(nameof(ZRangeByScore), Formatter = "ZRangeFormatter.ByScoreWithScores")]
600-
public static partial RespOperation<RedisValue[]> ZRangeByScoreWithScores(
619+
public static partial RespOperation<SortedSetEntry[]> ZRangeByScoreWithScores(
601620
this in SortedSetCommands context,
602621
RedisKey key,
603622
SortedSetCommands.ZRangeRequest request);
604623

624+
internal static RespOperation<SortedSetEntry[]> ZRangeByScoreWithScores(
625+
this in SortedSetCommands context,
626+
RedisKey key,
627+
SortedSetCommands.ZRangeRequest request,
628+
Order order) => order == Order.Ascending ? context.ZRangeByScoreWithScores(key, request) : context.ZRevRangeByScoreWithScores(key, request);
629+
605630
[RespCommand] // by rank
606631
public static partial RespOperation<long> ZRangeStore(
607632
this in SortedSetCommands context,
@@ -659,7 +684,7 @@ internal static RespOperation<long> ZRangeStore(
659684
RedisValue member);
660685

661686
[RespCommand]
662-
public static partial RespOperation<long> ZRem(
687+
public static partial RespOperation<bool> ZRem(
663688
this in SortedSetCommands context,
664689
RedisKey key,
665690
RedisValue member);

src/RESPite.StackExchange.Redis/RespContextDatabase.SortedSet.cs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,15 @@ public SortedSetEntry[] SortedSetRangeByRankWithScores(
354354
long stop = -1,
355355
Order order = Order.Ascending,
356356
CommandFlags flags = CommandFlags.None)
357-
=> throw new NotImplementedException();
357+
=> Context(flags).SortedSets().ZRangeWithScores(key, start, stop, order).Wait(SyncTimeout);
358358

359359
public Task<SortedSetEntry[]> SortedSetRangeByRankWithScoresAsync(
360360
RedisKey key,
361361
long start = 0,
362362
long stop = -1,
363363
Order order = Order.Ascending,
364364
CommandFlags flags = CommandFlags.None)
365-
=> throw new NotImplementedException();
365+
=> Context(flags).SortedSets().ZRangeWithScores(key, start, stop, order).AsTask();
366366

367367
public RedisValue[] SortedSetRangeByScore(
368368
RedisKey key,
@@ -373,7 +373,15 @@ public RedisValue[] SortedSetRangeByScore(
373373
long skip = 0,
374374
long take = -1,
375375
CommandFlags flags = CommandFlags.None)
376-
=> throw new NotImplementedException();
376+
=> Context(flags).SortedSets().ZRangeByScore(key, ByScore(start, stop, exclude, skip, take), order).Wait(SyncTimeout);
377+
378+
private static SortedSetCommands.ZRangeRequest ByScore(double start, double stop, Exclude exclude, long skip, long take)
379+
{
380+
var req = SortedSetCommands.ZRangeRequest.ByScore(start, stop, exclude);
381+
req.Offset = skip;
382+
req.Count = take;
383+
return req;
384+
}
377385

378386
public Task<RedisValue[]> SortedSetRangeByScoreAsync(
379387
RedisKey key,
@@ -384,7 +392,7 @@ public Task<RedisValue[]> SortedSetRangeByScoreAsync(
384392
long skip = 0,
385393
long take = -1,
386394
CommandFlags flags = CommandFlags.None)
387-
=> throw new NotImplementedException();
395+
=> Context(flags).SortedSets().ZRangeByScore(key, ByScore(start, stop, exclude, skip, take), order).AsTask();
388396

389397
public SortedSetEntry[] SortedSetRangeByScoreWithScores(
390398
RedisKey key,
@@ -395,7 +403,7 @@ public SortedSetEntry[] SortedSetRangeByScoreWithScores(
395403
long skip = 0,
396404
long take = -1,
397405
CommandFlags flags = CommandFlags.None)
398-
=> throw new NotImplementedException();
406+
=> Context(flags).SortedSets().ZRangeByScoreWithScores(key, ByScore(start, stop, exclude, skip, take), order).Wait(SyncTimeout);
399407

400408
public Task<SortedSetEntry[]> SortedSetRangeByScoreWithScoresAsync(
401409
RedisKey key,
@@ -406,7 +414,15 @@ public Task<SortedSetEntry[]> SortedSetRangeByScoreWithScoresAsync(
406414
long skip = 0,
407415
long take = -1,
408416
CommandFlags flags = CommandFlags.None)
409-
=> throw new NotImplementedException();
417+
=> Context(flags).SortedSets().ZRangeByScoreWithScores(key, ByScore(start, stop, exclude, skip, take), order).AsTask();
418+
419+
private static SortedSetCommands.ZRangeRequest ByLex(RedisValue start, RedisValue stop, Exclude exclude, long skip, long take)
420+
{
421+
var req = SortedSetCommands.ZRangeRequest.ByLex(start, stop, exclude);
422+
req.Offset = skip;
423+
req.Count = take;
424+
return req;
425+
}
410426

411427
public RedisValue[] SortedSetRangeByValue(
412428
RedisKey key,
@@ -416,7 +432,7 @@ public RedisValue[] SortedSetRangeByValue(
416432
long skip = 0,
417433
long take = -1,
418434
CommandFlags flags = CommandFlags.None)
419-
=> throw new NotImplementedException();
435+
=> Context(flags).SortedSets().ZRangeByLex(key, ByLex(min, max, exclude, skip, take)).Wait(SyncTimeout);
420436

421437
public RedisValue[] SortedSetRangeByValue(
422438
RedisKey key,
@@ -427,7 +443,7 @@ public RedisValue[] SortedSetRangeByValue(
427443
long skip = 0,
428444
long take = -1,
429445
CommandFlags flags = CommandFlags.None)
430-
=> throw new NotImplementedException();
446+
=> Context(flags).SortedSets().ZRangeByLex(key, ByLex(min, max, exclude, skip, take), order).Wait(SyncTimeout);
431447

432448
public Task<RedisValue[]> SortedSetRangeByValueAsync(
433449
RedisKey key,
@@ -437,7 +453,7 @@ public Task<RedisValue[]> SortedSetRangeByValueAsync(
437453
long skip = 0,
438454
long take = -1,
439455
CommandFlags flags = CommandFlags.None)
440-
=> throw new NotImplementedException();
456+
=> Context(flags).SortedSets().ZRangeByLex(key, ByLex(min, max, exclude, skip, take)).AsTask();
441457

442458
public Task<RedisValue[]> SortedSetRangeByValueAsync(
443459
RedisKey key,
@@ -448,68 +464,68 @@ public Task<RedisValue[]> SortedSetRangeByValueAsync(
448464
long skip = 0,
449465
long take = -1,
450466
CommandFlags flags = CommandFlags.None)
451-
=> throw new NotImplementedException();
467+
=> Context(flags).SortedSets().ZRangeByLex(key, ByLex(min, max, exclude, skip, take), order).AsTask();
452468

453469
public bool SortedSetRemove(RedisKey key, RedisValue member, CommandFlags flags = CommandFlags.None)
454-
=> throw new NotImplementedException();
470+
=> Context(flags).SortedSets().ZRem(key, member).Wait(SyncTimeout);
455471

456472
public long SortedSetRemove(RedisKey key, RedisValue[] members, CommandFlags flags = CommandFlags.None)
457-
=> throw new NotImplementedException();
473+
=> Context(flags).SortedSets().ZRem(key, members).Wait(SyncTimeout);
458474

459475
public Task<bool> SortedSetRemoveAsync(RedisKey key, RedisValue member, CommandFlags flags = CommandFlags.None)
460-
=> throw new NotImplementedException();
476+
=> Context(flags).SortedSets().ZRem(key, member).AsTask();
461477

462478
public Task<long> SortedSetRemoveAsync(
463479
RedisKey key,
464480
RedisValue[] members,
465481
CommandFlags flags = CommandFlags.None)
466-
=> throw new NotImplementedException();
482+
=> Context(flags).SortedSets().ZRem(key, members).AsTask();
467483

468484
public long SortedSetRemoveRangeByRank(
469485
RedisKey key,
470486
long start,
471487
long stop,
472488
CommandFlags flags = CommandFlags.None)
473-
=> throw new NotImplementedException();
489+
=> Context(flags).SortedSets().ZRemRangeByRank(key, start, stop).Wait(SyncTimeout);
474490

475491
public Task<long> SortedSetRemoveRangeByRankAsync(
476492
RedisKey key,
477493
long start,
478494
long stop,
479495
CommandFlags flags = CommandFlags.None)
480-
=> throw new NotImplementedException();
496+
=> Context(flags).SortedSets().ZRemRangeByRank(key, start, stop).AsTask();
481497

482498
public long SortedSetRemoveRangeByScore(
483499
RedisKey key,
484500
double start,
485501
double stop,
486502
Exclude exclude = Exclude.None,
487503
CommandFlags flags = CommandFlags.None)
488-
=> throw new NotImplementedException();
504+
=> Context(flags).SortedSets().ZRemRangeByScore(key, SortedSetCommands.ZRangeRequest.ByScore(start, stop, exclude)).Wait(SyncTimeout);
489505

490506
public Task<long> SortedSetRemoveRangeByScoreAsync(
491507
RedisKey key,
492508
double start,
493509
double stop,
494510
Exclude exclude = Exclude.None,
495511
CommandFlags flags = CommandFlags.None)
496-
=> throw new NotImplementedException();
512+
=> Context(flags).SortedSets().ZRemRangeByScore(key, SortedSetCommands.ZRangeRequest.ByScore(start, stop, exclude)).AsTask();
497513

498514
public long SortedSetRemoveRangeByValue(
499515
RedisKey key,
500516
RedisValue min,
501517
RedisValue max,
502518
Exclude exclude = Exclude.None,
503519
CommandFlags flags = CommandFlags.None)
504-
=> throw new NotImplementedException();
520+
=> Context(flags).SortedSets().ZRemRangeByScore(key, SortedSetCommands.ZRangeRequest.ByLex(min, max, exclude)).Wait(SyncTimeout);
505521

506522
public Task<long> SortedSetRemoveRangeByValueAsync(
507523
RedisKey key,
508524
RedisValue min,
509525
RedisValue max,
510526
Exclude exclude = Exclude.None,
511527
CommandFlags flags = CommandFlags.None)
512-
=> throw new NotImplementedException();
528+
=> Context(flags).SortedSets().ZRemRangeByScore(key, SortedSetCommands.ZRangeRequest.ByLex(min, max, exclude)).AsTask();
513529

514530
public IEnumerable<SortedSetEntry>
515531
SortedSetScan(RedisKey key, RedisValue pattern, int pageSize, CommandFlags flags)
@@ -554,27 +570,27 @@ public bool SortedSetUpdate(
554570
double score,
555571
SortedSetWhen when = SortedSetWhen.Always,
556572
CommandFlags flags = CommandFlags.None)
557-
=> throw new NotImplementedException();
573+
=> Context(flags).SortedSets().ZAdd(key, when, member, score).Wait(SyncTimeout);
558574

559575
public long SortedSetUpdate(
560576
RedisKey key,
561577
SortedSetEntry[] values,
562578
SortedSetWhen when = SortedSetWhen.Always,
563579
CommandFlags flags = CommandFlags.None)
564-
=> throw new NotImplementedException();
580+
=> Context(flags).SortedSets().ZAdd(key, when, values).Wait(SyncTimeout);
565581

566582
public Task<bool> SortedSetUpdateAsync(
567583
RedisKey key,
568584
RedisValue member,
569585
double score,
570586
SortedSetWhen when = SortedSetWhen.Always,
571587
CommandFlags flags = CommandFlags.None)
572-
=> throw new NotImplementedException();
588+
=> Context(flags).SortedSets().ZAdd(key, when, member, score).AsTask();
573589

574590
public Task<long> SortedSetUpdateAsync(
575591
RedisKey key,
576592
SortedSetEntry[] values,
577593
SortedSetWhen when = SortedSetWhen.Always,
578594
CommandFlags flags = CommandFlags.None)
579-
=> throw new NotImplementedException();
595+
=> Context(flags).SortedSets().ZAdd(key, when, values).AsTask();
580596
}

0 commit comments

Comments
 (0)