Skip to content

Redis

The redis adapter provides a complete Redis integration including the concrete adapter, its abstract port interface, and a mock implementation for testing.

Ports

Abstract port interface defining the Redis adapter contract.

archipy.adapters.redis.ports.RedisAbsExpiryType module-attribute

RedisAbsExpiryType = int | datetime

archipy.adapters.redis.ports.RedisExpiryType module-attribute

RedisExpiryType = int | timedelta

archipy.adapters.redis.ports.RedisIntegerResponseType module-attribute

RedisIntegerResponseType = int

archipy.adapters.redis.ports.RedisKeyType module-attribute

RedisKeyType = bytes | str

archipy.adapters.redis.ports.RedisListResponseType module-attribute

RedisListResponseType = list[Any]

archipy.adapters.redis.ports.RedisSetResponseType module-attribute

RedisSetResponseType = set[Any]

archipy.adapters.redis.ports.RedisPatternType module-attribute

RedisPatternType = bytes | str

archipy.adapters.redis.ports.RedisResponseType module-attribute

RedisResponseType = Any

archipy.adapters.redis.ports.RedisSetType module-attribute

RedisSetType = int | bytes | str | float

archipy.adapters.redis.ports.RedisScoreCastType module-attribute

RedisScoreCastType = type | Callable

archipy.adapters.redis.ports.RedisPort

Interface for Redis operations providing a standardized access pattern.

This interface defines the contract for Redis adapters, ensuring consistent implementation of Redis operations across different adapters. It covers all essential Redis functionality including key-value operations, collections (lists, sets, sorted sets, hashes), and pub/sub capabilities.

Implementing classes should provide concrete implementations for all methods, typically by wrapping a Redis client library.

Source code in archipy/adapters/redis/ports.py
  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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
class RedisPort:
    """Interface for Redis operations providing a standardized access pattern.

    This interface defines the contract for Redis adapters, ensuring consistent
    implementation of Redis operations across different adapters. It covers all
    essential Redis functionality including key-value operations, collections
    (lists, sets, sorted sets, hashes), and pub/sub capabilities.

    Implementing classes should provide concrete implementations for all
    methods, typically by wrapping a Redis client library.
    """

    @abstractmethod
    def ping(self) -> RedisResponseType:
        """Tests the connection to the Redis server.

        Returns:
            RedisResponseType: The response from the server, typically "PONG".

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def pttl(self, name: bytes | str) -> RedisResponseType:
        """Gets the remaining time to live of a key in milliseconds.

        Args:
            name (bytes | str): The key to check.

        Returns:
            RedisResponseType: The time to live in milliseconds, or -1 if no TTL, -2 if key doesn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
        """Increments the integer value of a key by the given amount.

        Args:
            name (RedisKeyType): The key to increment.
            amount (int): The amount to increment by. Defaults to 1.

        Returns:
            RedisResponseType: The new value after incrementing.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def set(
        self,
        name: RedisKeyType,
        value: RedisSetType,
        ex: RedisExpiryType | None = None,
        px: RedisExpiryType | None = None,
        nx: bool = False,
        xx: bool = False,
        keepttl: bool = False,
        get: bool = False,
        exat: RedisAbsExpiryType | None = None,
        pxat: RedisAbsExpiryType | None = None,
    ) -> RedisResponseType:
        """Sets a key to a value with optional expiration and conditions.

        Args:
            name (RedisKeyType): The key to set.
            value (RedisSetType): The value to set for the key.
            ex (RedisExpiryType, optional): Expiration time in seconds or timedelta.
            px (RedisExpiryType, optional): Expiration time in milliseconds or timedelta.
            nx (bool): If True, set only if the key does not exist. Defaults to False.
            xx (bool): If True, set only if the key already exists. Defaults to False.
            keepttl (bool): If True, retain the existing TTL. Defaults to False.
            get (bool): If True, return the old value before setting. Defaults to False.
            exat (RedisAbsExpiryType, optional): Absolute expiration time as Unix timestamp or datetime.
            pxat (RedisAbsExpiryType, optional): Absolute expiration time in milliseconds or datetime.

        Returns:
            RedisResponseType: The result of the operation, often "OK" or the old value if get=True.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def get(self, key: str) -> RedisResponseType:
        """Retrieves the value of a key.

        Args:
            key (str): The key to retrieve.

        Returns:
            RedisResponseType: The value associated with the key, or None if the key doesn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def mget(
        self,
        keys: RedisKeyType | Iterable[RedisKeyType],
        *args: bytes | str,
    ) -> RedisResponseType:
        """Gets the values of multiple keys.

        Args:
            keys (RedisKeyType | Iterable[RedisKeyType]): A single key or iterable of keys.
            *args (bytes | str): Additional keys.

        Returns:
            RedisResponseType: A list of values corresponding to the keys.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
        """Sets multiple keys to their respective values.

        Args:
            mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of keys to values.

        Returns:
            RedisResponseType: Typically "OK" on success.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """Returns all keys matching a pattern.

        Args:
            pattern (RedisPatternType): The pattern to match keys against. Defaults to "*".
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: A list of matching keys.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Sets a key to a value and returns its old value.

        Args:
            key (RedisKeyType): The key to set.
            value (bytes | str | float): The new value to set.

        Returns:
            RedisResponseType: The old value of the key, or None if it didn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def getdel(self, key: bytes | str) -> RedisResponseType:
        """Gets the value of a key and deletes it.

        Args:
            key (bytes | str): The key to get and delete.

        Returns:
            RedisResponseType: The value of the key before deletion, or None if it didn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def exists(self, *names: bytes | str) -> RedisResponseType:
        """Checks if one or more keys exist.

        Args:
            *names (bytes | str): Variable number of keys to check.

        Returns:
            RedisResponseType: The number of keys that exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def delete(self, *names: bytes | str) -> RedisResponseType:
        """Deletes one or more keys.

        Args:
            *names (bytes | str): Variable number of keys to delete.

        Returns:
            RedisResponseType: The number of keys deleted.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Appends a value to a key's string value.

        Args:
            key (RedisKeyType): The key to append to.
            value (bytes | str | float): The value to append.

        Returns:
            RedisResponseType: The length of the string after appending.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def ttl(self, name: bytes | str) -> RedisResponseType:
        """Gets the remaining time to live of a key in seconds.

        Args:
            name (bytes | str): The key to check.

        Returns:
            RedisResponseType: The time to live in seconds, or -1 if no TTL, -2 if key doesn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def type(self, name: bytes | str) -> RedisResponseType:
        """Determines the type of value stored at a key.

        Args:
            name (bytes | str): The key to check.

        Returns:
            RedisResponseType: The type of the key's value (e.g., "string", "list", etc.).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def llen(self, name: str) -> RedisIntegerResponseType:
        """Gets the length of a list.

        Args:
            name (str): The key of the list.

        Returns:
            RedisIntegerResponseType: The number of items in the list.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def lpop(self, name: str, count: int | None = None) -> Any:
        """Removes and returns the first element(s) of a list.

        Args:
            name (str): The key of the list.
            count (int, optional): Number of elements to pop. Defaults to None (pops 1).

        Returns:
            Any: The popped element(s), or None if the list is empty.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Pushes one or more values to the start of a list.

        Args:
            name (str): The key of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: The length of the list after the push.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
        """Gets a range of elements from a list.

        Args:
            name (str): The key of the list.
            start (int): The starting index (inclusive).
            end (int): The ending index (inclusive).

        Returns:
            RedisListResponseType: A list of elements in the specified range.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
        """Removes occurrences of a value from a list.

        Args:
            name (str): The key of the list.
            count (int): Number of occurrences to remove (0 for all).
            value (str): The value to remove.

        Returns:
            RedisIntegerResponseType: The number of elements removed.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def lset(self, name: str, index: int, value: str) -> bool:
        """Sets the value of an element in a list by index.

        Args:
            name (str): The key of the list.
            index (int): The index to set.
            value (str): The new value.

        Returns:
            bool: True if successful.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def rpop(self, name: str, count: int | None = None) -> Any:
        """Removes and returns the last element(s) of a list.

        Args:
            name (str): The key of the list.
            count (int, optional): Number of elements to pop. Defaults to None (pops 1).

        Returns:
            Any: The popped element(s), or None if the list is empty.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Pushes one or more values to the end of a list.

        Args:
            name (str): The key of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: The length of the list after the push.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def scan(
        self,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> RedisResponseType:
        """Iterates over keys in the database incrementally.

        Args:
            cursor (int): The cursor position to start scanning. Defaults to 0.
            match (bytes | str, optional): Pattern to match keys against.
            count (int, optional): Hint for number of keys to return per iteration.
            _type (str, optional): Filter by type (e.g., "string", "list").
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: A tuple of (new_cursor, list_of_keys).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def scan_iter(
        self,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> Iterator:
        """Provides an iterator over keys in the database.

        Args:
            match (bytes | str, optional): Pattern to match keys against.
            count (int, optional): Hint for number of keys to return per iteration.
            _type (str, optional): Filter by type (e.g., "string", "list").
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            Iterator: An iterator yielding keys.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def sscan(
        self,
        name: RedisKeyType,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> RedisResponseType:
        """Iterates over members of a set incrementally.

        Args:
            name (RedisKeyType): The key of the set.
            cursor (int): The cursor position to start scanning. Defaults to 0.
            match (bytes | str, optional): Pattern to match members against.
            count (int, optional): Hint for number of members to return per iteration.

        Returns:
            RedisResponseType: A tuple of (new_cursor, list_of_members).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def sscan_iter(
        self,
        name: RedisKeyType,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> Iterator:
        """Provides an iterator over members of a set.

        Args:
            name (RedisKeyType): The key of the set.
            match (bytes | str, optional): Pattern to match members against.
            count (int, optional): Hint for number of members to return per iteration.

        Returns:
            Iterator: An iterator yielding set members.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Adds one or more members to a set.

        Args:
            name (str): The key of the set.
            *values (bytes | str | float): Members to add.

        Returns:
            RedisIntegerResponseType: The number of members added (excluding duplicates).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def scard(self, name: str) -> RedisIntegerResponseType:
        """Gets the number of members in a set.

        Args:
            name (str): The key of the set.

        Returns:
            RedisIntegerResponseType: The cardinality (size) of the set.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def sismember(self, name: str, value: str) -> bool:
        """Checks if a value is a member of a set.

        Args:
            name (str): The key of the set.
            value (str): The value to check.

        Returns:
            bool: True if the value is a member, False otherwise.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def smembers(self, name: str) -> RedisSetResponseType:
        """Gets all members of a set.

        Args:
            name (str): The key of the set.

        Returns:
            RedisSetResponseType: A set of all members.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
        """Removes and returns one or more random members from a set.

        Args:
            name (str): The key of the set.
            count (int, optional): Number of members to pop. Defaults to None (pops 1).

        Returns:
            bytes | float | int | str | list | None: The popped member(s), or None if the set is empty.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Removes one or more members from a set.

        Args:
            name (str): The key of the set.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisIntegerResponseType: The number of members removed.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
        """Gets the union of multiple sets.

        Args:
            keys (RedisKeyType): Name of the first key.
            *args (bytes | str): Additional key names.

        Returns:
            RedisSetResponseType: A set containing members of the resulting union.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zadd(
        self,
        name: RedisKeyType,
        mapping: Mapping[RedisKeyType, bytes | str | float],
        nx: bool = False,
        xx: bool = False,
        ch: bool = False,
        incr: bool = False,
        gt: bool = False,
        lt: bool = False,
    ) -> RedisResponseType:
        """Adds members with scores to a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of members to scores.
            nx (bool): If True, only add new elements. Defaults to False.
            xx (bool): If True, only update existing elements. Defaults to False.
            ch (bool): If True, return the number of changed elements. Defaults to False.
            incr (bool): If True, increment scores instead of setting. Defaults to False.
            gt (bool): If True, only update if new score is greater. Defaults to False.
            lt (bool): If True, only update if new score is less. Defaults to False.

        Returns:
            RedisResponseType: The number of elements added or updated.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zcard(self, name: bytes | str) -> RedisResponseType:
        """Gets the number of members in a sorted set.

        Args:
            name (bytes | str): The key of the sorted set.

        Returns:
            RedisResponseType: The cardinality (size) of the sorted set.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
        """Counts members in a sorted set within a score range.

        Args:
            name (RedisKeyType): The key of the sorted set.
            min (float | str): The minimum score (inclusive).
            max (float | str): The maximum score (inclusive).

        Returns:
            RedisResponseType: The number of members within the score range.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Removes and returns members with the highest scores from a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            count (int, optional): Number of members to pop. Defaults to None (pops 1).

        Returns:
            RedisResponseType: A list of (member, score) tuples popped.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Removes and returns members with the lowest scores from a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            count (int, optional): Number of members to pop. Defaults to None (pops 1).

        Returns:
            RedisResponseType: A list of (member, score) tuples popped.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        desc: bool = False,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
        byscore: bool = False,
        bylex: bool = False,
        offset: int | None = None,
        num: int | None = None,
    ) -> RedisResponseType:
        """Gets a range of members from a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            start (int): The starting index or score (depending on byscore).
            end (int): The ending index or score (depending on byscore).
            desc (bool): If True, sort in descending order. Defaults to False.
            withscores (bool): If True, return scores with members. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.
            byscore (bool): If True, range by score instead of rank. Defaults to False.
            bylex (bool): If True, range by lexicographical order. Defaults to False.
            offset (int, optional): Offset for byscore or bylex.
            num (int, optional): Number of elements for byscore or bylex.

        Returns:
            RedisResponseType: A list of members (and scores if withscores=True).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zrevrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Gets a range of members from a sorted set in reverse order.

        Args:
            name (RedisKeyType): The key of the sorted set.
            start (int): The starting index.
            end (int): The ending index.
            withscores (bool): If True, return scores with members. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

        Returns:
            RedisResponseType: A list of members (and scores if withscores=True).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zrangebyscore(
        self,
        name: RedisKeyType,
        min: float | str,
        max: float | str,
        start: int | None = None,
        num: int | None = None,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Gets members from a sorted set by score range.

        Args:
            name (RedisKeyType): The key of the sorted set.
            min (float | str): The minimum score (inclusive).
            max (float | str): The maximum score (inclusive).
            start (int, optional): Starting offset.
            num (int, optional): Number of elements to return.
            withscores (bool): If True, return scores with members. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

        Returns:
            RedisResponseType: A list of members (and scores if withscores=True).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Gets the rank of a member in a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            value (bytes | str | float): The member to find.

        Returns:
            RedisResponseType: The rank (index) of the member, or None if not found.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
        """Removes one or more members from a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisResponseType: The number of members removed.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Gets the score of a member in a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            value (bytes | str | float): The member to check.

        Returns:
            RedisResponseType: The score of the member, or None if not found.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
        """Deletes one or more fields from a hash.

        Args:
            name (str): The key of the hash.
            *keys (str | bytes): Fields to delete.

        Returns:
            RedisIntegerResponseType: The number of fields deleted.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hexists(self, name: str, key: str) -> bool:
        """Checks if a field exists in a hash.

        Args:
            name (str): The key of the hash.
            key (str): The field to check.

        Returns:
            bool: True if the field exists, False otherwise.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hget(self, name: str, key: str) -> str | None:
        """Gets the value of a field in a hash.

        Args:
            name (str): The key of the hash.
            key (str): The field to get.

        Returns:
            str | None: The value of the field, or None if not found.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hgetall(self, name: str) -> dict[str, Any]:
        """Gets all fields and values in a hash.

        Args:
            name (str): The key of the hash.

        Returns:
            dict[str, Any]: A dictionary of field/value pairs.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hkeys(self, name: str) -> RedisListResponseType:
        """Gets all fields in a hash.

        Args:
            name (str): The key of the hash.

        Returns:
            RedisListResponseType: A list of fields in the hash.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hlen(self, name: str) -> RedisIntegerResponseType:
        """Gets the number of fields in a hash.

        Args:
            name (str): The key of the hash.

        Returns:
            RedisIntegerResponseType: The number of fields in the hash.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hset(
        self,
        name: str,
        key: str | bytes | None = None,
        value: str | bytes | None = None,
        mapping: dict | None = None,
        items: list | None = None,
    ) -> RedisIntegerResponseType:
        """Sets one or more fields in a hash.

        Args:
            name (str): The key of the hash.
            key (str | bytes, optional): A single field to set.
            value (str | bytes, optional): The value for the single field.
            mapping (dict, optional): A dictionary of field/value pairs.
            items (list, optional): A list of field/value pairs.

        Returns:
            RedisIntegerResponseType: The number of fields added or updated.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
        """Gets the values of multiple fields in a hash.

        Args:
            name (str): The key of the hash.
            keys (list): A list of fields to get.
            *args (str | bytes): Additional fields to get.

        Returns:
            RedisListResponseType: A list of values for the specified fields.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def hvals(self, name: str) -> RedisListResponseType:
        """Gets all values in a hash.

        Args:
            name (str): The key of the hash.

        Returns:
            RedisListResponseType: A list of values in the hash.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
        """Publishes a message to a channel.

        Args:
            channel (RedisKeyType): The channel to publish to.
            message (bytes | str): The message to publish.
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: The number of subscribers that received the message.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """Lists active channels matching a pattern.

        Args:
            pattern (RedisPatternType): The pattern to match channels. Defaults to "*".
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: A list of active channels.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
        """Increments the score of a member in a sorted set.

        Args:
            name (RedisKeyType): The key of the sorted set.
            amount (float): The amount to increment by.
            value (bytes | str | float): The member to increment.

        Returns:
            RedisResponseType: The new score of the member.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def pubsub(self, **kwargs: Any) -> Any:
        """Returns a pub/sub object for subscribing to channels.

        Args:
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            Any: A pub/sub object.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> Any:
        """Returns a pipeline object for batching commands.

        Args:
            transaction (Any): If True, execute commands in a transaction. Defaults to True.
            shard_hint (Any, optional): Hint for sharding in clustered Redis.

        Returns:
            Any: A pipeline object.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    # Cluster-specific methods (no-op for standalone mode)
    def cluster_info(self) -> RedisResponseType:
        """Get cluster information.

        Returns:
            RedisResponseType: Cluster information or None for standalone mode.
        """
        return None

    def cluster_nodes(self) -> RedisResponseType:
        """Get cluster nodes information.

        Returns:
            RedisResponseType: Cluster nodes info or None for standalone mode.
        """
        return None

    def cluster_slots(self) -> RedisResponseType:
        """Get cluster slots mapping.

        Returns:
            RedisResponseType: Slots mapping or None for standalone mode.
        """
        return None

    def cluster_key_slot(self, key: str) -> RedisResponseType:
        """Get the hash slot for a key.

        Args:
            key (str): The key to get slot for.

        Returns:
            RedisResponseType: Key slot or None for standalone mode.
        """
        return None

    def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
        """Count keys in a specific slot.

        Args:
            slot (int): The slot number.

        Returns:
            RedisResponseType: Key count or None for standalone mode.
        """
        return None

    def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
        """Get keys in a specific slot.

        Args:
            slot (int): The slot number.
            count (int): Maximum number of keys to return.

        Returns:
            RedisResponseType: List of keys or None for standalone mode.
        """
        return None

archipy.adapters.redis.ports.RedisPort.ping abstractmethod

ping() -> RedisResponseType

Tests the connection to the Redis server.

Returns:

Name Type Description
RedisResponseType RedisResponseType

The response from the server, typically "PONG".

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def ping(self) -> RedisResponseType:
    """Tests the connection to the Redis server.

    Returns:
        RedisResponseType: The response from the server, typically "PONG".

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.pttl abstractmethod

pttl(name: bytes | str) -> RedisResponseType

Gets the remaining time to live of a key in milliseconds.

Parameters:

Name Type Description Default
name bytes | str

The key to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The time to live in milliseconds, or -1 if no TTL, -2 if key doesn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def pttl(self, name: bytes | str) -> RedisResponseType:
    """Gets the remaining time to live of a key in milliseconds.

    Args:
        name (bytes | str): The key to check.

    Returns:
        RedisResponseType: The time to live in milliseconds, or -1 if no TTL, -2 if key doesn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.incrby abstractmethod

incrby(
    name: RedisKeyType, amount: int = 1
) -> RedisResponseType

Increments the integer value of a key by the given amount.

Parameters:

Name Type Description Default
name RedisKeyType

The key to increment.

required
amount int

The amount to increment by. Defaults to 1.

1

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new value after incrementing.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
    """Increments the integer value of a key by the given amount.

    Args:
        name (RedisKeyType): The key to increment.
        amount (int): The amount to increment by. Defaults to 1.

    Returns:
        RedisResponseType: The new value after incrementing.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.set abstractmethod

set(
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType

Sets a key to a value with optional expiration and conditions.

Parameters:

Name Type Description Default
name RedisKeyType

The key to set.

required
value RedisSetType

The value to set for the key.

required
ex RedisExpiryType

Expiration time in seconds or timedelta.

None
px RedisExpiryType

Expiration time in milliseconds or timedelta.

None
nx bool

If True, set only if the key does not exist. Defaults to False.

False
xx bool

If True, set only if the key already exists. Defaults to False.

False
keepttl bool

If True, retain the existing TTL. Defaults to False.

False
get bool

If True, return the old value before setting. Defaults to False.

False
exat RedisAbsExpiryType

Absolute expiration time as Unix timestamp or datetime.

None
pxat RedisAbsExpiryType

Absolute expiration time in milliseconds or datetime.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

The result of the operation, often "OK" or the old value if get=True.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def set(
    self,
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType:
    """Sets a key to a value with optional expiration and conditions.

    Args:
        name (RedisKeyType): The key to set.
        value (RedisSetType): The value to set for the key.
        ex (RedisExpiryType, optional): Expiration time in seconds or timedelta.
        px (RedisExpiryType, optional): Expiration time in milliseconds or timedelta.
        nx (bool): If True, set only if the key does not exist. Defaults to False.
        xx (bool): If True, set only if the key already exists. Defaults to False.
        keepttl (bool): If True, retain the existing TTL. Defaults to False.
        get (bool): If True, return the old value before setting. Defaults to False.
        exat (RedisAbsExpiryType, optional): Absolute expiration time as Unix timestamp or datetime.
        pxat (RedisAbsExpiryType, optional): Absolute expiration time in milliseconds or datetime.

    Returns:
        RedisResponseType: The result of the operation, often "OK" or the old value if get=True.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.get abstractmethod

get(key: str) -> RedisResponseType

Retrieves the value of a key.

Parameters:

Name Type Description Default
key str

The key to retrieve.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value associated with the key, or None if the key doesn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def get(self, key: str) -> RedisResponseType:
    """Retrieves the value of a key.

    Args:
        key (str): The key to retrieve.

    Returns:
        RedisResponseType: The value associated with the key, or None if the key doesn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.mget abstractmethod

mget(
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType

Gets the values of multiple keys.

Parameters:

Name Type Description Default
keys RedisKeyType | Iterable[RedisKeyType]

A single key or iterable of keys.

required
*args bytes | str

Additional keys.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of values corresponding to the keys.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def mget(
    self,
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType:
    """Gets the values of multiple keys.

    Args:
        keys (RedisKeyType | Iterable[RedisKeyType]): A single key or iterable of keys.
        *args (bytes | str): Additional keys.

    Returns:
        RedisResponseType: A list of values corresponding to the keys.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.mset abstractmethod

mset(
    mapping: Mapping[RedisKeyType, bytes | str | float],
) -> RedisResponseType

Sets multiple keys to their respective values.

Parameters:

Name Type Description Default
mapping Mapping[RedisKeyType, bytes | str | float]

A mapping of keys to values.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Typically "OK" on success.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
    """Sets multiple keys to their respective values.

    Args:
        mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of keys to values.

    Returns:
        RedisResponseType: Typically "OK" on success.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.keys abstractmethod

keys(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Returns all keys matching a pattern.

Parameters:

Name Type Description Default
pattern RedisPatternType

The pattern to match keys against. Defaults to "*".

'*'
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of matching keys.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Returns all keys matching a pattern.

    Args:
        pattern (RedisPatternType): The pattern to match keys against. Defaults to "*".
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: A list of matching keys.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.getset abstractmethod

getset(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Sets a key to a value and returns its old value.

Parameters:

Name Type Description Default
key RedisKeyType

The key to set.

required
value bytes | str | float

The new value to set.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The old value of the key, or None if it didn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Sets a key to a value and returns its old value.

    Args:
        key (RedisKeyType): The key to set.
        value (bytes | str | float): The new value to set.

    Returns:
        RedisResponseType: The old value of the key, or None if it didn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.getdel abstractmethod

getdel(key: bytes | str) -> RedisResponseType

Gets the value of a key and deletes it.

Parameters:

Name Type Description Default
key bytes | str

The key to get and delete.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key before deletion, or None if it didn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def getdel(self, key: bytes | str) -> RedisResponseType:
    """Gets the value of a key and deletes it.

    Args:
        key (bytes | str): The key to get and delete.

    Returns:
        RedisResponseType: The value of the key before deletion, or None if it didn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.exists abstractmethod

exists(*names: bytes | str) -> RedisResponseType

Checks if one or more keys exist.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of keys to check.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of keys that exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def exists(self, *names: bytes | str) -> RedisResponseType:
    """Checks if one or more keys exist.

    Args:
        *names (bytes | str): Variable number of keys to check.

    Returns:
        RedisResponseType: The number of keys that exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.delete abstractmethod

delete(*names: bytes | str) -> RedisResponseType

Deletes one or more keys.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of keys to delete.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of keys deleted.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def delete(self, *names: bytes | str) -> RedisResponseType:
    """Deletes one or more keys.

    Args:
        *names (bytes | str): Variable number of keys to delete.

    Returns:
        RedisResponseType: The number of keys deleted.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.append abstractmethod

append(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Appends a value to a key's string value.

Parameters:

Name Type Description Default
key RedisKeyType

The key to append to.

required
value bytes | str | float

The value to append.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The length of the string after appending.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Appends a value to a key's string value.

    Args:
        key (RedisKeyType): The key to append to.
        value (bytes | str | float): The value to append.

    Returns:
        RedisResponseType: The length of the string after appending.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.ttl abstractmethod

ttl(name: bytes | str) -> RedisResponseType

Gets the remaining time to live of a key in seconds.

Parameters:

Name Type Description Default
name bytes | str

The key to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The time to live in seconds, or -1 if no TTL, -2 if key doesn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def ttl(self, name: bytes | str) -> RedisResponseType:
    """Gets the remaining time to live of a key in seconds.

    Args:
        name (bytes | str): The key to check.

    Returns:
        RedisResponseType: The time to live in seconds, or -1 if no TTL, -2 if key doesn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.type abstractmethod

type(name: bytes | str) -> RedisResponseType

Determines the type of value stored at a key.

Parameters:

Name Type Description Default
name bytes | str

The key to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The type of the key's value (e.g., "string", "list", etc.).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def type(self, name: bytes | str) -> RedisResponseType:
    """Determines the type of value stored at a key.

    Args:
        name (bytes | str): The key to check.

    Returns:
        RedisResponseType: The type of the key's value (e.g., "string", "list", etc.).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.llen abstractmethod

llen(name: str) -> RedisIntegerResponseType

Gets the length of a list.

Parameters:

Name Type Description Default
name str

The key of the list.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of items in the list.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def llen(self, name: str) -> RedisIntegerResponseType:
    """Gets the length of a list.

    Args:
        name (str): The key of the list.

    Returns:
        RedisIntegerResponseType: The number of items in the list.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.lpop abstractmethod

lpop(name: str, count: int | None = None) -> Any

Removes and returns the first element(s) of a list.

Parameters:

Name Type Description Default
name str

The key of the list.

required
count int

Number of elements to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
Any Any

The popped element(s), or None if the list is empty.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def lpop(self, name: str, count: int | None = None) -> Any:
    """Removes and returns the first element(s) of a list.

    Args:
        name (str): The key of the list.
        count (int, optional): Number of elements to pop. Defaults to None (pops 1).

    Returns:
        Any: The popped element(s), or None if the list is empty.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.lpush abstractmethod

lpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Pushes one or more values to the start of a list.

Parameters:

Name Type Description Default
name str

The key of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The length of the list after the push.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Pushes one or more values to the start of a list.

    Args:
        name (str): The key of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: The length of the list after the push.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.lrange abstractmethod

lrange(
    name: str, start: int, end: int
) -> RedisListResponseType

Gets a range of elements from a list.

Parameters:

Name Type Description Default
name str

The key of the list.

required
start int

The starting index (inclusive).

required
end int

The ending index (inclusive).

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of elements in the specified range.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
    """Gets a range of elements from a list.

    Args:
        name (str): The key of the list.
        start (int): The starting index (inclusive).
        end (int): The ending index (inclusive).

    Returns:
        RedisListResponseType: A list of elements in the specified range.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.lrem abstractmethod

lrem(
    name: str, count: int, value: str
) -> RedisIntegerResponseType

Removes occurrences of a value from a list.

Parameters:

Name Type Description Default
name str

The key of the list.

required
count int

Number of occurrences to remove (0 for all).

required
value str

The value to remove.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of elements removed.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
    """Removes occurrences of a value from a list.

    Args:
        name (str): The key of the list.
        count (int): Number of occurrences to remove (0 for all).
        value (str): The value to remove.

    Returns:
        RedisIntegerResponseType: The number of elements removed.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.lset abstractmethod

lset(name: str, index: int, value: str) -> bool

Sets the value of an element in a list by index.

Parameters:

Name Type Description Default
name str

The key of the list.

required
index int

The index to set.

required
value str

The new value.

required

Returns:

Name Type Description
bool bool

True if successful.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def lset(self, name: str, index: int, value: str) -> bool:
    """Sets the value of an element in a list by index.

    Args:
        name (str): The key of the list.
        index (int): The index to set.
        value (str): The new value.

    Returns:
        bool: True if successful.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.rpop abstractmethod

rpop(name: str, count: int | None = None) -> Any

Removes and returns the last element(s) of a list.

Parameters:

Name Type Description Default
name str

The key of the list.

required
count int

Number of elements to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
Any Any

The popped element(s), or None if the list is empty.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def rpop(self, name: str, count: int | None = None) -> Any:
    """Removes and returns the last element(s) of a list.

    Args:
        name (str): The key of the list.
        count (int, optional): Number of elements to pop. Defaults to None (pops 1).

    Returns:
        Any: The popped element(s), or None if the list is empty.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.rpush abstractmethod

rpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Pushes one or more values to the end of a list.

Parameters:

Name Type Description Default
name str

The key of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The length of the list after the push.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Pushes one or more values to the end of a list.

    Args:
        name (str): The key of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: The length of the list after the push.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.scan abstractmethod

scan(
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType

Iterates over keys in the database incrementally.

Parameters:

Name Type Description Default
cursor int

The cursor position to start scanning. Defaults to 0.

0
match bytes | str

Pattern to match keys against.

None
count int

Hint for number of keys to return per iteration.

None
_type str

Filter by type (e.g., "string", "list").

None
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

A tuple of (new_cursor, list_of_keys).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def scan(
    self,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType:
    """Iterates over keys in the database incrementally.

    Args:
        cursor (int): The cursor position to start scanning. Defaults to 0.
        match (bytes | str, optional): Pattern to match keys against.
        count (int, optional): Hint for number of keys to return per iteration.
        _type (str, optional): Filter by type (e.g., "string", "list").
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: A tuple of (new_cursor, list_of_keys).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.scan_iter abstractmethod

scan_iter(
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator

Provides an iterator over keys in the database.

Parameters:

Name Type Description Default
match bytes | str

Pattern to match keys against.

None
count int

Hint for number of keys to return per iteration.

None
_type str

Filter by type (e.g., "string", "list").

None
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
Iterator Iterator

An iterator yielding keys.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def scan_iter(
    self,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator:
    """Provides an iterator over keys in the database.

    Args:
        match (bytes | str, optional): Pattern to match keys against.
        count (int, optional): Hint for number of keys to return per iteration.
        _type (str, optional): Filter by type (e.g., "string", "list").
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        Iterator: An iterator yielding keys.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.sscan abstractmethod

sscan(
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType

Iterates over members of a set incrementally.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the set.

required
cursor int

The cursor position to start scanning. Defaults to 0.

0
match bytes | str

Pattern to match members against.

None
count int

Hint for number of members to return per iteration.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A tuple of (new_cursor, list_of_members).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def sscan(
    self,
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType:
    """Iterates over members of a set incrementally.

    Args:
        name (RedisKeyType): The key of the set.
        cursor (int): The cursor position to start scanning. Defaults to 0.
        match (bytes | str, optional): Pattern to match members against.
        count (int, optional): Hint for number of members to return per iteration.

    Returns:
        RedisResponseType: A tuple of (new_cursor, list_of_members).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.sscan_iter abstractmethod

sscan_iter(
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator

Provides an iterator over members of a set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the set.

required
match bytes | str

Pattern to match members against.

None
count int

Hint for number of members to return per iteration.

None

Returns:

Name Type Description
Iterator Iterator

An iterator yielding set members.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def sscan_iter(
    self,
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator:
    """Provides an iterator over members of a set.

    Args:
        name (RedisKeyType): The key of the set.
        match (bytes | str, optional): Pattern to match members against.
        count (int, optional): Hint for number of members to return per iteration.

    Returns:
        Iterator: An iterator yielding set members.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.sadd abstractmethod

sadd(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Adds one or more members to a set.

Parameters:

Name Type Description Default
name str

The key of the set.

required
*values bytes | str | float

Members to add.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of members added (excluding duplicates).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Adds one or more members to a set.

    Args:
        name (str): The key of the set.
        *values (bytes | str | float): Members to add.

    Returns:
        RedisIntegerResponseType: The number of members added (excluding duplicates).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.scard abstractmethod

scard(name: str) -> RedisIntegerResponseType

Gets the number of members in a set.

Parameters:

Name Type Description Default
name str

The key of the set.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The cardinality (size) of the set.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def scard(self, name: str) -> RedisIntegerResponseType:
    """Gets the number of members in a set.

    Args:
        name (str): The key of the set.

    Returns:
        RedisIntegerResponseType: The cardinality (size) of the set.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.sismember abstractmethod

sismember(name: str, value: str) -> bool

Checks if a value is a member of a set.

Parameters:

Name Type Description Default
name str

The key of the set.

required
value str

The value to check.

required

Returns:

Name Type Description
bool bool

True if the value is a member, False otherwise.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def sismember(self, name: str, value: str) -> bool:
    """Checks if a value is a member of a set.

    Args:
        name (str): The key of the set.
        value (str): The value to check.

    Returns:
        bool: True if the value is a member, False otherwise.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.smembers abstractmethod

smembers(name: str) -> RedisSetResponseType

Gets all members of a set.

Parameters:

Name Type Description Default
name str

The key of the set.

required

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

A set of all members.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def smembers(self, name: str) -> RedisSetResponseType:
    """Gets all members of a set.

    Args:
        name (str): The key of the set.

    Returns:
        RedisSetResponseType: A set of all members.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.spop abstractmethod

spop(
    name: str, count: int | None = None
) -> bytes | float | int | str | list | None

Removes and returns one or more random members from a set.

Parameters:

Name Type Description Default
name str

The key of the set.

required
count int

Number of members to pop. Defaults to None (pops 1).

None

Returns:

Type Description
bytes | float | int | str | list | None

bytes | float | int | str | list | None: The popped member(s), or None if the set is empty.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
    """Removes and returns one or more random members from a set.

    Args:
        name (str): The key of the set.
        count (int, optional): Number of members to pop. Defaults to None (pops 1).

    Returns:
        bytes | float | int | str | list | None: The popped member(s), or None if the set is empty.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.srem abstractmethod

srem(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Removes one or more members from a set.

Parameters:

Name Type Description Default
name str

The key of the set.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of members removed.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Removes one or more members from a set.

    Args:
        name (str): The key of the set.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisIntegerResponseType: The number of members removed.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.sunion abstractmethod

sunion(
    keys: RedisKeyType, *args: bytes | str
) -> RedisSetResponseType

Gets the union of multiple sets.

Parameters:

Name Type Description Default
keys RedisKeyType

Name of the first key.

required
*args bytes | str

Additional key names.

()

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

A set containing members of the resulting union.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
    """Gets the union of multiple sets.

    Args:
        keys (RedisKeyType): Name of the first key.
        *args (bytes | str): Additional key names.

    Returns:
        RedisSetResponseType: A set containing members of the resulting union.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zadd abstractmethod

zadd(
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType

Adds members with scores to a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
mapping Mapping[RedisKeyType, bytes | str | float]

A mapping of members to scores.

required
nx bool

If True, only add new elements. Defaults to False.

False
xx bool

If True, only update existing elements. Defaults to False.

False
ch bool

If True, return the number of changed elements. Defaults to False.

False
incr bool

If True, increment scores instead of setting. Defaults to False.

False
gt bool

If True, only update if new score is greater. Defaults to False.

False
lt bool

If True, only update if new score is less. Defaults to False.

False

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of elements added or updated.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zadd(
    self,
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType:
    """Adds members with scores to a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of members to scores.
        nx (bool): If True, only add new elements. Defaults to False.
        xx (bool): If True, only update existing elements. Defaults to False.
        ch (bool): If True, return the number of changed elements. Defaults to False.
        incr (bool): If True, increment scores instead of setting. Defaults to False.
        gt (bool): If True, only update if new score is greater. Defaults to False.
        lt (bool): If True, only update if new score is less. Defaults to False.

    Returns:
        RedisResponseType: The number of elements added or updated.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zcard abstractmethod

zcard(name: bytes | str) -> RedisResponseType

Gets the number of members in a sorted set.

Parameters:

Name Type Description Default
name bytes | str

The key of the sorted set.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The cardinality (size) of the sorted set.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zcard(self, name: bytes | str) -> RedisResponseType:
    """Gets the number of members in a sorted set.

    Args:
        name (bytes | str): The key of the sorted set.

    Returns:
        RedisResponseType: The cardinality (size) of the sorted set.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zcount abstractmethod

zcount(
    name: RedisKeyType, min: float | str, max: float | str
) -> RedisResponseType

Counts members in a sorted set within a score range.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
min float | str

The minimum score (inclusive).

required
max float | str

The maximum score (inclusive).

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of members within the score range.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
    """Counts members in a sorted set within a score range.

    Args:
        name (RedisKeyType): The key of the sorted set.
        min (float | str): The minimum score (inclusive).
        max (float | str): The maximum score (inclusive).

    Returns:
        RedisResponseType: The number of members within the score range.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zpopmax abstractmethod

zpopmax(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Removes and returns members with the highest scores from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
count int

Number of members to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of (member, score) tuples popped.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Removes and returns members with the highest scores from a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        count (int, optional): Number of members to pop. Defaults to None (pops 1).

    Returns:
        RedisResponseType: A list of (member, score) tuples popped.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zpopmin abstractmethod

zpopmin(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Removes and returns members with the lowest scores from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
count int

Number of members to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of (member, score) tuples popped.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Removes and returns members with the lowest scores from a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        count (int, optional): Number of members to pop. Defaults to None (pops 1).

    Returns:
        RedisResponseType: A list of (member, score) tuples popped.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zrange abstractmethod

zrange(
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType

Gets a range of members from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
start int

The starting index or score (depending on byscore).

required
end int

The ending index or score (depending on byscore).

required
desc bool

If True, sort in descending order. Defaults to False.

False
withscores bool

If True, return scores with members. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float
byscore bool

If True, range by score instead of rank. Defaults to False.

False
bylex bool

If True, range by lexicographical order. Defaults to False.

False
offset int

Offset for byscore or bylex.

None
num int

Number of elements for byscore or bylex.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of members (and scores if withscores=True).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType:
    """Gets a range of members from a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        start (int): The starting index or score (depending on byscore).
        end (int): The ending index or score (depending on byscore).
        desc (bool): If True, sort in descending order. Defaults to False.
        withscores (bool): If True, return scores with members. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.
        byscore (bool): If True, range by score instead of rank. Defaults to False.
        bylex (bool): If True, range by lexicographical order. Defaults to False.
        offset (int, optional): Offset for byscore or bylex.
        num (int, optional): Number of elements for byscore or bylex.

    Returns:
        RedisResponseType: A list of members (and scores if withscores=True).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zrevrange abstractmethod

zrevrange(
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Gets a range of members from a sorted set in reverse order.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
start int

The starting index.

required
end int

The ending index.

required
withscores bool

If True, return scores with members. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of members (and scores if withscores=True).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zrevrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Gets a range of members from a sorted set in reverse order.

    Args:
        name (RedisKeyType): The key of the sorted set.
        start (int): The starting index.
        end (int): The ending index.
        withscores (bool): If True, return scores with members. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: A list of members (and scores if withscores=True).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zrangebyscore abstractmethod

zrangebyscore(
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Gets members from a sorted set by score range.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
min float | str

The minimum score (inclusive).

required
max float | str

The maximum score (inclusive).

required
start int

Starting offset.

None
num int

Number of elements to return.

None
withscores bool

If True, return scores with members. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of members (and scores if withscores=True).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zrangebyscore(
    self,
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Gets members from a sorted set by score range.

    Args:
        name (RedisKeyType): The key of the sorted set.
        min (float | str): The minimum score (inclusive).
        max (float | str): The maximum score (inclusive).
        start (int, optional): Starting offset.
        num (int, optional): Number of elements to return.
        withscores (bool): If True, return scores with members. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: A list of members (and scores if withscores=True).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zrank abstractmethod

zrank(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Gets the rank of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
value bytes | str | float

The member to find.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The rank (index) of the member, or None if not found.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Gets the rank of a member in a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        value (bytes | str | float): The member to find.

    Returns:
        RedisResponseType: The rank (index) of the member, or None if not found.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zrem abstractmethod

zrem(
    name: RedisKeyType, *values: bytes | str | float
) -> RedisResponseType

Removes one or more members from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of members removed.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
    """Removes one or more members from a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisResponseType: The number of members removed.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zscore abstractmethod

zscore(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Gets the score of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
value bytes | str | float

The member to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The score of the member, or None if not found.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Gets the score of a member in a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        value (bytes | str | float): The member to check.

    Returns:
        RedisResponseType: The score of the member, or None if not found.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hdel abstractmethod

hdel(
    name: str, *keys: str | bytes
) -> RedisIntegerResponseType

Deletes one or more fields from a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
*keys str | bytes

Fields to delete.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of fields deleted.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
    """Deletes one or more fields from a hash.

    Args:
        name (str): The key of the hash.
        *keys (str | bytes): Fields to delete.

    Returns:
        RedisIntegerResponseType: The number of fields deleted.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hexists abstractmethod

hexists(name: str, key: str) -> bool

Checks if a field exists in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
key str

The field to check.

required

Returns:

Name Type Description
bool bool

True if the field exists, False otherwise.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hexists(self, name: str, key: str) -> bool:
    """Checks if a field exists in a hash.

    Args:
        name (str): The key of the hash.
        key (str): The field to check.

    Returns:
        bool: True if the field exists, False otherwise.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hget abstractmethod

hget(name: str, key: str) -> str | None

Gets the value of a field in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
key str

The field to get.

required

Returns:

Type Description
str | None

str | None: The value of the field, or None if not found.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hget(self, name: str, key: str) -> str | None:
    """Gets the value of a field in a hash.

    Args:
        name (str): The key of the hash.
        key (str): The field to get.

    Returns:
        str | None: The value of the field, or None if not found.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hgetall abstractmethod

hgetall(name: str) -> dict[str, Any]

Gets all fields and values in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: A dictionary of field/value pairs.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hgetall(self, name: str) -> dict[str, Any]:
    """Gets all fields and values in a hash.

    Args:
        name (str): The key of the hash.

    Returns:
        dict[str, Any]: A dictionary of field/value pairs.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hkeys abstractmethod

hkeys(name: str) -> RedisListResponseType

Gets all fields in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of fields in the hash.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hkeys(self, name: str) -> RedisListResponseType:
    """Gets all fields in a hash.

    Args:
        name (str): The key of the hash.

    Returns:
        RedisListResponseType: A list of fields in the hash.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hlen abstractmethod

hlen(name: str) -> RedisIntegerResponseType

Gets the number of fields in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of fields in the hash.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hlen(self, name: str) -> RedisIntegerResponseType:
    """Gets the number of fields in a hash.

    Args:
        name (str): The key of the hash.

    Returns:
        RedisIntegerResponseType: The number of fields in the hash.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hset abstractmethod

hset(
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType

Sets one or more fields in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
key str | bytes

A single field to set.

None
value str | bytes

The value for the single field.

None
mapping dict

A dictionary of field/value pairs.

None
items list

A list of field/value pairs.

None

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of fields added or updated.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hset(
    self,
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType:
    """Sets one or more fields in a hash.

    Args:
        name (str): The key of the hash.
        key (str | bytes, optional): A single field to set.
        value (str | bytes, optional): The value for the single field.
        mapping (dict, optional): A dictionary of field/value pairs.
        items (list, optional): A list of field/value pairs.

    Returns:
        RedisIntegerResponseType: The number of fields added or updated.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hmget abstractmethod

hmget(
    name: str, keys: list, *args: str | bytes
) -> RedisListResponseType

Gets the values of multiple fields in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
keys list

A list of fields to get.

required
*args str | bytes

Additional fields to get.

()

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of values for the specified fields.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
    """Gets the values of multiple fields in a hash.

    Args:
        name (str): The key of the hash.
        keys (list): A list of fields to get.
        *args (str | bytes): Additional fields to get.

    Returns:
        RedisListResponseType: A list of values for the specified fields.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.hvals abstractmethod

hvals(name: str) -> RedisListResponseType

Gets all values in a hash.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of values in the hash.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def hvals(self, name: str) -> RedisListResponseType:
    """Gets all values in a hash.

    Args:
        name (str): The key of the hash.

    Returns:
        RedisListResponseType: A list of values in the hash.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.publish abstractmethod

publish(
    channel: RedisKeyType,
    message: bytes | str,
    **kwargs: Any,
) -> RedisResponseType

Publishes a message to a channel.

Parameters:

Name Type Description Default
channel RedisKeyType

The channel to publish to.

required
message bytes | str

The message to publish.

required
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of subscribers that received the message.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
    """Publishes a message to a channel.

    Args:
        channel (RedisKeyType): The channel to publish to.
        message (bytes | str): The message to publish.
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: The number of subscribers that received the message.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.pubsub_channels abstractmethod

pubsub_channels(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Lists active channels matching a pattern.

Parameters:

Name Type Description Default
pattern RedisPatternType

The pattern to match channels. Defaults to "*".

'*'
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of active channels.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Lists active channels matching a pattern.

    Args:
        pattern (RedisPatternType): The pattern to match channels. Defaults to "*".
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: A list of active channels.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.zincrby abstractmethod

zincrby(
    name: RedisKeyType,
    amount: float,
    value: bytes | str | float,
) -> RedisResponseType

Increments the score of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
amount float

The amount to increment by.

required
value bytes | str | float

The member to increment.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new score of the member.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
    """Increments the score of a member in a sorted set.

    Args:
        name (RedisKeyType): The key of the sorted set.
        amount (float): The amount to increment by.
        value (bytes | str | float): The member to increment.

    Returns:
        RedisResponseType: The new score of the member.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.pubsub abstractmethod

pubsub(**kwargs: Any) -> Any

Returns a pub/sub object for subscribing to channels.

Parameters:

Name Type Description Default
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
Any Any

A pub/sub object.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def pubsub(self, **kwargs: Any) -> Any:
    """Returns a pub/sub object for subscribing to channels.

    Args:
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        Any: A pub/sub object.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.get_pipeline abstractmethod

get_pipeline(
    transaction: Any = True, shard_hint: Any = None
) -> Any

Returns a pipeline object for batching commands.

Parameters:

Name Type Description Default
transaction Any

If True, execute commands in a transaction. Defaults to True.

True
shard_hint Any

Hint for sharding in clustered Redis.

None

Returns:

Name Type Description
Any Any

A pipeline object.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> Any:
    """Returns a pipeline object for batching commands.

    Args:
        transaction (Any): If True, execute commands in a transaction. Defaults to True.
        shard_hint (Any, optional): Hint for sharding in clustered Redis.

    Returns:
        Any: A pipeline object.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.RedisPort.cluster_info

cluster_info() -> RedisResponseType

Get cluster information.

Returns:

Name Type Description
RedisResponseType RedisResponseType

Cluster information or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
def cluster_info(self) -> RedisResponseType:
    """Get cluster information.

    Returns:
        RedisResponseType: Cluster information or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.RedisPort.cluster_nodes

cluster_nodes() -> RedisResponseType

Get cluster nodes information.

Returns:

Name Type Description
RedisResponseType RedisResponseType

Cluster nodes info or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
def cluster_nodes(self) -> RedisResponseType:
    """Get cluster nodes information.

    Returns:
        RedisResponseType: Cluster nodes info or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.RedisPort.cluster_slots

cluster_slots() -> RedisResponseType

Get cluster slots mapping.

Returns:

Name Type Description
RedisResponseType RedisResponseType

Slots mapping or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
def cluster_slots(self) -> RedisResponseType:
    """Get cluster slots mapping.

    Returns:
        RedisResponseType: Slots mapping or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.RedisPort.cluster_key_slot

cluster_key_slot(key: str) -> RedisResponseType

Get the hash slot for a key.

Parameters:

Name Type Description Default
key str

The key to get slot for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Key slot or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
def cluster_key_slot(self, key: str) -> RedisResponseType:
    """Get the hash slot for a key.

    Args:
        key (str): The key to get slot for.

    Returns:
        RedisResponseType: Key slot or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.RedisPort.cluster_count_keys_in_slot

cluster_count_keys_in_slot(slot: int) -> RedisResponseType

Count keys in a specific slot.

Parameters:

Name Type Description Default
slot int

The slot number.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Key count or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
    """Count keys in a specific slot.

    Args:
        slot (int): The slot number.

    Returns:
        RedisResponseType: Key count or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.RedisPort.cluster_get_keys_in_slot

cluster_get_keys_in_slot(
    slot: int, count: int
) -> RedisResponseType

Get keys in a specific slot.

Parameters:

Name Type Description Default
slot int

The slot number.

required
count int

Maximum number of keys to return.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of keys or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
    """Get keys in a specific slot.

    Args:
        slot (int): The slot number.
        count (int): Maximum number of keys to return.

    Returns:
        RedisResponseType: List of keys or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.AsyncRedisPort

Interface for asynchronous Redis operations providing a standardized access pattern.

This interface defines the contract for asynchronous Redis adapters, ensuring consistent implementation of Redis operations across different adapters. It covers all essential Redis functionality including key-value operations, collections (lists, sets, sorted sets, hashes), and pub/sub capabilities.

Implementing classes should provide concrete implementations for all methods, typically by wrapping an asynchronous Redis client library.

Source code in archipy/adapters/redis/ports.py
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
class AsyncRedisPort:
    """Interface for asynchronous Redis operations providing a standardized access pattern.

    This interface defines the contract for asynchronous Redis adapters, ensuring consistent
    implementation of Redis operations across different adapters. It covers all
    essential Redis functionality including key-value operations, collections
    (lists, sets, sorted sets, hashes), and pub/sub capabilities.

    Implementing classes should provide concrete implementations for all
    methods, typically by wrapping an asynchronous Redis client library.
    """

    @abstractmethod
    async def ping(self) -> RedisResponseType:
        """Tests the connection to the Redis server asynchronously.

        Returns:
            RedisResponseType: The response from the server, typically "PONG".

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def pttl(self, name: bytes | str) -> RedisResponseType:
        """Gets the remaining time to live of a key in milliseconds asynchronously.

        Args:
            name (bytes | str): The key to check.

        Returns:
            RedisResponseType: The time to live in milliseconds, or -1 if no TTL, -2 if key doesn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
        """Increments the integer value of a key by the given amount asynchronously.

        Args:
            name (RedisKeyType): The key to increment.
            amount (int): The amount to increment by. Defaults to 1.

        Returns:
            RedisResponseType: The new value after incrementing.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def set(
        self,
        name: RedisKeyType,
        value: RedisSetType,
        ex: RedisExpiryType | None = None,
        px: RedisExpiryType | None = None,
        nx: bool = False,
        xx: bool = False,
        keepttl: bool = False,
        get: bool = False,
        exat: RedisAbsExpiryType | None = None,
        pxat: RedisAbsExpiryType | None = None,
    ) -> RedisResponseType:
        """Sets a key to a value with optional expiration and conditions asynchronously.

        Args:
            name (RedisKeyType): The key to set.
            value (RedisSetType): The value to set for the key.
            ex (RedisExpiryType, optional): Expiration time in seconds or timedelta.
            px (RedisExpiryType, optional): Expiration time in milliseconds or timedelta.
            nx (bool): If True, set only if the key does not exist. Defaults to False.
            xx (bool): If True, set only if the key already exists. Defaults to False.
            keepttl (bool): If True, retain the existing TTL. Defaults to False.
            get (bool): If True, return the old value before setting. Defaults to False.
            exat (RedisAbsExpiryType, optional): Absolute expiration time as Unix timestamp or datetime.
            pxat (RedisAbsExpiryType, optional): Absolute expiration time in milliseconds or datetime.

        Returns:
            RedisResponseType: The result of the operation, often "OK" or the old value if get=True.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def get(self, key: str) -> RedisResponseType:
        """Retrieves the value of a key asynchronously.

        Args:
            key (str): The key to retrieve.

        Returns:
            RedisResponseType: The value associated with the key, or None if the key doesn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def mget(
        self,
        keys: RedisKeyType | Iterable[RedisKeyType],
        *args: bytes | str,
    ) -> RedisResponseType:
        """Gets the values of multiple keys asynchronously.

        Args:
            keys (RedisKeyType | Iterable[RedisKeyType]): A single key or iterable of keys.
            *args (bytes | str): Additional keys.

        Returns:
            RedisResponseType: A list of values corresponding to the keys.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
        """Sets multiple keys to their respective values asynchronously.

        Args:
            mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of keys to values.

        Returns:
            RedisResponseType: Typically "OK" on success.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """Returns all keys matching a pattern asynchronously.

        Args:
            pattern (RedisPatternType): The pattern to match keys against. Defaults to "*".
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: A list of matching keys.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Sets a key to a value and returns its old value asynchronously.

        Args:
            key (RedisKeyType): The key to set.
            value (bytes | str | float): The new value to set.

        Returns:
            RedisResponseType: The old value of the key, or None if it didn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def getdel(self, key: bytes | str) -> RedisResponseType:
        """Gets the value of a key and deletes it asynchronously.

        Args:
            key (bytes | str): The key to get and delete.

        Returns:
            RedisResponseType: The value of the key before deletion, or None if it didn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def exists(self, *names: bytes | str) -> RedisResponseType:
        """Checks if one or more keys exist asynchronously.

        Args:
            *names (bytes | str): Variable number of keys to check.

        Returns:
            RedisResponseType: The number of keys that exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def delete(self, *names: bytes | str) -> RedisResponseType:
        """Deletes one or more keys asynchronously.

        Args:
            *names (bytes | str): Variable number of keys to delete.

        Returns:
            RedisResponseType: The number of keys deleted.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Appends a value to a key's string value asynchronously.

        Args:
            key (RedisKeyType): The key to append to.
            value (bytes | str | float): The value to append.

        Returns:
            RedisResponseType: The length of the string after appending.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def ttl(self, name: bytes | str) -> RedisResponseType:
        """Gets the remaining time to live of a key in seconds asynchronously.

        Args:
            name (bytes | str): The key to check.

        Returns:
            RedisResponseType: The time to live in seconds, or -1 if no TTL, -2 if key doesn't exist.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def type(self, name: bytes | str) -> RedisResponseType:
        """Determines the type of value stored at a key asynchronously.

        Args:
            name (bytes | str): The key to check.

        Returns:
            RedisResponseType: The type of the key's value (e.g., "string", "list", etc.).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def llen(self, name: str) -> RedisIntegerResponseType:
        """Gets the length of a list asynchronously.

        Args:
            name (str): The key of the list.

        Returns:
            RedisIntegerResponseType: The number of items in the list.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def lpop(self, name: str, count: int | None = None) -> Any:
        """Removes and returns the first element(s) of a list asynchronously.

        Args:
            name (str): The key of the list.
            count (int, optional): Number of elements to pop. Defaults to None (pops 1).

        Returns:
            Any: The popped element(s), or None if the list is empty.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Pushes one or more values to the start of a list asynchronously.

        Args:
            name (str): The key of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: The length of the list after the push.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
        """Gets a range of elements from a list asynchronously.

        Args:
            name (str): The key of the list.
            start (int): The starting index (inclusive).
            end (int): The ending index (inclusive).

        Returns:
            RedisListResponseType: A list of elements in the specified range.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
        """Removes occurrences of a value from a list asynchronously.

        Args:
            name (str): The key of the list.
            count (int): Number of occurrences to remove (0 for all).
            value (str): The value to remove.

        Returns:
            RedisIntegerResponseType: The number of elements removed.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def lset(self, name: str, index: int, value: str) -> bool:
        """Sets the value of an element in a list by index asynchronously.

        Args:
            name (str): The key of the list.
            index (int): The index to set.
            value (str): The new value.

        Returns:
            bool: True if successful.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def rpop(self, name: str, count: int | None = None) -> Any:
        """Removes and returns the last element(s) of a list asynchronously.

        Args:
            name (str): The key of the list.
            count (int, optional): Number of elements to pop. Defaults to None (pops 1).

        Returns:
            Any: The popped element(s), or None if the list is empty.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Pushes one or more values to the end of a list asynchronously.

        Args:
            name (str): The key of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: The length of the list after the push.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def scan(
        self,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> RedisResponseType:
        """Iterates over keys in the database incrementally asynchronously.

        Args:
            cursor (int): The cursor position to start scanning. Defaults to 0.
            match (bytes | str, optional): Pattern to match keys against.
            count (int, optional): Hint for number of keys to return per iteration.
            _type (str, optional): Filter by type (e.g., "string", "list").
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: A tuple of (new_cursor, list_of_keys).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def scan_iter(
        self,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> Iterator:
        """Provides an iterator over keys in the database asynchronously.

        Args:
            match (bytes | str, optional): Pattern to match keys against.
            count (int, optional): Hint for number of keys to return per iteration.
            _type (str, optional): Filter by type (e.g., "string", "list").
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            Iterator: An iterator yielding keys.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def sscan(
        self,
        name: RedisKeyType,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> RedisResponseType:
        """Iterates over members of a set incrementally asynchronously.

        Args:
            name (RedisKeyType): The key of the set.
            cursor (int): The cursor position to start scanning. Defaults to 0.
            match (bytes | str, optional): Pattern to match members against.
            count (int, optional): Hint for number of members to return per iteration.

        Returns:
            RedisResponseType: A tuple of (new_cursor, list_of_members).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def sscan_iter(
        self,
        name: RedisKeyType,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> Iterator:
        """Provides an iterator over members of a set asynchronously.

        Args:
            name (RedisKeyType): The key of the set.
            match (bytes | str, optional): Pattern to match members against.
            count (int, optional): Hint for number of members to return per iteration.

        Returns:
            Iterator: An iterator yielding set members.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Adds one or more members to a set asynchronously.

        Args:
            name (str): The key of the set.
            *values (bytes | str | float): Members to add.

        Returns:
            RedisIntegerResponseType: The number of members added (excluding duplicates).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def scard(self, name: str) -> RedisIntegerResponseType:
        """Gets the number of members in a set asynchronously.

        Args:
            name (str): The key of the set.

        Returns:
            RedisIntegerResponseType: The cardinality (size) of the set.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def sismember(self, name: str, value: str) -> bool:
        """Checks if a value is a member of a set asynchronously.

        Args:
            name (str): The key of the set.
            value (str): The value to check.

        Returns:
            bool: True if the value is a member, False otherwise.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def smembers(self, name: str) -> RedisSetResponseType:
        """Gets all members of a set asynchronously.

        Args:
            name (str): The key of the set.

        Returns:
            RedisSetResponseType: A set of all members.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
        """Removes and returns one or more random members from a set asynchronously.

        Args:
            name (str): The key of the set.
            count (int, optional): Number of members to pop. Defaults to None (pops 1).

        Returns:
            bytes | float | int | str | list | None: The popped member(s), or None if the set is empty.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Removes one or more members from a set asynchronously.

        Args:
            name (str): The key of the set.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisIntegerResponseType: The number of members removed.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
        """Gets the union of multiple sets asynchronously.

        Args:
            keys (RedisKeyType): Name of the first key.
            *args (bytes | str): Additional key names.

        Returns:
            RedisSetResponseType: A set containing members of the resulting union.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zadd(
        self,
        name: RedisKeyType,
        mapping: Mapping[RedisKeyType, bytes | str | float],
        nx: bool = False,
        xx: bool = False,
        ch: bool = False,
        incr: bool = False,
        gt: bool = False,
        lt: bool = False,
    ) -> RedisResponseType:
        """Adds members with scores to a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of members to scores.
            nx (bool): If True, only add new elements. Defaults to False.
            xx (bool): If True, only update existing elements. Defaults to False.
            ch (bool): If True, return the number of changed elements. Defaults to False.
            incr (bool): If True, increment scores instead of setting. Defaults to False.
            gt (bool): If True, only update if new score is greater. Defaults to False.
            lt (bool): If True, only update if new score is less. Defaults to False.

        Returns:
            RedisResponseType: The number of elements added or updated.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zcard(self, name: bytes | str) -> RedisResponseType:
        """Gets the number of members in a sorted set asynchronously.

        Args:
            name (bytes | str): The key of the sorted set.

        Returns:
            RedisResponseType: The cardinality (size) of the sorted set.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
        """Counts members in a sorted set within a score range asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            min (float | str): The minimum score (inclusive).
            max (float | str): The maximum score (inclusive).

        Returns:
            RedisResponseType: The number of members within the score range.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Removes and returns members with the highest scores from a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            count (int, optional): Number of members to pop. Defaults to None (pops 1).

        Returns:
            RedisResponseType: A list of (member, score) tuples popped.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Removes and returns members with the lowest scores from a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            count (int, optional): Number of members to pop. Defaults to None (pops 1).

        Returns:
            RedisResponseType: A list of (member, score) tuples popped.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        desc: bool = False,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
        byscore: bool = False,
        bylex: bool = False,
        offset: int | None = None,
        num: int | None = None,
    ) -> RedisResponseType:
        """Gets a range of members from a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            start (int): The starting index or score (depending on byscore).
            end (int): The ending index or score (depending on byscore).
            desc (bool): If True, sort in descending order. Defaults to False.
            withscores (bool): If True, return scores with members. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.
            byscore (bool): If True, range by score instead of rank. Defaults to False.
            bylex (bool): If True, range by lexicographical order. Defaults to False.
            offset (int, optional): Offset for byscore or bylex.
            num (int, optional): Number of elements for byscore or bylex.

        Returns:
            RedisResponseType: A list of members (and scores if withscores=True).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zrevrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Gets a range of members from a sorted set in reverse order asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            start (int): The starting index.
            end (int): The ending index.
            withscores (bool): If True, return scores with members. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

        Returns:
            RedisResponseType: A list of members (and scores if withscores=True).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zrangebyscore(
        self,
        name: RedisKeyType,
        min: float | str,
        max: float | str,
        start: int | None = None,
        num: int | None = None,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Gets members from a sorted set by score range asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            min (float | str): The minimum score (inclusive).
            max (float | str): The maximum score (inclusive).
            start (int, optional): Starting offset.
            num (int, optional): Number of elements to return.
            withscores (bool): If True, return scores with members. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

        Returns:
            RedisResponseType: A list of members (and scores if withscores=True).

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Gets the rank of a member in a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            value (bytes | str | float): The member to find.

        Returns:
            RedisResponseType: The rank (index) of the member, or None if not found.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
        """Removes one or more members from a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisResponseType: The number of members removed.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Gets the score of a member in a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            value (bytes | str | float): The member to check.

        Returns:
            RedisResponseType: The score of the member, or None if not found.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
        """Deletes one or more fields from a hash asynchronously.

        Args:
            name (str): The key of the hash.
            *keys (str | bytes): Fields to delete.

        Returns:
            RedisIntegerResponseType: The number of fields deleted.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hexists(self, name: str, key: str) -> bool:
        """Checks if a field exists in a hash asynchronously.

        Args:
            name (str): The key of the hash.
            key (str): The field to check.

        Returns:
            bool: True if the field exists, False otherwise.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hget(self, name: str, key: str) -> str | None:
        """Gets the value of a field in a hash asynchronously.

        Args:
            name (str): The key of the hash.
            key (str): The field to get.

        Returns:
            str | None: The value of the field, or None if not found.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hgetall(self, name: str) -> dict[str, Any]:
        """Gets all fields and values in a hash asynchronously.

        Args:
            name (str): The key of the hash.

        Returns:
            dict[str, Any]: A dictionary of field/value pairs.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hkeys(self, name: str) -> RedisListResponseType:
        """Gets all fields in a hash asynchronously.

        Args:
            name (str): The key of the hash.

        Returns:
            RedisListResponseType: A list of fields in the hash.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hlen(self, name: str) -> RedisIntegerResponseType:
        """Gets the number of fields in a hash asynchronously.

        Args:
            name (str): The key of the hash.

        Returns:
            RedisIntegerResponseType: The number of fields in the hash.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hset(
        self,
        name: str,
        key: str | bytes | None = None,
        value: str | bytes | None = None,
        mapping: dict | None = None,
        items: list | None = None,
    ) -> RedisIntegerResponseType:
        """Sets one or more fields in a hash asynchronously.

        Args:
            name (str): The key of the hash.
            key (str | bytes, optional): A single field to set.
            value (str | bytes, optional): The value for the single field.
            mapping (dict, optional): A dictionary of field/value pairs.
            items (list, optional): A list of field/value pairs.

        Returns:
            RedisIntegerResponseType: The number of fields added or updated.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
        """Gets the values of multiple fields in a hash asynchronously.

        Args:
            name (str): The key of the hash.
            keys (list): A list of fields to get.
            *args (str | bytes): Additional fields to get.

        Returns:
            RedisListResponseType: A list of values for the specified fields.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def hvals(self, name: str) -> RedisListResponseType:
        """Gets all values in a hash asynchronously.

        Args:
            name (str): The key of the hash.

        Returns:
            RedisListResponseType: A list of values in the hash.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
        """Publishes a message to a channel asynchronously.

        Args:
            channel (RedisKeyType): The channel to publish to.
            message (bytes | str): The message to publish.
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: The number of subscribers that received the message.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """Lists active channels matching a pattern asynchronously.

        Args:
            pattern (RedisPatternType): The pattern to match channels. Defaults to "*".
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            RedisResponseType: A list of active channels.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
        """Increments the score of a member in a sorted set asynchronously.

        Args:
            name (RedisKeyType): The key of the sorted set.
            amount (float): The amount to increment by.
            value (bytes | str | float): The member to increment.

        Returns:
            RedisResponseType: The new score of the member.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def pubsub(self, **kwargs: Any) -> Any:
        """Returns a pub/sub object for subscribing to channels asynchronously.

        Args:
            **kwargs (Any): Additional arguments for the underlying implementation.

        Returns:
            Any: A pub/sub object.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    @abstractmethod
    async def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> Any:
        """Returns a pipeline object for batching commands asynchronously.

        Args:
            transaction (Any): If True, execute commands in a transaction. Defaults to True.
            shard_hint (Any, optional): Hint for sharding in clustered Redis.

        Returns:
            Any: A pipeline object.

        Raises:
            NotImplementedError: If not implemented by the subclass.
        """
        raise NotImplementedError

    # Cluster-specific methods (no-op for standalone mode)
    async def cluster_info(self) -> RedisResponseType:
        """Get cluster information asynchronously.

        Returns:
            RedisResponseType: Cluster information or None for standalone mode.
        """
        return None

    async def cluster_nodes(self) -> RedisResponseType:
        """Get cluster nodes information asynchronously.

        Returns:
            RedisResponseType: Cluster nodes info or None for standalone mode.
        """
        return None

    async def cluster_slots(self) -> RedisResponseType:
        """Get cluster slots mapping asynchronously.

        Returns:
            RedisResponseType: Slots mapping or None for standalone mode.
        """
        return None

    async def cluster_key_slot(self, key: str) -> RedisResponseType:
        """Get the hash slot for a key asynchronously.

        Args:
            key (str): The key to get slot for.

        Returns:
            RedisResponseType: Key slot or None for standalone mode.
        """
        return None

    async def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
        """Count keys in a specific slot asynchronously.

        Args:
            slot (int): The slot number.

        Returns:
            RedisResponseType: Key count or None for standalone mode.
        """
        return None

    async def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
        """Get keys in a specific slot asynchronously.

        Args:
            slot (int): The slot number.
            count (int): Maximum number of keys to return.

        Returns:
            RedisResponseType: List of keys or None for standalone mode.
        """
        return None

archipy.adapters.redis.ports.AsyncRedisPort.ping abstractmethod async

ping() -> RedisResponseType

Tests the connection to the Redis server asynchronously.

Returns:

Name Type Description
RedisResponseType RedisResponseType

The response from the server, typically "PONG".

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def ping(self) -> RedisResponseType:
    """Tests the connection to the Redis server asynchronously.

    Returns:
        RedisResponseType: The response from the server, typically "PONG".

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.pttl abstractmethod async

pttl(name: bytes | str) -> RedisResponseType

Gets the remaining time to live of a key in milliseconds asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The time to live in milliseconds, or -1 if no TTL, -2 if key doesn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def pttl(self, name: bytes | str) -> RedisResponseType:
    """Gets the remaining time to live of a key in milliseconds asynchronously.

    Args:
        name (bytes | str): The key to check.

    Returns:
        RedisResponseType: The time to live in milliseconds, or -1 if no TTL, -2 if key doesn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.incrby abstractmethod async

incrby(
    name: RedisKeyType, amount: int = 1
) -> RedisResponseType

Increments the integer value of a key by the given amount asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key to increment.

required
amount int

The amount to increment by. Defaults to 1.

1

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new value after incrementing.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
    """Increments the integer value of a key by the given amount asynchronously.

    Args:
        name (RedisKeyType): The key to increment.
        amount (int): The amount to increment by. Defaults to 1.

    Returns:
        RedisResponseType: The new value after incrementing.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.set abstractmethod async

set(
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType

Sets a key to a value with optional expiration and conditions asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key to set.

required
value RedisSetType

The value to set for the key.

required
ex RedisExpiryType

Expiration time in seconds or timedelta.

None
px RedisExpiryType

Expiration time in milliseconds or timedelta.

None
nx bool

If True, set only if the key does not exist. Defaults to False.

False
xx bool

If True, set only if the key already exists. Defaults to False.

False
keepttl bool

If True, retain the existing TTL. Defaults to False.

False
get bool

If True, return the old value before setting. Defaults to False.

False
exat RedisAbsExpiryType

Absolute expiration time as Unix timestamp or datetime.

None
pxat RedisAbsExpiryType

Absolute expiration time in milliseconds or datetime.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

The result of the operation, often "OK" or the old value if get=True.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def set(
    self,
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType:
    """Sets a key to a value with optional expiration and conditions asynchronously.

    Args:
        name (RedisKeyType): The key to set.
        value (RedisSetType): The value to set for the key.
        ex (RedisExpiryType, optional): Expiration time in seconds or timedelta.
        px (RedisExpiryType, optional): Expiration time in milliseconds or timedelta.
        nx (bool): If True, set only if the key does not exist. Defaults to False.
        xx (bool): If True, set only if the key already exists. Defaults to False.
        keepttl (bool): If True, retain the existing TTL. Defaults to False.
        get (bool): If True, return the old value before setting. Defaults to False.
        exat (RedisAbsExpiryType, optional): Absolute expiration time as Unix timestamp or datetime.
        pxat (RedisAbsExpiryType, optional): Absolute expiration time in milliseconds or datetime.

    Returns:
        RedisResponseType: The result of the operation, often "OK" or the old value if get=True.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.get abstractmethod async

get(key: str) -> RedisResponseType

Retrieves the value of a key asynchronously.

Parameters:

Name Type Description Default
key str

The key to retrieve.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value associated with the key, or None if the key doesn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def get(self, key: str) -> RedisResponseType:
    """Retrieves the value of a key asynchronously.

    Args:
        key (str): The key to retrieve.

    Returns:
        RedisResponseType: The value associated with the key, or None if the key doesn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.mget abstractmethod async

mget(
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType

Gets the values of multiple keys asynchronously.

Parameters:

Name Type Description Default
keys RedisKeyType | Iterable[RedisKeyType]

A single key or iterable of keys.

required
*args bytes | str

Additional keys.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of values corresponding to the keys.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def mget(
    self,
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType:
    """Gets the values of multiple keys asynchronously.

    Args:
        keys (RedisKeyType | Iterable[RedisKeyType]): A single key or iterable of keys.
        *args (bytes | str): Additional keys.

    Returns:
        RedisResponseType: A list of values corresponding to the keys.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.mset abstractmethod async

mset(
    mapping: Mapping[RedisKeyType, bytes | str | float],
) -> RedisResponseType

Sets multiple keys to their respective values asynchronously.

Parameters:

Name Type Description Default
mapping Mapping[RedisKeyType, bytes | str | float]

A mapping of keys to values.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Typically "OK" on success.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
    """Sets multiple keys to their respective values asynchronously.

    Args:
        mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of keys to values.

    Returns:
        RedisResponseType: Typically "OK" on success.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.keys abstractmethod async

keys(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Returns all keys matching a pattern asynchronously.

Parameters:

Name Type Description Default
pattern RedisPatternType

The pattern to match keys against. Defaults to "*".

'*'
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of matching keys.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Returns all keys matching a pattern asynchronously.

    Args:
        pattern (RedisPatternType): The pattern to match keys against. Defaults to "*".
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: A list of matching keys.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.getset abstractmethod async

getset(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Sets a key to a value and returns its old value asynchronously.

Parameters:

Name Type Description Default
key RedisKeyType

The key to set.

required
value bytes | str | float

The new value to set.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The old value of the key, or None if it didn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Sets a key to a value and returns its old value asynchronously.

    Args:
        key (RedisKeyType): The key to set.
        value (bytes | str | float): The new value to set.

    Returns:
        RedisResponseType: The old value of the key, or None if it didn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.getdel abstractmethod async

getdel(key: bytes | str) -> RedisResponseType

Gets the value of a key and deletes it asynchronously.

Parameters:

Name Type Description Default
key bytes | str

The key to get and delete.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key before deletion, or None if it didn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def getdel(self, key: bytes | str) -> RedisResponseType:
    """Gets the value of a key and deletes it asynchronously.

    Args:
        key (bytes | str): The key to get and delete.

    Returns:
        RedisResponseType: The value of the key before deletion, or None if it didn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.exists abstractmethod async

exists(*names: bytes | str) -> RedisResponseType

Checks if one or more keys exist asynchronously.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of keys to check.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of keys that exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def exists(self, *names: bytes | str) -> RedisResponseType:
    """Checks if one or more keys exist asynchronously.

    Args:
        *names (bytes | str): Variable number of keys to check.

    Returns:
        RedisResponseType: The number of keys that exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.delete abstractmethod async

delete(*names: bytes | str) -> RedisResponseType

Deletes one or more keys asynchronously.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of keys to delete.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of keys deleted.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def delete(self, *names: bytes | str) -> RedisResponseType:
    """Deletes one or more keys asynchronously.

    Args:
        *names (bytes | str): Variable number of keys to delete.

    Returns:
        RedisResponseType: The number of keys deleted.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.append abstractmethod async

append(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Appends a value to a key's string value asynchronously.

Parameters:

Name Type Description Default
key RedisKeyType

The key to append to.

required
value bytes | str | float

The value to append.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The length of the string after appending.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Appends a value to a key's string value asynchronously.

    Args:
        key (RedisKeyType): The key to append to.
        value (bytes | str | float): The value to append.

    Returns:
        RedisResponseType: The length of the string after appending.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.ttl abstractmethod async

ttl(name: bytes | str) -> RedisResponseType

Gets the remaining time to live of a key in seconds asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The time to live in seconds, or -1 if no TTL, -2 if key doesn't exist.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def ttl(self, name: bytes | str) -> RedisResponseType:
    """Gets the remaining time to live of a key in seconds asynchronously.

    Args:
        name (bytes | str): The key to check.

    Returns:
        RedisResponseType: The time to live in seconds, or -1 if no TTL, -2 if key doesn't exist.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.type abstractmethod async

type(name: bytes | str) -> RedisResponseType

Determines the type of value stored at a key asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The type of the key's value (e.g., "string", "list", etc.).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def type(self, name: bytes | str) -> RedisResponseType:
    """Determines the type of value stored at a key asynchronously.

    Args:
        name (bytes | str): The key to check.

    Returns:
        RedisResponseType: The type of the key's value (e.g., "string", "list", etc.).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.llen abstractmethod async

llen(name: str) -> RedisIntegerResponseType

Gets the length of a list asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of items in the list.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def llen(self, name: str) -> RedisIntegerResponseType:
    """Gets the length of a list asynchronously.

    Args:
        name (str): The key of the list.

    Returns:
        RedisIntegerResponseType: The number of items in the list.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.lpop abstractmethod async

lpop(name: str, count: int | None = None) -> Any

Removes and returns the first element(s) of a list asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required
count int

Number of elements to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
Any Any

The popped element(s), or None if the list is empty.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def lpop(self, name: str, count: int | None = None) -> Any:
    """Removes and returns the first element(s) of a list asynchronously.

    Args:
        name (str): The key of the list.
        count (int, optional): Number of elements to pop. Defaults to None (pops 1).

    Returns:
        Any: The popped element(s), or None if the list is empty.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.lpush abstractmethod async

lpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Pushes one or more values to the start of a list asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The length of the list after the push.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Pushes one or more values to the start of a list asynchronously.

    Args:
        name (str): The key of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: The length of the list after the push.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.lrange abstractmethod async

lrange(
    name: str, start: int, end: int
) -> RedisListResponseType

Gets a range of elements from a list asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required
start int

The starting index (inclusive).

required
end int

The ending index (inclusive).

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of elements in the specified range.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
    """Gets a range of elements from a list asynchronously.

    Args:
        name (str): The key of the list.
        start (int): The starting index (inclusive).
        end (int): The ending index (inclusive).

    Returns:
        RedisListResponseType: A list of elements in the specified range.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.lrem abstractmethod async

lrem(
    name: str, count: int, value: str
) -> RedisIntegerResponseType

Removes occurrences of a value from a list asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required
count int

Number of occurrences to remove (0 for all).

required
value str

The value to remove.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of elements removed.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
    """Removes occurrences of a value from a list asynchronously.

    Args:
        name (str): The key of the list.
        count (int): Number of occurrences to remove (0 for all).
        value (str): The value to remove.

    Returns:
        RedisIntegerResponseType: The number of elements removed.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.lset abstractmethod async

lset(name: str, index: int, value: str) -> bool

Sets the value of an element in a list by index asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required
index int

The index to set.

required
value str

The new value.

required

Returns:

Name Type Description
bool bool

True if successful.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def lset(self, name: str, index: int, value: str) -> bool:
    """Sets the value of an element in a list by index asynchronously.

    Args:
        name (str): The key of the list.
        index (int): The index to set.
        value (str): The new value.

    Returns:
        bool: True if successful.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.rpop abstractmethod async

rpop(name: str, count: int | None = None) -> Any

Removes and returns the last element(s) of a list asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required
count int

Number of elements to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
Any Any

The popped element(s), or None if the list is empty.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def rpop(self, name: str, count: int | None = None) -> Any:
    """Removes and returns the last element(s) of a list asynchronously.

    Args:
        name (str): The key of the list.
        count (int, optional): Number of elements to pop. Defaults to None (pops 1).

    Returns:
        Any: The popped element(s), or None if the list is empty.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.rpush abstractmethod async

rpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Pushes one or more values to the end of a list asynchronously.

Parameters:

Name Type Description Default
name str

The key of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The length of the list after the push.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Pushes one or more values to the end of a list asynchronously.

    Args:
        name (str): The key of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: The length of the list after the push.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.scan abstractmethod async

scan(
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType

Iterates over keys in the database incrementally asynchronously.

Parameters:

Name Type Description Default
cursor int

The cursor position to start scanning. Defaults to 0.

0
match bytes | str

Pattern to match keys against.

None
count int

Hint for number of keys to return per iteration.

None
_type str

Filter by type (e.g., "string", "list").

None
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

A tuple of (new_cursor, list_of_keys).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def scan(
    self,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType:
    """Iterates over keys in the database incrementally asynchronously.

    Args:
        cursor (int): The cursor position to start scanning. Defaults to 0.
        match (bytes | str, optional): Pattern to match keys against.
        count (int, optional): Hint for number of keys to return per iteration.
        _type (str, optional): Filter by type (e.g., "string", "list").
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: A tuple of (new_cursor, list_of_keys).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.scan_iter abstractmethod async

scan_iter(
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator

Provides an iterator over keys in the database asynchronously.

Parameters:

Name Type Description Default
match bytes | str

Pattern to match keys against.

None
count int

Hint for number of keys to return per iteration.

None
_type str

Filter by type (e.g., "string", "list").

None
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
Iterator Iterator

An iterator yielding keys.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def scan_iter(
    self,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator:
    """Provides an iterator over keys in the database asynchronously.

    Args:
        match (bytes | str, optional): Pattern to match keys against.
        count (int, optional): Hint for number of keys to return per iteration.
        _type (str, optional): Filter by type (e.g., "string", "list").
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        Iterator: An iterator yielding keys.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.sscan abstractmethod async

sscan(
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType

Iterates over members of a set incrementally asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the set.

required
cursor int

The cursor position to start scanning. Defaults to 0.

0
match bytes | str

Pattern to match members against.

None
count int

Hint for number of members to return per iteration.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A tuple of (new_cursor, list_of_members).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def sscan(
    self,
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType:
    """Iterates over members of a set incrementally asynchronously.

    Args:
        name (RedisKeyType): The key of the set.
        cursor (int): The cursor position to start scanning. Defaults to 0.
        match (bytes | str, optional): Pattern to match members against.
        count (int, optional): Hint for number of members to return per iteration.

    Returns:
        RedisResponseType: A tuple of (new_cursor, list_of_members).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.sscan_iter abstractmethod async

sscan_iter(
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator

Provides an iterator over members of a set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the set.

required
match bytes | str

Pattern to match members against.

None
count int

Hint for number of members to return per iteration.

None

Returns:

Name Type Description
Iterator Iterator

An iterator yielding set members.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def sscan_iter(
    self,
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator:
    """Provides an iterator over members of a set asynchronously.

    Args:
        name (RedisKeyType): The key of the set.
        match (bytes | str, optional): Pattern to match members against.
        count (int, optional): Hint for number of members to return per iteration.

    Returns:
        Iterator: An iterator yielding set members.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.sadd abstractmethod async

sadd(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Adds one or more members to a set asynchronously.

Parameters:

Name Type Description Default
name str

The key of the set.

required
*values bytes | str | float

Members to add.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of members added (excluding duplicates).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Adds one or more members to a set asynchronously.

    Args:
        name (str): The key of the set.
        *values (bytes | str | float): Members to add.

    Returns:
        RedisIntegerResponseType: The number of members added (excluding duplicates).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.scard abstractmethod async

scard(name: str) -> RedisIntegerResponseType

Gets the number of members in a set asynchronously.

Parameters:

Name Type Description Default
name str

The key of the set.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The cardinality (size) of the set.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def scard(self, name: str) -> RedisIntegerResponseType:
    """Gets the number of members in a set asynchronously.

    Args:
        name (str): The key of the set.

    Returns:
        RedisIntegerResponseType: The cardinality (size) of the set.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.sismember abstractmethod async

sismember(name: str, value: str) -> bool

Checks if a value is a member of a set asynchronously.

Parameters:

Name Type Description Default
name str

The key of the set.

required
value str

The value to check.

required

Returns:

Name Type Description
bool bool

True if the value is a member, False otherwise.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def sismember(self, name: str, value: str) -> bool:
    """Checks if a value is a member of a set asynchronously.

    Args:
        name (str): The key of the set.
        value (str): The value to check.

    Returns:
        bool: True if the value is a member, False otherwise.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.smembers abstractmethod async

smembers(name: str) -> RedisSetResponseType

Gets all members of a set asynchronously.

Parameters:

Name Type Description Default
name str

The key of the set.

required

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

A set of all members.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def smembers(self, name: str) -> RedisSetResponseType:
    """Gets all members of a set asynchronously.

    Args:
        name (str): The key of the set.

    Returns:
        RedisSetResponseType: A set of all members.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.spop abstractmethod async

spop(
    name: str, count: int | None = None
) -> bytes | float | int | str | list | None

Removes and returns one or more random members from a set asynchronously.

Parameters:

Name Type Description Default
name str

The key of the set.

required
count int

Number of members to pop. Defaults to None (pops 1).

None

Returns:

Type Description
bytes | float | int | str | list | None

bytes | float | int | str | list | None: The popped member(s), or None if the set is empty.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
    """Removes and returns one or more random members from a set asynchronously.

    Args:
        name (str): The key of the set.
        count (int, optional): Number of members to pop. Defaults to None (pops 1).

    Returns:
        bytes | float | int | str | list | None: The popped member(s), or None if the set is empty.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.srem abstractmethod async

srem(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Removes one or more members from a set asynchronously.

Parameters:

Name Type Description Default
name str

The key of the set.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of members removed.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Removes one or more members from a set asynchronously.

    Args:
        name (str): The key of the set.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisIntegerResponseType: The number of members removed.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.sunion abstractmethod async

sunion(
    keys: RedisKeyType, *args: bytes | str
) -> RedisSetResponseType

Gets the union of multiple sets asynchronously.

Parameters:

Name Type Description Default
keys RedisKeyType

Name of the first key.

required
*args bytes | str

Additional key names.

()

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

A set containing members of the resulting union.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
    """Gets the union of multiple sets asynchronously.

    Args:
        keys (RedisKeyType): Name of the first key.
        *args (bytes | str): Additional key names.

    Returns:
        RedisSetResponseType: A set containing members of the resulting union.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zadd abstractmethod async

zadd(
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType

Adds members with scores to a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
mapping Mapping[RedisKeyType, bytes | str | float]

A mapping of members to scores.

required
nx bool

If True, only add new elements. Defaults to False.

False
xx bool

If True, only update existing elements. Defaults to False.

False
ch bool

If True, return the number of changed elements. Defaults to False.

False
incr bool

If True, increment scores instead of setting. Defaults to False.

False
gt bool

If True, only update if new score is greater. Defaults to False.

False
lt bool

If True, only update if new score is less. Defaults to False.

False

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of elements added or updated.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zadd(
    self,
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType:
    """Adds members with scores to a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        mapping (Mapping[RedisKeyType, bytes | str | float]): A mapping of members to scores.
        nx (bool): If True, only add new elements. Defaults to False.
        xx (bool): If True, only update existing elements. Defaults to False.
        ch (bool): If True, return the number of changed elements. Defaults to False.
        incr (bool): If True, increment scores instead of setting. Defaults to False.
        gt (bool): If True, only update if new score is greater. Defaults to False.
        lt (bool): If True, only update if new score is less. Defaults to False.

    Returns:
        RedisResponseType: The number of elements added or updated.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zcard abstractmethod async

zcard(name: bytes | str) -> RedisResponseType

Gets the number of members in a sorted set asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key of the sorted set.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The cardinality (size) of the sorted set.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zcard(self, name: bytes | str) -> RedisResponseType:
    """Gets the number of members in a sorted set asynchronously.

    Args:
        name (bytes | str): The key of the sorted set.

    Returns:
        RedisResponseType: The cardinality (size) of the sorted set.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zcount abstractmethod async

zcount(
    name: RedisKeyType, min: float | str, max: float | str
) -> RedisResponseType

Counts members in a sorted set within a score range asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
min float | str

The minimum score (inclusive).

required
max float | str

The maximum score (inclusive).

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of members within the score range.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
    """Counts members in a sorted set within a score range asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        min (float | str): The minimum score (inclusive).
        max (float | str): The maximum score (inclusive).

    Returns:
        RedisResponseType: The number of members within the score range.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zpopmax abstractmethod async

zpopmax(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Removes and returns members with the highest scores from a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
count int

Number of members to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of (member, score) tuples popped.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Removes and returns members with the highest scores from a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        count (int, optional): Number of members to pop. Defaults to None (pops 1).

    Returns:
        RedisResponseType: A list of (member, score) tuples popped.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zpopmin abstractmethod async

zpopmin(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Removes and returns members with the lowest scores from a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
count int

Number of members to pop. Defaults to None (pops 1).

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of (member, score) tuples popped.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Removes and returns members with the lowest scores from a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        count (int, optional): Number of members to pop. Defaults to None (pops 1).

    Returns:
        RedisResponseType: A list of (member, score) tuples popped.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zrange abstractmethod async

zrange(
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType

Gets a range of members from a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
start int

The starting index or score (depending on byscore).

required
end int

The ending index or score (depending on byscore).

required
desc bool

If True, sort in descending order. Defaults to False.

False
withscores bool

If True, return scores with members. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float
byscore bool

If True, range by score instead of rank. Defaults to False.

False
bylex bool

If True, range by lexicographical order. Defaults to False.

False
offset int

Offset for byscore or bylex.

None
num int

Number of elements for byscore or bylex.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of members (and scores if withscores=True).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType:
    """Gets a range of members from a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        start (int): The starting index or score (depending on byscore).
        end (int): The ending index or score (depending on byscore).
        desc (bool): If True, sort in descending order. Defaults to False.
        withscores (bool): If True, return scores with members. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.
        byscore (bool): If True, range by score instead of rank. Defaults to False.
        bylex (bool): If True, range by lexicographical order. Defaults to False.
        offset (int, optional): Offset for byscore or bylex.
        num (int, optional): Number of elements for byscore or bylex.

    Returns:
        RedisResponseType: A list of members (and scores if withscores=True).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zrevrange abstractmethod async

zrevrange(
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Gets a range of members from a sorted set in reverse order asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
start int

The starting index.

required
end int

The ending index.

required
withscores bool

If True, return scores with members. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of members (and scores if withscores=True).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zrevrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Gets a range of members from a sorted set in reverse order asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        start (int): The starting index.
        end (int): The ending index.
        withscores (bool): If True, return scores with members. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: A list of members (and scores if withscores=True).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zrangebyscore abstractmethod async

zrangebyscore(
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Gets members from a sorted set by score range asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
min float | str

The minimum score (inclusive).

required
max float | str

The maximum score (inclusive).

required
start int

Starting offset.

None
num int

Number of elements to return.

None
withscores bool

If True, return scores with members. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of members (and scores if withscores=True).

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zrangebyscore(
    self,
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Gets members from a sorted set by score range asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        min (float | str): The minimum score (inclusive).
        max (float | str): The maximum score (inclusive).
        start (int, optional): Starting offset.
        num (int, optional): Number of elements to return.
        withscores (bool): If True, return scores with members. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: A list of members (and scores if withscores=True).

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zrank abstractmethod async

zrank(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Gets the rank of a member in a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
value bytes | str | float

The member to find.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The rank (index) of the member, or None if not found.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Gets the rank of a member in a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        value (bytes | str | float): The member to find.

    Returns:
        RedisResponseType: The rank (index) of the member, or None if not found.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zrem abstractmethod async

zrem(
    name: RedisKeyType, *values: bytes | str | float
) -> RedisResponseType

Removes one or more members from a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of members removed.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
    """Removes one or more members from a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisResponseType: The number of members removed.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zscore abstractmethod async

zscore(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Gets the score of a member in a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
value bytes | str | float

The member to check.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The score of the member, or None if not found.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Gets the score of a member in a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        value (bytes | str | float): The member to check.

    Returns:
        RedisResponseType: The score of the member, or None if not found.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hdel abstractmethod async

hdel(
    name: str, *keys: str | bytes
) -> RedisIntegerResponseType

Deletes one or more fields from a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
*keys str | bytes

Fields to delete.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of fields deleted.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
    """Deletes one or more fields from a hash asynchronously.

    Args:
        name (str): The key of the hash.
        *keys (str | bytes): Fields to delete.

    Returns:
        RedisIntegerResponseType: The number of fields deleted.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hexists abstractmethod async

hexists(name: str, key: str) -> bool

Checks if a field exists in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
key str

The field to check.

required

Returns:

Name Type Description
bool bool

True if the field exists, False otherwise.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hexists(self, name: str, key: str) -> bool:
    """Checks if a field exists in a hash asynchronously.

    Args:
        name (str): The key of the hash.
        key (str): The field to check.

    Returns:
        bool: True if the field exists, False otherwise.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hget abstractmethod async

hget(name: str, key: str) -> str | None

Gets the value of a field in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
key str

The field to get.

required

Returns:

Type Description
str | None

str | None: The value of the field, or None if not found.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hget(self, name: str, key: str) -> str | None:
    """Gets the value of a field in a hash asynchronously.

    Args:
        name (str): The key of the hash.
        key (str): The field to get.

    Returns:
        str | None: The value of the field, or None if not found.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hgetall abstractmethod async

hgetall(name: str) -> dict[str, Any]

Gets all fields and values in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: A dictionary of field/value pairs.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hgetall(self, name: str) -> dict[str, Any]:
    """Gets all fields and values in a hash asynchronously.

    Args:
        name (str): The key of the hash.

    Returns:
        dict[str, Any]: A dictionary of field/value pairs.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hkeys abstractmethod async

hkeys(name: str) -> RedisListResponseType

Gets all fields in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of fields in the hash.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hkeys(self, name: str) -> RedisListResponseType:
    """Gets all fields in a hash asynchronously.

    Args:
        name (str): The key of the hash.

    Returns:
        RedisListResponseType: A list of fields in the hash.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hlen abstractmethod async

hlen(name: str) -> RedisIntegerResponseType

Gets the number of fields in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of fields in the hash.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hlen(self, name: str) -> RedisIntegerResponseType:
    """Gets the number of fields in a hash asynchronously.

    Args:
        name (str): The key of the hash.

    Returns:
        RedisIntegerResponseType: The number of fields in the hash.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hset abstractmethod async

hset(
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType

Sets one or more fields in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
key str | bytes

A single field to set.

None
value str | bytes

The value for the single field.

None
mapping dict

A dictionary of field/value pairs.

None
items list

A list of field/value pairs.

None

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

The number of fields added or updated.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hset(
    self,
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType:
    """Sets one or more fields in a hash asynchronously.

    Args:
        name (str): The key of the hash.
        key (str | bytes, optional): A single field to set.
        value (str | bytes, optional): The value for the single field.
        mapping (dict, optional): A dictionary of field/value pairs.
        items (list, optional): A list of field/value pairs.

    Returns:
        RedisIntegerResponseType: The number of fields added or updated.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hmget abstractmethod async

hmget(
    name: str, keys: list, *args: str | bytes
) -> RedisListResponseType

Gets the values of multiple fields in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required
keys list

A list of fields to get.

required
*args str | bytes

Additional fields to get.

()

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of values for the specified fields.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
    """Gets the values of multiple fields in a hash asynchronously.

    Args:
        name (str): The key of the hash.
        keys (list): A list of fields to get.
        *args (str | bytes): Additional fields to get.

    Returns:
        RedisListResponseType: A list of values for the specified fields.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.hvals abstractmethod async

hvals(name: str) -> RedisListResponseType

Gets all values in a hash asynchronously.

Parameters:

Name Type Description Default
name str

The key of the hash.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

A list of values in the hash.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def hvals(self, name: str) -> RedisListResponseType:
    """Gets all values in a hash asynchronously.

    Args:
        name (str): The key of the hash.

    Returns:
        RedisListResponseType: A list of values in the hash.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.publish abstractmethod async

publish(
    channel: RedisKeyType,
    message: bytes | str,
    **kwargs: Any,
) -> RedisResponseType

Publishes a message to a channel asynchronously.

Parameters:

Name Type Description Default
channel RedisKeyType

The channel to publish to.

required
message bytes | str

The message to publish.

required
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

The number of subscribers that received the message.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
    """Publishes a message to a channel asynchronously.

    Args:
        channel (RedisKeyType): The channel to publish to.
        message (bytes | str): The message to publish.
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: The number of subscribers that received the message.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.pubsub_channels abstractmethod async

pubsub_channels(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Lists active channels matching a pattern asynchronously.

Parameters:

Name Type Description Default
pattern RedisPatternType

The pattern to match channels. Defaults to "*".

'*'
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

A list of active channels.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Lists active channels matching a pattern asynchronously.

    Args:
        pattern (RedisPatternType): The pattern to match channels. Defaults to "*".
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        RedisResponseType: A list of active channels.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.zincrby abstractmethod async

zincrby(
    name: RedisKeyType,
    amount: float,
    value: bytes | str | float,
) -> RedisResponseType

Increments the score of a member in a sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key of the sorted set.

required
amount float

The amount to increment by.

required
value bytes | str | float

The member to increment.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new score of the member.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
    """Increments the score of a member in a sorted set asynchronously.

    Args:
        name (RedisKeyType): The key of the sorted set.
        amount (float): The amount to increment by.
        value (bytes | str | float): The member to increment.

    Returns:
        RedisResponseType: The new score of the member.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.pubsub abstractmethod async

pubsub(**kwargs: Any) -> Any

Returns a pub/sub object for subscribing to channels asynchronously.

Parameters:

Name Type Description Default
**kwargs Any

Additional arguments for the underlying implementation.

{}

Returns:

Name Type Description
Any Any

A pub/sub object.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def pubsub(self, **kwargs: Any) -> Any:
    """Returns a pub/sub object for subscribing to channels asynchronously.

    Args:
        **kwargs (Any): Additional arguments for the underlying implementation.

    Returns:
        Any: A pub/sub object.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.get_pipeline abstractmethod async

get_pipeline(
    transaction: Any = True, shard_hint: Any = None
) -> Any

Returns a pipeline object for batching commands asynchronously.

Parameters:

Name Type Description Default
transaction Any

If True, execute commands in a transaction. Defaults to True.

True
shard_hint Any

Hint for sharding in clustered Redis.

None

Returns:

Name Type Description
Any Any

A pipeline object.

Raises:

Type Description
NotImplementedError

If not implemented by the subclass.

Source code in archipy/adapters/redis/ports.py
@abstractmethod
async def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> Any:
    """Returns a pipeline object for batching commands asynchronously.

    Args:
        transaction (Any): If True, execute commands in a transaction. Defaults to True.
        shard_hint (Any, optional): Hint for sharding in clustered Redis.

    Returns:
        Any: A pipeline object.

    Raises:
        NotImplementedError: If not implemented by the subclass.
    """
    raise NotImplementedError

archipy.adapters.redis.ports.AsyncRedisPort.cluster_info async

cluster_info() -> RedisResponseType

Get cluster information asynchronously.

Returns:

Name Type Description
RedisResponseType RedisResponseType

Cluster information or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
async def cluster_info(self) -> RedisResponseType:
    """Get cluster information asynchronously.

    Returns:
        RedisResponseType: Cluster information or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.AsyncRedisPort.cluster_nodes async

cluster_nodes() -> RedisResponseType

Get cluster nodes information asynchronously.

Returns:

Name Type Description
RedisResponseType RedisResponseType

Cluster nodes info or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
async def cluster_nodes(self) -> RedisResponseType:
    """Get cluster nodes information asynchronously.

    Returns:
        RedisResponseType: Cluster nodes info or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.AsyncRedisPort.cluster_slots async

cluster_slots() -> RedisResponseType

Get cluster slots mapping asynchronously.

Returns:

Name Type Description
RedisResponseType RedisResponseType

Slots mapping or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
async def cluster_slots(self) -> RedisResponseType:
    """Get cluster slots mapping asynchronously.

    Returns:
        RedisResponseType: Slots mapping or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.AsyncRedisPort.cluster_key_slot async

cluster_key_slot(key: str) -> RedisResponseType

Get the hash slot for a key asynchronously.

Parameters:

Name Type Description Default
key str

The key to get slot for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Key slot or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
async def cluster_key_slot(self, key: str) -> RedisResponseType:
    """Get the hash slot for a key asynchronously.

    Args:
        key (str): The key to get slot for.

    Returns:
        RedisResponseType: Key slot or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.AsyncRedisPort.cluster_count_keys_in_slot async

cluster_count_keys_in_slot(slot: int) -> RedisResponseType

Count keys in a specific slot asynchronously.

Parameters:

Name Type Description Default
slot int

The slot number.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Key count or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
async def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
    """Count keys in a specific slot asynchronously.

    Args:
        slot (int): The slot number.

    Returns:
        RedisResponseType: Key count or None for standalone mode.
    """
    return None

archipy.adapters.redis.ports.AsyncRedisPort.cluster_get_keys_in_slot async

cluster_get_keys_in_slot(
    slot: int, count: int
) -> RedisResponseType

Get keys in a specific slot asynchronously.

Parameters:

Name Type Description Default
slot int

The slot number.

required
count int

Maximum number of keys to return.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of keys or None for standalone mode.

Source code in archipy/adapters/redis/ports.py
async def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
    """Get keys in a specific slot asynchronously.

    Args:
        slot (int): The slot number.
        count (int): Maximum number of keys to return.

    Returns:
        RedisResponseType: List of keys or None for standalone mode.
    """
    return None

options: show_root_toc_entry: false heading_level: 3

Adapters

Concrete Redis adapter wrapping the Redis client with ArchiPy conventions for cache operations, pub/sub, and key-value management.

archipy.adapters.redis.adapters.RedisAdapter

Bases: RedisPort

Adapter for Redis operations providing a standardized interface.

This adapter implements the RedisPort interface to provide a consistent way to interact with Redis, abstracting the underlying Redis client implementation. It supports all common Redis operations including key-value operations, lists, sets, sorted sets, hashes, and pub/sub functionality.

The adapter maintains separate connections for read and write operations, which can be used to implement read replicas for better performance.

Parameters:

Name Type Description Default
redis_config RedisConfig

Configuration settings for Redis. If None, retrieves from global config. Defaults to None.

None
Source code in archipy/adapters/redis/adapters.py
  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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
class RedisAdapter(RedisPort):
    """Adapter for Redis operations providing a standardized interface.

    This adapter implements the RedisPort interface to provide a consistent
    way to interact with Redis, abstracting the underlying Redis client
    implementation. It supports all common Redis operations including key-value
    operations, lists, sets, sorted sets, hashes, and pub/sub functionality.

    The adapter maintains separate connections for read and write operations,
    which can be used to implement read replicas for better performance.

    Args:
        redis_config (RedisConfig, optional): Configuration settings for Redis.
            If None, retrieves from global config. Defaults to None.
    """

    def __init__(self, redis_config: RedisConfig | None = None) -> None:
        """Initialize the RedisAdapter with configuration settings.

        Args:
            redis_config (RedisConfig, optional): Configuration settings for Redis.
                If None, retrieves from global config. Defaults to None.
        """
        configs: RedisConfig = BaseConfig.global_config().REDIS if redis_config is None else redis_config
        self._set_clients(configs)

    def _set_clients(self, configs: RedisConfig) -> None:
        """Set up Redis clients based on the configured mode.

        Args:
            configs (RedisConfig): Configuration settings for Redis.
        """
        match configs.MODE:
            case RedisMode.CLUSTER:
                self._set_cluster_clients(configs)
            case RedisMode.SENTINEL:
                self._set_sentinel_clients(configs)
            case RedisMode.STANDALONE:
                self._set_standalone_clients(configs)
            case _:
                raise ValueError(f"Unsupported Redis mode: {configs.MODE}")

    def _set_standalone_clients(self, configs: RedisConfig) -> None:
        """Set up standalone Redis clients.

        Args:
            configs (RedisConfig): Configuration settings for Redis.
        """
        if redis_master_host := configs.MASTER_HOST:
            self.client: Redis | RedisCluster = self._get_client(redis_master_host, configs)
        if redis_slave_host := configs.SLAVE_HOST:
            self.read_only_client: Redis | RedisCluster = self._get_client(redis_slave_host, configs)
        else:
            self.read_only_client = self.client

    def _set_cluster_clients(self, configs: RedisConfig) -> None:
        """Set up Redis cluster clients.

        Args:
            configs (RedisConfig): Configuration settings for Redis cluster.
        """
        from redis.cluster import ClusterNode

        startup_nodes = []
        for node in configs.CLUSTER_NODES:
            if ":" in node:
                host, port = node.split(":", 1)
                startup_nodes.append(ClusterNode(host, int(port)))
            else:
                startup_nodes.append(ClusterNode(node, configs.PORT))

        cluster_client = RedisCluster(
            startup_nodes=startup_nodes,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
            max_connections=configs.MAX_CONNECTIONS,
            socket_connect_timeout=configs.SOCKET_CONNECT_TIMEOUT,
            socket_timeout=configs.SOCKET_TIMEOUT,
            health_check_interval=configs.HEALTH_CHECK_INTERVAL,
            read_from_replicas=configs.CLUSTER_READ_FROM_REPLICAS,
            require_full_coverage=configs.CLUSTER_REQUIRE_FULL_COVERAGE,
        )

        # In cluster mode, both clients point to the cluster
        self.client: Redis | RedisCluster = cluster_client
        self.read_only_client: Redis | RedisCluster = cluster_client

    def _set_sentinel_clients(self, configs: RedisConfig) -> None:
        """Set up Redis sentinel clients.

        Args:
            configs (RedisConfig): Configuration settings for Redis sentinel.
        """
        sentinel_service_name = configs.SENTINEL_SERVICE_NAME
        if not sentinel_service_name:
            raise ValueError("SENTINEL_SERVICE_NAME must be provided for sentinel mode")
        sentinel_nodes = [(node.split(":")[0], int(node.split(":")[1])) for node in configs.SENTINEL_NODES]

        sentinel = Sentinel(
            sentinel_nodes,
            socket_timeout=configs.SENTINEL_SOCKET_TIMEOUT,
            password=configs.PASSWORD,
        )

        self.client = sentinel.master_for(
            sentinel_service_name,
            socket_timeout=configs.SOCKET_TIMEOUT,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
        )

        self.read_only_client = sentinel.slave_for(
            sentinel_service_name,
            socket_timeout=configs.SOCKET_TIMEOUT,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
        )

    # Override cluster methods to work when in cluster mode
    @override
    def cluster_info(self) -> RedisResponseType:
        """Get cluster information."""
        if isinstance(self.client, RedisCluster):
            return self.client.cluster_info()
        return None

    @override
    def cluster_nodes(self) -> RedisResponseType:
        """Get cluster nodes information."""
        if isinstance(self.client, RedisCluster):
            return self.client.cluster_nodes()
        return None

    @override
    def cluster_slots(self) -> RedisResponseType:
        """Get cluster slots mapping."""
        if isinstance(self.client, RedisCluster):
            return self.client.cluster_slots()
        return None

    @override
    def cluster_key_slot(self, key: str) -> RedisResponseType:
        """Get the hash slot for a key."""
        if isinstance(self.client, RedisCluster):
            return self.client.cluster_keyslot(key)
        return None

    @override
    def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
        """Count keys in a specific slot."""
        if isinstance(self.client, RedisCluster):
            return self.client.cluster_countkeysinslot(slot)
        return None

    @override
    def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
        """Get keys in a specific slot."""
        if isinstance(self.client, RedisCluster):
            return self.client.cluster_get_keys_in_slot(slot, count)
        return None

    @staticmethod
    def _get_client(host: str, configs: RedisConfig) -> Redis:
        """Create a Redis client with the specified configuration.

        Args:
            host (str): Redis host address.
            configs (RedisConfig): Configuration settings for Redis.

        Returns:
            Redis: Configured Redis client instance.
        """
        return Redis(
            host=host,
            port=configs.PORT,
            db=configs.DATABASE,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
            health_check_interval=configs.HEALTH_CHECK_INTERVAL,
        )

    @staticmethod
    def _ensure_sync_int(value: int | Awaitable[int]) -> int:
        """Ensure a synchronous integer result, raising if awaitable."""
        if isinstance(value, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return int(value)

    @override
    def pttl(self, name: bytes | str) -> RedisResponseType:
        """Get the time to live in milliseconds for a key.

        Args:
            name (bytes | str): The key name.

        Returns:
            RedisResponseType: Time to live in milliseconds.
        """
        return self.read_only_client.pttl(name)

    @override
    def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
        """Increment the integer value of a key by the given amount.

        Args:
            name (RedisKeyType): The key name.
            amount (int): Amount to increment by. Defaults to 1.

        Returns:
            RedisResponseType: The new value after increment.
        """
        return self.client.incrby(name, amount)

    @override
    def set(
        self,
        name: RedisKeyType,
        value: RedisSetType,
        ex: RedisExpiryType | None = None,
        px: RedisExpiryType | None = None,
        nx: bool = False,
        xx: bool = False,
        keepttl: bool = False,
        get: bool = False,
        exat: RedisAbsExpiryType | None = None,
        pxat: RedisAbsExpiryType | None = None,
    ) -> RedisResponseType:
        """Set the value of a key with optional expiration and conditions.

        Args:
            name (RedisKeyType): The key name.
            value (RedisSetType): The value to set.
            ex (RedisExpiryType | None): Expire time in seconds.
            px (RedisExpiryType | None): Expire time in milliseconds.
            nx (bool): Only set if key doesn't exist.
            xx (bool): Only set if key exists.
            keepttl (bool): Retain the TTL from the previous value.
            get (bool): Return the old value.
            exat (RedisAbsExpiryType | None): Absolute expiration time in seconds.
            pxat (RedisAbsExpiryType | None): Absolute expiration time in milliseconds.

        Returns:
            RedisResponseType: Result of the operation.
        """
        return self.client.set(name, value, ex, px, nx, xx, keepttl, get, exat, pxat)

    @override
    def get(self, key: str) -> RedisResponseType:
        """Get the value of a key.

        Args:
            key (str): The key name.

        Returns:
            RedisResponseType: The value of the key or None if not exists.
        """
        return self.read_only_client.get(key)

    @override
    def mget(
        self,
        keys: RedisKeyType | Iterable[RedisKeyType],
        *args: bytes | str,
    ) -> RedisResponseType:
        """Get the values of multiple keys.

        Args:
            keys (RedisKeyType | Iterable[RedisKeyType]): Single key or iterable of keys.
            *args (bytes | str): Additional keys.

        Returns:
            RedisResponseType: List of values.
        """
        return self.read_only_client.mget(keys, *args)

    @override
    def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
        """Set multiple keys to their respective values.

        Args:
            mapping (Mapping[RedisKeyType, bytes | str | float]): Dictionary of key-value pairs.

        Returns:
            RedisResponseType: Always returns 'OK'.
        """
        # Convert Mapping to dict for type compatibility with Redis client
        dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
        return self.client.mset(dict_mapping)

    @override
    def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """Find all keys matching the given pattern.

        Args:
            pattern (RedisPatternType): Pattern to match keys against. Defaults to "*".
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: List of matching keys.
        """
        return self.read_only_client.keys(pattern, **kwargs)

    @override
    def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Set the value of a key and return its old value.

        Args:
            key (RedisKeyType): The key name.
            value (bytes | str | float): The new value.

        Returns:
            RedisResponseType: The previous value or None.
        """
        return self.client.getset(key, value)

    @override
    def getdel(self, key: bytes | str) -> RedisResponseType:
        """Get the value of a key and delete it.

        Args:
            key (bytes | str): The key name.

        Returns:
            RedisResponseType: The value of the key or None.
        """
        return self.client.getdel(key)

    @override
    def exists(self, *names: bytes | str) -> RedisResponseType:
        """Check if one or more keys exist.

        Args:
            *names (bytes | str): Variable number of key names.

        Returns:
            RedisResponseType: Number of keys that exist.
        """
        return self.read_only_client.exists(*names)

    @override
    def delete(self, *names: bytes | str) -> RedisResponseType:
        """Delete one or more keys.

        Args:
            *names (bytes | str): Variable number of key names.

        Returns:
            RedisResponseType: Number of keys deleted.
        """
        return self.client.delete(*names)

    @override
    def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Append a value to a key.

        Args:
            key (RedisKeyType): The key name.
            value (bytes | str | float): The value to append.

        Returns:
            RedisResponseType: Length of the string after append.
        """
        return self.client.append(key, value)

    @override
    def ttl(self, name: bytes | str) -> RedisResponseType:
        """Get the time to live in seconds for a key.

        Args:
            name (bytes | str): The key name.

        Returns:
            RedisResponseType: Time to live in seconds.
        """
        return self.read_only_client.ttl(name)

    @override
    def type(self, name: bytes | str) -> RedisResponseType:
        """Determine the type stored at key.

        Args:
            name (bytes | str): The key name.

        Returns:
            RedisResponseType: Type of the key's value.
        """
        return self.read_only_client.type(name)

    @override
    def llen(self, name: str) -> RedisIntegerResponseType:
        """Get the length of a list.

        Args:
            name (str): The key name of the list.

        Returns:
            RedisIntegerResponseType: Length of the list.
        """
        client: Redis | RedisCluster = self.read_only_client
        result = client.llen(name)
        return self._ensure_sync_int(result)

    @override
    def lpop(self, name: str, count: int | None = None) -> Any:
        """Remove and return elements from the left of a list.

        Args:
            name (str): The key name of the list.
            count (int | None): Number of elements to pop. Defaults to None.

        Returns:
            Any: Popped element(s) or None if list is empty.
        """
        return self.client.lpop(name, count)

    @override
    def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Push elements to the left of a list.

        Args:
            name (str): The key name of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: Length of the list after push.
        """
        result = self.client.lpush(name, *values)
        return self._ensure_sync_int(result)

    @override
    def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
        """Get a range of elements from a list.

        Args:
            name (str): The key name of the list.
            start (int): Start index.
            end (int): End index.

        Returns:
            RedisListResponseType: List of elements in the specified range.
        """
        result = self.read_only_client.lrange(name, start, end)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return list(result)

    @override
    def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
        """Remove elements from a list.

        Args:
            name (str): The key name of the list.
            count (int): Number of occurrences to remove.
            value (str): Value to remove.

        Returns:
            RedisIntegerResponseType: Number of elements removed.
        """
        result = self.client.lrem(name, count, value)
        return self._ensure_sync_int(result)

    @override
    def lset(self, name: str, index: int, value: str) -> bool:
        """Set the value of an element in a list by its index.

        Args:
            name (str): The key name of the list.
            index (int): Index of the element.
            value (str): New value.

        Returns:
            bool: True if successful.
        """
        return bool(self.client.lset(name, index, value))

    @override
    def rpop(self, name: str, count: int | None = None) -> Any:
        """Remove and return elements from the right of a list.

        Args:
            name (str): The key name of the list.
            count (int | None): Number of elements to pop. Defaults to None.

        Returns:
            Any: Popped element(s) or None if list is empty.
        """
        return self.client.rpop(name, count)

    @override
    def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Push elements to the right of a list.

        Args:
            name (str): The key name of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: Length of the list after push.
        """
        result = self.client.rpush(name, *values)
        return self._ensure_sync_int(result)

    @override
    def scan(
        self,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> RedisResponseType:
        """Scan keys in the database incrementally.

        Args:
            cursor (int): Cursor position. Defaults to 0.
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of keys to return. Defaults to None.
            _type (str | None): Filter by type. Defaults to None.
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: Tuple of cursor and list of keys.
        """
        return self.read_only_client.scan(cursor, match, count, _type, **kwargs)

    @override
    def scan_iter(
        self,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> Iterator:
        """Iterate over keys in the database.

        Args:
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of keys to return. Defaults to None.
            _type (str | None): Filter by type. Defaults to None.
            **kwargs (Any): Additional arguments.

        Returns:
            Iterator: Iterator over matching keys.
        """
        return self.read_only_client.scan_iter(match, count, _type, **kwargs)

    @override
    def sscan(
        self,
        name: RedisKeyType,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> RedisResponseType:
        """Scan members of a set incrementally.

        Args:
            name (RedisKeyType): The set key name.
            cursor (int): Cursor position. Defaults to 0.
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of elements. Defaults to None.

        Returns:
            RedisResponseType: Tuple of cursor and list of members.
        """
        return self.read_only_client.sscan(name, cursor, match, count)

    @override
    def sscan_iter(
        self,
        name: RedisKeyType,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> Iterator:
        """Iterate over members of a set.

        Args:
            name (RedisKeyType): The set key name.
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of elements. Defaults to None.

        Returns:
            Iterator: Iterator over set members.
        """
        return self.read_only_client.sscan_iter(name, match, count)

    @override
    def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Add members to a set.

        Args:
            name (str): The set key name.
            *values (bytes | str | float): Members to add.

        Returns:
            RedisIntegerResponseType: Number of elements added.
        """
        result = self.client.sadd(name, *values)
        return self._ensure_sync_int(result)

    @override
    def scard(self, name: str) -> RedisIntegerResponseType:
        """Get the number of members in a set.

        Args:
            name (str): The set key name.

        Returns:
            RedisIntegerResponseType: Number of members.
        """
        result = self.client.scard(name)
        return self._ensure_sync_int(result)

    @override
    def sismember(self, name: str, value: str) -> bool:
        """Check if a value is a member of a set.

        Args:
            name (str): The set key name.
            value (str): Value to check.

        Returns:
            bool: True if value is a member, False otherwise.
        """
        result = self.read_only_client.sismember(name, value)
        return bool(result)

    @override
    def smembers(self, name: str) -> RedisSetResponseType:
        """Get all members of a set.

        Args:
            name (str): The set key name.

        Returns:
            RedisSetResponseType: Set of all members.
        """
        result = self.read_only_client.smembers(name)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return set(result) if result else set()

    @override
    def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
        """Remove and return random members from a set.

        Args:
            name (str): The set key name.
            count (int | None): Number of members to pop. Defaults to None.

        Returns:
            bytes | float | int | str | list | None: Popped member(s) or None.
        """
        result = self.client.spop(name, count)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return result

    @override
    def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Remove members from a set.

        Args:
            name (str): The set key name.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisIntegerResponseType: Number of members removed.
        """
        result = self.client.srem(name, *values)
        return self._ensure_sync_int(result)

    @override
    def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
        """Get the union of multiple sets.

        Args:
            keys (RedisKeyType): First set key.
            *args (bytes | str): Additional set keys.

        Returns:
            RedisSetResponseType: Set containing union of all sets.
        """
        # Redis sunion expects a list of keys as first argument
        keys_list: list[str | bytes] = [keys, *list(args)]
        result = self.client.sunion(keys_list)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return set(result) if result else set()

    @override
    def zadd(
        self,
        name: RedisKeyType,
        mapping: Mapping[RedisKeyType, bytes | str | float],
        nx: bool = False,
        xx: bool = False,
        ch: bool = False,
        incr: bool = False,
        gt: bool = False,
        lt: bool = False,
    ) -> RedisResponseType:
        """Add members to a sorted set with scores.

        Args:
            name (RedisKeyType): The sorted set key name.
            mapping (Mapping[RedisKeyType, bytes | str | float]): Member-score pairs.
            nx (bool): Only add new elements. Defaults to False.
            xx (bool): Only update existing elements. Defaults to False.
            ch (bool): Return number of changed elements. Defaults to False.
            incr (bool): Increment existing scores. Defaults to False.
            gt (bool): Only update if score is greater. Defaults to False.
            lt (bool): Only update if score is less. Defaults to False.

        Returns:
            RedisResponseType: Number of elements added or modified.
        """
        # Convert Mapping to dict for type compatibility with Redis client
        dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
        str_name = str(name)
        return self.client.zadd(str_name, dict_mapping, nx, xx, ch, incr, gt, lt)

    @override
    def zcard(self, name: bytes | str) -> RedisResponseType:
        """Get the number of members in a sorted set.

        Args:
            name (bytes | str): The sorted set key name.

        Returns:
            RedisResponseType: Number of members.
        """
        return self.client.zcard(name)

    @override
    def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
        """Count members in a sorted set with scores in range.

        Args:
            name (RedisKeyType): The sorted set key name.
            min (float | str): Minimum score.
            max (float | str): Maximum score.

        Returns:
            RedisResponseType: Number of members in range.
        """
        return self.client.zcount(name, min, max)

    @override
    def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Remove and return members with highest scores from sorted set.

        Args:
            name (RedisKeyType): The sorted set key name.
            count (int | None): Number of members to pop. Defaults to None.

        Returns:
            RedisResponseType: List of popped member-score pairs.
        """
        return self.client.zpopmax(name, count)

    @override
    def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Remove and return members with lowest scores from sorted set.

        Args:
            name (RedisKeyType): The sorted set key name.
            count (int | None): Number of members to pop. Defaults to None.

        Returns:
            RedisResponseType: List of popped member-score pairs.
        """
        return self.client.zpopmin(name, count)

    @override
    def zrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        desc: bool = False,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
        byscore: bool = False,
        bylex: bool = False,
        offset: int | None = None,
        num: int | None = None,
    ) -> RedisResponseType:
        """Get a range of members from a sorted set.

        Args:
            name (RedisKeyType): The sorted set key name.
            start (int): Start index or score.
            end (int): End index or score.
            desc (bool): Sort in descending order. Defaults to False.
            withscores (bool): Include scores in result. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.
            byscore (bool): Range by score. Defaults to False.
            bylex (bool): Range by lexicographical order. Defaults to False.
            offset (int | None): Offset for byscore/bylex. Defaults to None.
            num (int | None): Count for byscore/bylex. Defaults to None.

        Returns:
            RedisResponseType: List of members or member-score pairs.
        """
        return self.client.zrange(
            name,
            start,
            end,
            desc,
            withscores,
            score_cast_func,
            byscore,
            bylex,
            offset,
            num,
        )

    @override
    def zrevrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Get a range of members from a sorted set in reverse order.

        Args:
            name (RedisKeyType): The sorted set key name.
            start (int): Start index.
            end (int): End index.
            withscores (bool): Include scores in result. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

        Returns:
            RedisResponseType: List of members or member-score pairs.
        """
        return self.client.zrevrange(name, start, end, withscores, score_cast_func)

    @override
    def zrangebyscore(
        self,
        name: RedisKeyType,
        min: float | str,
        max: float | str,
        start: int | None = None,
        num: int | None = None,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Get members from a sorted set by score range.

        Args:
            name (RedisKeyType): The sorted set key name.
            min (float | str): Minimum score.
            max (float | str): Maximum score.
            start (int | None): Offset. Defaults to None.
            num (int | None): Count. Defaults to None.
            withscores (bool): Include scores in result. Defaults to False.
            score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

        Returns:
            RedisResponseType: List of members or member-score pairs.
        """
        return self.client.zrangebyscore(name, min, max, start, num, withscores, score_cast_func)

    @override
    def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Get the rank of a member in a sorted set.

        Args:
            name (RedisKeyType): The sorted set key name.
            value (bytes | str | float): Member to find rank for.

        Returns:
            RedisResponseType: Rank of the member or None if not found.
        """
        return self.client.zrank(name, value)

    @override
    def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
        """Remove members from a sorted set.

        Args:
            name (RedisKeyType): The sorted set key name.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisResponseType: Number of members removed.
        """
        return self.client.zrem(name, *values)

    @override
    def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Get the score of a member in a sorted set.

        Args:
            name (RedisKeyType): The sorted set key name.
            value (bytes | str | float): Member to get score for.

        Returns:
            RedisResponseType: Score of the member or None if not found.
        """
        return self.client.zscore(name, value)

    @override
    def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
        """Delete fields from a hash.

        Args:
            name (str): The hash key name.
            *keys (str | bytes): Fields to delete.

        Returns:
            RedisIntegerResponseType: Number of fields deleted.
        """
        # Convert keys to str for type compatibility with Redis client
        str_keys: tuple[str, ...] = tuple(str(k) if isinstance(k, bytes) else k for k in keys)
        result = self.client.hdel(name, *str_keys)
        return self._ensure_sync_int(result)

    @override
    def hexists(self, name: str, key: str) -> bool:
        """Check if a field exists in a hash.

        Args:
            name (str): The hash key name.
            key (str): Field to check.

        Returns:
            bool: True if field exists, False otherwise.
        """
        result = self.read_only_client.hexists(name, key)
        return bool(result)

    @override
    def hget(self, name: str, key: str) -> str | None:
        """Get the value of a field in a hash.

        Args:
            name (str): The hash key name.
            key (str): Field to get.

        Returns:
            str | None: Value of the field or None.
        """
        result = self.read_only_client.hget(name, key)
        return str(result) if result is not None else None

    @override
    def hgetall(self, name: str) -> dict[str, Any]:
        """Get all fields and values in a hash.

        Args:
            name (str): The hash key name.

        Returns:
            dict[str, Any]: Dictionary of field-value pairs.
        """
        result = self.read_only_client.hgetall(name)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        if result:
            return {str(k): v for k, v in result.items()}
        return {}

    @override
    def hkeys(self, name: str) -> RedisListResponseType:
        """Get all fields in a hash.

        Args:
            name (str): The hash key name.

        Returns:
            RedisListResponseType: List of field names.
        """
        result = self.read_only_client.hkeys(name)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return list(result) if result else []

    @override
    def hlen(self, name: str) -> RedisIntegerResponseType:
        """Get the number of fields in a hash.

        Args:
            name (str): The hash key name.

        Returns:
            RedisIntegerResponseType: Number of fields.
        """
        result = self.read_only_client.hlen(name)
        return self._ensure_sync_int(result)

    @override
    def hset(
        self,
        name: str,
        key: str | bytes | None = None,
        value: str | bytes | None = None,
        mapping: dict | None = None,
        items: list | None = None,
    ) -> RedisIntegerResponseType:
        """Set fields in a hash.

        Args:
            name (str): The hash key name.
            key (str | bytes | None): Single field name. Defaults to None.
            value (str | bytes | None): Single field value. Defaults to None.
            mapping (dict | None): Dictionary of field-value pairs. Defaults to None.
            items (list | None): List of field-value pairs. Defaults to None.

        Returns:
            RedisIntegerResponseType: Number of fields set.
        """
        # Convert bytes to str for type compatibility with Redis client
        str_key: str | None = str(key) if key is not None and isinstance(key, bytes) else key
        str_value: str | None = str(value) if value is not None and isinstance(value, bytes) else value
        result = self.client.hset(name, str_key, str_value, mapping, items)
        return self._ensure_sync_int(result)

    @override
    def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
        """Get values of multiple fields in a hash.

        Args:
            name (str): The hash key name.
            keys (list): List of field names.
            *args (str | bytes): Additional field names.

        Returns:
            RedisListResponseType: List of field values.
        """
        # Convert keys list and args for type compatibility, combine into single list
        keys_list: list[str] = [str(k) for k in keys] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
        result = self.read_only_client.hmget(name, keys_list)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return list(result) if result else []

    @override
    def hvals(self, name: str) -> RedisListResponseType:
        """Get all values in a hash.

        Args:
            name (str): The hash key name.

        Returns:
            RedisListResponseType: List of values.
        """
        result = self.read_only_client.hvals(name)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        return list(result) if result else []

    @override
    def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
        """Publish a message to a channel.

        Args:
            channel (RedisKeyType): Channel name.
            message (bytes | str): Message to publish.
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: Number of subscribers that received the message.
        """
        return self.client.publish(channel, message, **kwargs)

    @override
    def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """List active channels matching a pattern.

        Args:
            pattern (RedisPatternType): Pattern to match channels. Defaults to "*".
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: List of channel names.
        """
        return self.client.pubsub_channels(pattern, **kwargs)

    @override
    def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
        """Increment the score of a member in a sorted set.

        Args:
            name (RedisKeyType): The sorted set key name.
            amount (float): Amount to increment by.
            value (bytes | str | float): Member to increment.

        Returns:
            RedisResponseType: New score of the member.
        """
        return self.client.zincrby(name, amount, value)

    @override
    def pubsub(self, **kwargs: Any) -> PubSub:
        """Get a PubSub object for subscribing to channels.

        Args:
            **kwargs (Any): Additional arguments.

        Returns:
            PubSub: PubSub object.
        """
        return self.client.pubsub(**kwargs)

    @override
    def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> Pipeline:
        """Get a pipeline object for executing multiple commands.

        Args:
            transaction (Any): Whether to use transactions. Defaults to True.
            shard_hint (Any): Hint for sharding. Defaults to None.

        Returns:
            Pipeline: Pipeline object.
        """
        return self.client.pipeline(transaction, shard_hint)

    @override
    def ping(self) -> RedisResponseType:
        """Ping the Redis server.

        Returns:
            RedisResponseType: 'PONG' if successful.
        """
        return self.client.ping()

archipy.adapters.redis.adapters.RedisAdapter.cluster_info

cluster_info() -> RedisResponseType

Get cluster information.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_info(self) -> RedisResponseType:
    """Get cluster information."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_info()
    return None

archipy.adapters.redis.adapters.RedisAdapter.cluster_nodes

cluster_nodes() -> RedisResponseType

Get cluster nodes information.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_nodes(self) -> RedisResponseType:
    """Get cluster nodes information."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_nodes()
    return None

archipy.adapters.redis.adapters.RedisAdapter.cluster_slots

cluster_slots() -> RedisResponseType

Get cluster slots mapping.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_slots(self) -> RedisResponseType:
    """Get cluster slots mapping."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_slots()
    return None

archipy.adapters.redis.adapters.RedisAdapter.cluster_key_slot

cluster_key_slot(key: str) -> RedisResponseType

Get the hash slot for a key.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_key_slot(self, key: str) -> RedisResponseType:
    """Get the hash slot for a key."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_keyslot(key)
    return None

archipy.adapters.redis.adapters.RedisAdapter.cluster_count_keys_in_slot

cluster_count_keys_in_slot(slot: int) -> RedisResponseType

Count keys in a specific slot.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
    """Count keys in a specific slot."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_countkeysinslot(slot)
    return None

archipy.adapters.redis.adapters.RedisAdapter.cluster_get_keys_in_slot

cluster_get_keys_in_slot(
    slot: int, count: int
) -> RedisResponseType

Get keys in a specific slot.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
    """Get keys in a specific slot."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_get_keys_in_slot(slot, count)
    return None

archipy.adapters.redis.adapters.RedisAdapter.pttl

pttl(name: bytes | str) -> RedisResponseType

Get the time to live in milliseconds for a key.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in milliseconds.

Source code in archipy/adapters/redis/adapters.py
@override
def pttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in milliseconds for a key.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in milliseconds.
    """
    return self.read_only_client.pttl(name)

archipy.adapters.redis.adapters.RedisAdapter.incrby

incrby(
    name: RedisKeyType, amount: int = 1
) -> RedisResponseType

Increment the integer value of a key by the given amount.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
amount int

Amount to increment by. Defaults to 1.

1

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new value after increment.

Source code in archipy/adapters/redis/adapters.py
@override
def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
    """Increment the integer value of a key by the given amount.

    Args:
        name (RedisKeyType): The key name.
        amount (int): Amount to increment by. Defaults to 1.

    Returns:
        RedisResponseType: The new value after increment.
    """
    return self.client.incrby(name, amount)

archipy.adapters.redis.adapters.RedisAdapter.set

set(
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType

Set the value of a key with optional expiration and conditions.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
value RedisSetType

The value to set.

required
ex RedisExpiryType | None

Expire time in seconds.

None
px RedisExpiryType | None

Expire time in milliseconds.

None
nx bool

Only set if key doesn't exist.

False
xx bool

Only set if key exists.

False
keepttl bool

Retain the TTL from the previous value.

False
get bool

Return the old value.

False
exat RedisAbsExpiryType | None

Absolute expiration time in seconds.

None
pxat RedisAbsExpiryType | None

Absolute expiration time in milliseconds.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Result of the operation.

Source code in archipy/adapters/redis/adapters.py
@override
def set(
    self,
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType:
    """Set the value of a key with optional expiration and conditions.

    Args:
        name (RedisKeyType): The key name.
        value (RedisSetType): The value to set.
        ex (RedisExpiryType | None): Expire time in seconds.
        px (RedisExpiryType | None): Expire time in milliseconds.
        nx (bool): Only set if key doesn't exist.
        xx (bool): Only set if key exists.
        keepttl (bool): Retain the TTL from the previous value.
        get (bool): Return the old value.
        exat (RedisAbsExpiryType | None): Absolute expiration time in seconds.
        pxat (RedisAbsExpiryType | None): Absolute expiration time in milliseconds.

    Returns:
        RedisResponseType: Result of the operation.
    """
    return self.client.set(name, value, ex, px, nx, xx, keepttl, get, exat, pxat)

archipy.adapters.redis.adapters.RedisAdapter.get

get(key: str) -> RedisResponseType

Get the value of a key.

Parameters:

Name Type Description Default
key str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None if not exists.

Source code in archipy/adapters/redis/adapters.py
@override
def get(self, key: str) -> RedisResponseType:
    """Get the value of a key.

    Args:
        key (str): The key name.

    Returns:
        RedisResponseType: The value of the key or None if not exists.
    """
    return self.read_only_client.get(key)

archipy.adapters.redis.adapters.RedisAdapter.mget

mget(
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType

Get the values of multiple keys.

Parameters:

Name Type Description Default
keys RedisKeyType | Iterable[RedisKeyType]

Single key or iterable of keys.

required
*args bytes | str

Additional keys.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
def mget(
    self,
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType:
    """Get the values of multiple keys.

    Args:
        keys (RedisKeyType | Iterable[RedisKeyType]): Single key or iterable of keys.
        *args (bytes | str): Additional keys.

    Returns:
        RedisResponseType: List of values.
    """
    return self.read_only_client.mget(keys, *args)

archipy.adapters.redis.adapters.RedisAdapter.mset

mset(
    mapping: Mapping[RedisKeyType, bytes | str | float],
) -> RedisResponseType

Set multiple keys to their respective values.

Parameters:

Name Type Description Default
mapping Mapping[RedisKeyType, bytes | str | float]

Dictionary of key-value pairs.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Always returns 'OK'.

Source code in archipy/adapters/redis/adapters.py
@override
def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
    """Set multiple keys to their respective values.

    Args:
        mapping (Mapping[RedisKeyType, bytes | str | float]): Dictionary of key-value pairs.

    Returns:
        RedisResponseType: Always returns 'OK'.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    return self.client.mset(dict_mapping)

archipy.adapters.redis.adapters.RedisAdapter.keys

keys(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Find all keys matching the given pattern.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match keys against. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Find all keys matching the given pattern.

    Args:
        pattern (RedisPatternType): Pattern to match keys against. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of matching keys.
    """
    return self.read_only_client.keys(pattern, **kwargs)

archipy.adapters.redis.adapters.RedisAdapter.getset

getset(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Set the value of a key and return its old value.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The new value.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The previous value or None.

Source code in archipy/adapters/redis/adapters.py
@override
def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Set the value of a key and return its old value.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The new value.

    Returns:
        RedisResponseType: The previous value or None.
    """
    return self.client.getset(key, value)

archipy.adapters.redis.adapters.RedisAdapter.getdel

getdel(key: bytes | str) -> RedisResponseType

Get the value of a key and delete it.

Parameters:

Name Type Description Default
key bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None.

Source code in archipy/adapters/redis/adapters.py
@override
def getdel(self, key: bytes | str) -> RedisResponseType:
    """Get the value of a key and delete it.

    Args:
        key (bytes | str): The key name.

    Returns:
        RedisResponseType: The value of the key or None.
    """
    return self.client.getdel(key)

archipy.adapters.redis.adapters.RedisAdapter.exists

exists(*names: bytes | str) -> RedisResponseType

Check if one or more keys exist.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys that exist.

Source code in archipy/adapters/redis/adapters.py
@override
def exists(self, *names: bytes | str) -> RedisResponseType:
    """Check if one or more keys exist.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys that exist.
    """
    return self.read_only_client.exists(*names)

archipy.adapters.redis.adapters.RedisAdapter.delete

delete(*names: bytes | str) -> RedisResponseType

Delete one or more keys.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys deleted.

Source code in archipy/adapters/redis/adapters.py
@override
def delete(self, *names: bytes | str) -> RedisResponseType:
    """Delete one or more keys.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys deleted.
    """
    return self.client.delete(*names)

archipy.adapters.redis.adapters.RedisAdapter.append

append(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Append a value to a key.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The value to append.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Length of the string after append.

Source code in archipy/adapters/redis/adapters.py
@override
def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Append a value to a key.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The value to append.

    Returns:
        RedisResponseType: Length of the string after append.
    """
    return self.client.append(key, value)

archipy.adapters.redis.adapters.RedisAdapter.ttl

ttl(name: bytes | str) -> RedisResponseType

Get the time to live in seconds for a key.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in seconds.

Source code in archipy/adapters/redis/adapters.py
@override
def ttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in seconds for a key.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in seconds.
    """
    return self.read_only_client.ttl(name)

archipy.adapters.redis.adapters.RedisAdapter.type

type(name: bytes | str) -> RedisResponseType

Determine the type stored at key.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Type of the key's value.

Source code in archipy/adapters/redis/adapters.py
@override
def type(self, name: bytes | str) -> RedisResponseType:
    """Determine the type stored at key.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Type of the key's value.
    """
    return self.read_only_client.type(name)

archipy.adapters.redis.adapters.RedisAdapter.llen

llen(name: str) -> RedisIntegerResponseType

Get the length of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list.

Source code in archipy/adapters/redis/adapters.py
@override
def llen(self, name: str) -> RedisIntegerResponseType:
    """Get the length of a list.

    Args:
        name (str): The key name of the list.

    Returns:
        RedisIntegerResponseType: Length of the list.
    """
    client: Redis | RedisCluster = self.read_only_client
    result = client.llen(name)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.lpop

lpop(name: str, count: int | None = None) -> Any

Remove and return elements from the left of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
def lpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from the left of a list.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    return self.client.lpop(name, count)

archipy.adapters.redis.adapters.RedisAdapter.lpush

lpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to the left of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to the left of a list.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.lpush(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.lrange

lrange(
    name: str, start: int, end: int
) -> RedisListResponseType

Get a range of elements from a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
start int

Start index.

required
end int

End index.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of elements in the specified range.

Source code in archipy/adapters/redis/adapters.py
@override
def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
    """Get a range of elements from a list.

    Args:
        name (str): The key name of the list.
        start (int): Start index.
        end (int): End index.

    Returns:
        RedisListResponseType: List of elements in the specified range.
    """
    result = self.read_only_client.lrange(name, start, end)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result)

archipy.adapters.redis.adapters.RedisAdapter.lrem

lrem(
    name: str, count: int, value: str
) -> RedisIntegerResponseType

Remove elements from a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int

Number of occurrences to remove.

required
value str

Value to remove.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements removed.

Source code in archipy/adapters/redis/adapters.py
@override
def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
    """Remove elements from a list.

    Args:
        name (str): The key name of the list.
        count (int): Number of occurrences to remove.
        value (str): Value to remove.

    Returns:
        RedisIntegerResponseType: Number of elements removed.
    """
    result = self.client.lrem(name, count, value)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.lset

lset(name: str, index: int, value: str) -> bool

Set the value of an element in a list by its index.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
index int

Index of the element.

required
value str

New value.

required

Returns:

Name Type Description
bool bool

True if successful.

Source code in archipy/adapters/redis/adapters.py
@override
def lset(self, name: str, index: int, value: str) -> bool:
    """Set the value of an element in a list by its index.

    Args:
        name (str): The key name of the list.
        index (int): Index of the element.
        value (str): New value.

    Returns:
        bool: True if successful.
    """
    return bool(self.client.lset(name, index, value))

archipy.adapters.redis.adapters.RedisAdapter.rpop

rpop(name: str, count: int | None = None) -> Any

Remove and return elements from the right of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
def rpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from the right of a list.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    return self.client.rpop(name, count)

archipy.adapters.redis.adapters.RedisAdapter.rpush

rpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to the right of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to the right of a list.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.rpush(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.scan

scan(
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType

Scan keys in the database incrementally.

Parameters:

Name Type Description Default
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys to return. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of keys.

Source code in archipy/adapters/redis/adapters.py
@override
def scan(
    self,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType:
    """Scan keys in the database incrementally.

    Args:
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys to return. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Tuple of cursor and list of keys.
    """
    return self.read_only_client.scan(cursor, match, count, _type, **kwargs)

archipy.adapters.redis.adapters.RedisAdapter.scan_iter

scan_iter(
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator

Iterate over keys in the database.

Parameters:

Name Type Description Default
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys to return. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
Iterator Iterator

Iterator over matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
def scan_iter(
    self,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator:
    """Iterate over keys in the database.

    Args:
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys to return. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        Iterator: Iterator over matching keys.
    """
    return self.read_only_client.scan_iter(match, count, _type, **kwargs)

archipy.adapters.redis.adapters.RedisAdapter.sscan

sscan(
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType

Scan members of a set incrementally.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of members.

Source code in archipy/adapters/redis/adapters.py
@override
def sscan(
    self,
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType:
    """Scan members of a set incrementally.

    Args:
        name (RedisKeyType): The set key name.
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        RedisResponseType: Tuple of cursor and list of members.
    """
    return self.read_only_client.sscan(name, cursor, match, count)

archipy.adapters.redis.adapters.RedisAdapter.sscan_iter

sscan_iter(
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator

Iterate over members of a set.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Name Type Description
Iterator Iterator

Iterator over set members.

Source code in archipy/adapters/redis/adapters.py
@override
def sscan_iter(
    self,
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator:
    """Iterate over members of a set.

    Args:
        name (RedisKeyType): The set key name.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        Iterator: Iterator over set members.
    """
    return self.read_only_client.sscan_iter(name, match, count)

archipy.adapters.redis.adapters.RedisAdapter.sadd

sadd(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Add members to a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to add.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements added.

Source code in archipy/adapters/redis/adapters.py
@override
def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Add members to a set.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to add.

    Returns:
        RedisIntegerResponseType: Number of elements added.
    """
    result = self.client.sadd(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.scard

scard(name: str) -> RedisIntegerResponseType

Get the number of members in a set.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
def scard(self, name: str) -> RedisIntegerResponseType:
    """Get the number of members in a set.

    Args:
        name (str): The set key name.

    Returns:
        RedisIntegerResponseType: Number of members.
    """
    result = self.client.scard(name)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.sismember

sismember(name: str, value: str) -> bool

Check if a value is a member of a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
value str

Value to check.

required

Returns:

Name Type Description
bool bool

True if value is a member, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
def sismember(self, name: str, value: str) -> bool:
    """Check if a value is a member of a set.

    Args:
        name (str): The set key name.
        value (str): Value to check.

    Returns:
        bool: True if value is a member, False otherwise.
    """
    result = self.read_only_client.sismember(name, value)
    return bool(result)

archipy.adapters.redis.adapters.RedisAdapter.smembers

smembers(name: str) -> RedisSetResponseType

Get all members of a set.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set of all members.

Source code in archipy/adapters/redis/adapters.py
@override
def smembers(self, name: str) -> RedisSetResponseType:
    """Get all members of a set.

    Args:
        name (str): The set key name.

    Returns:
        RedisSetResponseType: Set of all members.
    """
    result = self.read_only_client.smembers(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return set(result) if result else set()

archipy.adapters.redis.adapters.RedisAdapter.spop

spop(
    name: str, count: int | None = None
) -> bytes | float | int | str | list | None

Remove and return random members from a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Type Description
bytes | float | int | str | list | None

bytes | float | int | str | list | None: Popped member(s) or None.

Source code in archipy/adapters/redis/adapters.py
@override
def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
    """Remove and return random members from a set.

    Args:
        name (str): The set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        bytes | float | int | str | list | None: Popped member(s) or None.
    """
    result = self.client.spop(name, count)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return result

archipy.adapters.redis.adapters.RedisAdapter.srem

srem(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Remove members from a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Remove members from a set.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisIntegerResponseType: Number of members removed.
    """
    result = self.client.srem(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.sunion

sunion(
    keys: RedisKeyType, *args: bytes | str
) -> RedisSetResponseType

Get the union of multiple sets.

Parameters:

Name Type Description Default
keys RedisKeyType

First set key.

required
*args bytes | str

Additional set keys.

()

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set containing union of all sets.

Source code in archipy/adapters/redis/adapters.py
@override
def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
    """Get the union of multiple sets.

    Args:
        keys (RedisKeyType): First set key.
        *args (bytes | str): Additional set keys.

    Returns:
        RedisSetResponseType: Set containing union of all sets.
    """
    # Redis sunion expects a list of keys as first argument
    keys_list: list[str | bytes] = [keys, *list(args)]
    result = self.client.sunion(keys_list)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return set(result) if result else set()

archipy.adapters.redis.adapters.RedisAdapter.zadd

zadd(
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType

Add members to a sorted set with scores.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
mapping Mapping[RedisKeyType, bytes | str | float]

Member-score pairs.

required
nx bool

Only add new elements. Defaults to False.

False
xx bool

Only update existing elements. Defaults to False.

False
ch bool

Return number of changed elements. Defaults to False.

False
incr bool

Increment existing scores. Defaults to False.

False
gt bool

Only update if score is greater. Defaults to False.

False
lt bool

Only update if score is less. Defaults to False.

False

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of elements added or modified.

Source code in archipy/adapters/redis/adapters.py
@override
def zadd(
    self,
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType:
    """Add members to a sorted set with scores.

    Args:
        name (RedisKeyType): The sorted set key name.
        mapping (Mapping[RedisKeyType, bytes | str | float]): Member-score pairs.
        nx (bool): Only add new elements. Defaults to False.
        xx (bool): Only update existing elements. Defaults to False.
        ch (bool): Return number of changed elements. Defaults to False.
        incr (bool): Increment existing scores. Defaults to False.
        gt (bool): Only update if score is greater. Defaults to False.
        lt (bool): Only update if score is less. Defaults to False.

    Returns:
        RedisResponseType: Number of elements added or modified.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    str_name = str(name)
    return self.client.zadd(str_name, dict_mapping, nx, xx, ch, incr, gt, lt)

archipy.adapters.redis.adapters.RedisAdapter.zcard

zcard(name: bytes | str) -> RedisResponseType

Get the number of members in a sorted set.

Parameters:

Name Type Description Default
name bytes | str

The sorted set key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
def zcard(self, name: bytes | str) -> RedisResponseType:
    """Get the number of members in a sorted set.

    Args:
        name (bytes | str): The sorted set key name.

    Returns:
        RedisResponseType: Number of members.
    """
    return self.client.zcard(name)

archipy.adapters.redis.adapters.RedisAdapter.zcount

zcount(
    name: RedisKeyType, min: float | str, max: float | str
) -> RedisResponseType

Count members in a sorted set with scores in range.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members in range.

Source code in archipy/adapters/redis/adapters.py
@override
def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
    """Count members in a sorted set with scores in range.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.

    Returns:
        RedisResponseType: Number of members in range.
    """
    return self.client.zcount(name, min, max)

archipy.adapters.redis.adapters.RedisAdapter.zpopmax

zpopmax(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Remove and return members with highest scores from sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Remove and return members with highest scores from sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return self.client.zpopmax(name, count)

archipy.adapters.redis.adapters.RedisAdapter.zpopmin

zpopmin(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Remove and return members with lowest scores from sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Remove and return members with lowest scores from sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return self.client.zpopmin(name, count)

archipy.adapters.redis.adapters.RedisAdapter.zrange

zrange(
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType

Get a range of members from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index or score.

required
end int

End index or score.

required
desc bool

Sort in descending order. Defaults to False.

False
withscores bool

Include scores in result. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float
byscore bool

Range by score. Defaults to False.

False
bylex bool

Range by lexicographical order. Defaults to False.

False
offset int | None

Offset for byscore/bylex. Defaults to None.

None
num int | None

Count for byscore/bylex. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType:
    """Get a range of members from a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index or score.
        end (int): End index or score.
        desc (bool): Sort in descending order. Defaults to False.
        withscores (bool): Include scores in result. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.
        byscore (bool): Range by score. Defaults to False.
        bylex (bool): Range by lexicographical order. Defaults to False.
        offset (int | None): Offset for byscore/bylex. Defaults to None.
        num (int | None): Count for byscore/bylex. Defaults to None.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return self.client.zrange(
        name,
        start,
        end,
        desc,
        withscores,
        score_cast_func,
        byscore,
        bylex,
        offset,
        num,
    )

archipy.adapters.redis.adapters.RedisAdapter.zrevrange

zrevrange(
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get a range of members from a sorted set in reverse order.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index.

required
end int

End index.

required
withscores bool

Include scores in result. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zrevrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get a range of members from a sorted set in reverse order.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index.
        end (int): End index.
        withscores (bool): Include scores in result. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return self.client.zrevrange(name, start, end, withscores, score_cast_func)

archipy.adapters.redis.adapters.RedisAdapter.zrangebyscore

zrangebyscore(
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get members from a sorted set by score range.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required
start int | None

Offset. Defaults to None.

None
num int | None

Count. Defaults to None.

None
withscores bool

Include scores in result. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zrangebyscore(
    self,
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get members from a sorted set by score range.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.
        start (int | None): Offset. Defaults to None.
        num (int | None): Count. Defaults to None.
        withscores (bool): Include scores in result. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return self.client.zrangebyscore(name, min, max, start, num, withscores, score_cast_func)

archipy.adapters.redis.adapters.RedisAdapter.zrank

zrank(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get the rank of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to find rank for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Rank of the member or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get the rank of a member in a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to find rank for.

    Returns:
        RedisResponseType: Rank of the member or None if not found.
    """
    return self.client.zrank(name, value)

archipy.adapters.redis.adapters.RedisAdapter.zrem

zrem(
    name: RedisKeyType, *values: bytes | str | float
) -> RedisResponseType

Remove members from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
    """Remove members from a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisResponseType: Number of members removed.
    """
    return self.client.zrem(name, *values)

archipy.adapters.redis.adapters.RedisAdapter.zscore

zscore(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get the score of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to get score for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Score of the member or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get the score of a member in a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to get score for.

    Returns:
        RedisResponseType: Score of the member or None if not found.
    """
    return self.client.zscore(name, value)

archipy.adapters.redis.adapters.RedisAdapter.hdel

hdel(
    name: str, *keys: str | bytes
) -> RedisIntegerResponseType

Delete fields from a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
*keys str | bytes

Fields to delete.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields deleted.

Source code in archipy/adapters/redis/adapters.py
@override
def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
    """Delete fields from a hash.

    Args:
        name (str): The hash key name.
        *keys (str | bytes): Fields to delete.

    Returns:
        RedisIntegerResponseType: Number of fields deleted.
    """
    # Convert keys to str for type compatibility with Redis client
    str_keys: tuple[str, ...] = tuple(str(k) if isinstance(k, bytes) else k for k in keys)
    result = self.client.hdel(name, *str_keys)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.hexists

hexists(name: str, key: str) -> bool

Check if a field exists in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to check.

required

Returns:

Name Type Description
bool bool

True if field exists, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
def hexists(self, name: str, key: str) -> bool:
    """Check if a field exists in a hash.

    Args:
        name (str): The hash key name.
        key (str): Field to check.

    Returns:
        bool: True if field exists, False otherwise.
    """
    result = self.read_only_client.hexists(name, key)
    return bool(result)

archipy.adapters.redis.adapters.RedisAdapter.hget

hget(name: str, key: str) -> str | None

Get the value of a field in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to get.

required

Returns:

Type Description
str | None

str | None: Value of the field or None.

Source code in archipy/adapters/redis/adapters.py
@override
def hget(self, name: str, key: str) -> str | None:
    """Get the value of a field in a hash.

    Args:
        name (str): The hash key name.
        key (str): Field to get.

    Returns:
        str | None: Value of the field or None.
    """
    result = self.read_only_client.hget(name, key)
    return str(result) if result is not None else None

archipy.adapters.redis.adapters.RedisAdapter.hgetall

hgetall(name: str) -> dict[str, Any]

Get all fields and values in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Dictionary of field-value pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def hgetall(self, name: str) -> dict[str, Any]:
    """Get all fields and values in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        dict[str, Any]: Dictionary of field-value pairs.
    """
    result = self.read_only_client.hgetall(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    if result:
        return {str(k): v for k, v in result.items()}
    return {}

archipy.adapters.redis.adapters.RedisAdapter.hkeys

hkeys(name: str) -> RedisListResponseType

Get all fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field names.

Source code in archipy/adapters/redis/adapters.py
@override
def hkeys(self, name: str) -> RedisListResponseType:
    """Get all fields in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of field names.
    """
    result = self.read_only_client.hkeys(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result) if result else []

archipy.adapters.redis.adapters.RedisAdapter.hlen

hlen(name: str) -> RedisIntegerResponseType

Get the number of fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields.

Source code in archipy/adapters/redis/adapters.py
@override
def hlen(self, name: str) -> RedisIntegerResponseType:
    """Get the number of fields in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        RedisIntegerResponseType: Number of fields.
    """
    result = self.read_only_client.hlen(name)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.hset

hset(
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType

Set fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str | bytes | None

Single field name. Defaults to None.

None
value str | bytes | None

Single field value. Defaults to None.

None
mapping dict | None

Dictionary of field-value pairs. Defaults to None.

None
items list | None

List of field-value pairs. Defaults to None.

None

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields set.

Source code in archipy/adapters/redis/adapters.py
@override
def hset(
    self,
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType:
    """Set fields in a hash.

    Args:
        name (str): The hash key name.
        key (str | bytes | None): Single field name. Defaults to None.
        value (str | bytes | None): Single field value. Defaults to None.
        mapping (dict | None): Dictionary of field-value pairs. Defaults to None.
        items (list | None): List of field-value pairs. Defaults to None.

    Returns:
        RedisIntegerResponseType: Number of fields set.
    """
    # Convert bytes to str for type compatibility with Redis client
    str_key: str | None = str(key) if key is not None and isinstance(key, bytes) else key
    str_value: str | None = str(value) if value is not None and isinstance(value, bytes) else value
    result = self.client.hset(name, str_key, str_value, mapping, items)
    return self._ensure_sync_int(result)

archipy.adapters.redis.adapters.RedisAdapter.hmget

hmget(
    name: str, keys: list, *args: str | bytes
) -> RedisListResponseType

Get values of multiple fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
keys list

List of field names.

required
*args str | bytes

Additional field names.

()

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field values.

Source code in archipy/adapters/redis/adapters.py
@override
def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
    """Get values of multiple fields in a hash.

    Args:
        name (str): The hash key name.
        keys (list): List of field names.
        *args (str | bytes): Additional field names.

    Returns:
        RedisListResponseType: List of field values.
    """
    # Convert keys list and args for type compatibility, combine into single list
    keys_list: list[str] = [str(k) for k in keys] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
    result = self.read_only_client.hmget(name, keys_list)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result) if result else []

archipy.adapters.redis.adapters.RedisAdapter.hvals

hvals(name: str) -> RedisListResponseType

Get all values in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
def hvals(self, name: str) -> RedisListResponseType:
    """Get all values in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of values.
    """
    result = self.read_only_client.hvals(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result) if result else []

archipy.adapters.redis.adapters.RedisAdapter.publish

publish(
    channel: RedisKeyType,
    message: bytes | str,
    **kwargs: Any,
) -> RedisResponseType

Publish a message to a channel.

Parameters:

Name Type Description Default
channel RedisKeyType

Channel name.

required
message bytes | str

Message to publish.

required
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of subscribers that received the message.

Source code in archipy/adapters/redis/adapters.py
@override
def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
    """Publish a message to a channel.

    Args:
        channel (RedisKeyType): Channel name.
        message (bytes | str): Message to publish.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Number of subscribers that received the message.
    """
    return self.client.publish(channel, message, **kwargs)

archipy.adapters.redis.adapters.RedisAdapter.pubsub_channels

pubsub_channels(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

List active channels matching a pattern.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match channels. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of channel names.

Source code in archipy/adapters/redis/adapters.py
@override
def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """List active channels matching a pattern.

    Args:
        pattern (RedisPatternType): Pattern to match channels. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of channel names.
    """
    return self.client.pubsub_channels(pattern, **kwargs)

archipy.adapters.redis.adapters.RedisAdapter.zincrby

zincrby(
    name: RedisKeyType,
    amount: float,
    value: bytes | str | float,
) -> RedisResponseType

Increment the score of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
amount float

Amount to increment by.

required
value bytes | str | float

Member to increment.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

New score of the member.

Source code in archipy/adapters/redis/adapters.py
@override
def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
    """Increment the score of a member in a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        amount (float): Amount to increment by.
        value (bytes | str | float): Member to increment.

    Returns:
        RedisResponseType: New score of the member.
    """
    return self.client.zincrby(name, amount, value)

archipy.adapters.redis.adapters.RedisAdapter.pubsub

pubsub(**kwargs: Any) -> PubSub

Get a PubSub object for subscribing to channels.

Parameters:

Name Type Description Default
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
PubSub PubSub

PubSub object.

Source code in archipy/adapters/redis/adapters.py
@override
def pubsub(self, **kwargs: Any) -> PubSub:
    """Get a PubSub object for subscribing to channels.

    Args:
        **kwargs (Any): Additional arguments.

    Returns:
        PubSub: PubSub object.
    """
    return self.client.pubsub(**kwargs)

archipy.adapters.redis.adapters.RedisAdapter.get_pipeline

get_pipeline(
    transaction: Any = True, shard_hint: Any = None
) -> Pipeline

Get a pipeline object for executing multiple commands.

Parameters:

Name Type Description Default
transaction Any

Whether to use transactions. Defaults to True.

True
shard_hint Any

Hint for sharding. Defaults to None.

None

Returns:

Name Type Description
Pipeline Pipeline

Pipeline object.

Source code in archipy/adapters/redis/adapters.py
@override
def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> Pipeline:
    """Get a pipeline object for executing multiple commands.

    Args:
        transaction (Any): Whether to use transactions. Defaults to True.
        shard_hint (Any): Hint for sharding. Defaults to None.

    Returns:
        Pipeline: Pipeline object.
    """
    return self.client.pipeline(transaction, shard_hint)

archipy.adapters.redis.adapters.RedisAdapter.ping

ping() -> RedisResponseType

Ping the Redis server.

Returns:

Name Type Description
RedisResponseType RedisResponseType

'PONG' if successful.

Source code in archipy/adapters/redis/adapters.py
@override
def ping(self) -> RedisResponseType:
    """Ping the Redis server.

    Returns:
        RedisResponseType: 'PONG' if successful.
    """
    return self.client.ping()

archipy.adapters.redis.adapters.AsyncRedisAdapter

Bases: AsyncRedisPort

Async adapter for Redis operations providing a standardized interface.

This adapter implements the AsyncRedisPort interface to provide a consistent way to interact with Redis asynchronously, abstracting the underlying Redis client implementation. It supports all common Redis operations including key-value operations, lists, sets, sorted sets, hashes, and pub/sub functionality.

The adapter maintains separate connections for read and write operations, which can be used to implement read replicas for better performance.

Parameters:

Name Type Description Default
redis_config RedisConfig

Configuration settings for Redis. If None, retrieves from global config. Defaults to None.

None
Source code in archipy/adapters/redis/adapters.py
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
class AsyncRedisAdapter(AsyncRedisPort):
    """Async adapter for Redis operations providing a standardized interface.

    This adapter implements the AsyncRedisPort interface to provide a consistent
    way to interact with Redis asynchronously, abstracting the underlying Redis
    client implementation. It supports all common Redis operations including
    key-value operations, lists, sets, sorted sets, hashes, and pub/sub functionality.

    The adapter maintains separate connections for read and write operations,
    which can be used to implement read replicas for better performance.

    Args:
        redis_config (RedisConfig, optional): Configuration settings for Redis.
            If None, retrieves from global config. Defaults to None.
    """

    def __init__(self, redis_config: RedisConfig | None = None) -> None:
        """Initialize the AsyncRedisAdapter with configuration settings.

        Args:
            redis_config (RedisConfig, optional): Configuration settings for Redis.
                If None, retrieves from global config. Defaults to None.
        """
        configs: RedisConfig = BaseConfig.global_config().REDIS if redis_config is None else redis_config
        self._set_clients(configs)

    def _set_clients(self, configs: RedisConfig) -> None:
        """Set up async Redis clients based on the configured mode.

        Args:
            configs (RedisConfig): Configuration settings for Redis.
        """
        match configs.MODE:
            case RedisMode.CLUSTER:
                self._set_cluster_clients(configs)
            case RedisMode.SENTINEL:
                self._set_sentinel_clients(configs)
            case RedisMode.STANDALONE:
                self._set_standalone_clients(configs)
            case _:
                raise ValueError(f"Unsupported Redis mode: {configs.MODE}")

    def _set_standalone_clients(self, configs: RedisConfig) -> None:
        """Set up standalone async Redis clients.

        Args:
            configs (RedisConfig): Configuration settings for Redis.
        """
        if redis_master_host := configs.MASTER_HOST:
            self.client: AsyncRedis | AsyncRedisCluster = self._get_client(redis_master_host, configs)
        if redis_slave_host := configs.SLAVE_HOST:
            self.read_only_client: AsyncRedis | AsyncRedisCluster = self._get_client(redis_slave_host, configs)
        else:
            self.read_only_client = self.client

    def _set_cluster_clients(self, configs: RedisConfig) -> None:
        """Set up async Redis cluster clients.

        Args:
            configs (RedisConfig): Configuration settings for Redis cluster.
        """
        from redis.cluster import ClusterNode

        startup_nodes = []
        for node in configs.CLUSTER_NODES:
            if ":" in node:
                host, port = node.split(":", 1)
                startup_nodes.append(ClusterNode(host, int(port)))
            else:
                startup_nodes.append(ClusterNode(node, configs.PORT))

        cluster_client = AsyncRedisCluster(
            startup_nodes=startup_nodes,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
            max_connections=configs.MAX_CONNECTIONS,
            socket_connect_timeout=configs.SOCKET_CONNECT_TIMEOUT,
            socket_timeout=configs.SOCKET_TIMEOUT,
            health_check_interval=configs.HEALTH_CHECK_INTERVAL,
            read_from_replicas=configs.CLUSTER_READ_FROM_REPLICAS,
            require_full_coverage=configs.CLUSTER_REQUIRE_FULL_COVERAGE,
        )

        # In cluster mode, both clients point to the cluster
        self.client: AsyncRedis | AsyncRedisCluster = cluster_client
        self.read_only_client: AsyncRedis | AsyncRedisCluster = cluster_client

    def _set_sentinel_clients(self, configs: RedisConfig) -> None:
        """Set up async Redis sentinel clients.

        Args:
            configs (RedisConfig): Configuration settings for Redis sentinel.
        """
        sentinel_service_name = configs.SENTINEL_SERVICE_NAME
        if not sentinel_service_name:
            raise ValueError("SENTINEL_SERVICE_NAME must be provided for sentinel mode")
        sentinel_nodes = [(node.split(":")[0], int(node.split(":")[1])) for node in configs.SENTINEL_NODES]

        sentinel = AsyncSentinel(
            sentinel_nodes,
            socket_timeout=configs.SENTINEL_SOCKET_TIMEOUT,
            password=configs.PASSWORD,
        )

        self.client = sentinel.master_for(
            sentinel_service_name,
            socket_timeout=configs.SOCKET_TIMEOUT,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
        )

        self.read_only_client = sentinel.slave_for(
            sentinel_service_name,
            socket_timeout=configs.SOCKET_TIMEOUT,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
        )

    # Override cluster methods to work when in cluster mode
    @override
    async def cluster_info(self) -> RedisResponseType:
        """Get cluster information asynchronously."""
        if isinstance(self.client, AsyncRedisCluster):
            return await self.client.cluster_info()
        return None

    @override
    async def cluster_nodes(self) -> RedisResponseType:
        """Get cluster nodes information asynchronously."""
        if isinstance(self.client, AsyncRedisCluster):
            return await self.client.cluster_nodes()
        return None

    @override
    async def cluster_slots(self) -> RedisResponseType:
        """Get cluster slots mapping asynchronously."""
        if isinstance(self.client, AsyncRedisCluster):
            return await self.client.cluster_slots()
        return None

    @override
    async def cluster_key_slot(self, key: str) -> RedisResponseType:
        """Get the hash slot for a key asynchronously."""
        if isinstance(self.client, AsyncRedisCluster):
            return await self.client.cluster_keyslot(key)
        return None

    @override
    async def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
        """Count keys in a specific slot asynchronously."""
        if isinstance(self.client, AsyncRedisCluster):
            return await self.client.cluster_countkeysinslot(slot)
        return None

    @override
    async def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
        """Get keys in a specific slot asynchronously."""
        if isinstance(self.client, AsyncRedisCluster):
            return await self.client.cluster_get_keys_in_slot(slot, count)
        return None

    @staticmethod
    def _get_client(host: str, configs: RedisConfig) -> AsyncRedis:
        """Create an async Redis client with the specified configuration.

        Args:
            host (str): Redis host address.
            configs (RedisConfig): Configuration settings for Redis.

        Returns:
            AsyncRedis: Configured async Redis client instance.
        """
        return AsyncRedis(
            host=host,
            port=configs.PORT,
            db=configs.DATABASE,
            password=configs.PASSWORD,
            decode_responses=configs.DECODE_RESPONSES,
            health_check_interval=configs.HEALTH_CHECK_INTERVAL,
        )

    @staticmethod
    async def _ensure_async_int(value: int | Awaitable[int]) -> int:
        """Ensure an async integer result, awaiting if necessary."""
        if isinstance(value, Awaitable):
            awaited_value = await value
            if not isinstance(awaited_value, int):
                raise TypeError(f"Expected int, got {type(awaited_value)}")
            return awaited_value
        return value

    @staticmethod
    async def _ensure_async_bool(value: bool | Awaitable[bool]) -> bool:
        """Ensure an async boolean result, awaiting if necessary."""
        if isinstance(value, Awaitable):
            awaited_value = await value
            return bool(awaited_value)
        return bool(value)

    @staticmethod
    async def _ensure_async_str(value: str | None | Awaitable[str | None]) -> str | None:
        """Ensure an async string result, awaiting if necessary."""
        if isinstance(value, Awaitable):
            result = await value
            if result is not None and not isinstance(result, str):
                raise TypeError(f"Expected str | None, got {type(result)}")
            return result
        return value

    @staticmethod
    async def _ensure_async_list(value: list[Any] | Awaitable[list[Any]]) -> list[Any]:
        """Ensure an async list result, awaiting if necessary."""
        if isinstance(value, Awaitable):
            result = await value
            if result is None:
                return []
            if isinstance(result, list):
                return result
            # Type narrowing: result is iterable but not a list
            from collections.abc import Iterable

            if isinstance(result, Iterable):
                return list(result)
            return []
        if value is None:
            return []
        if isinstance(value, list):
            return value
        # Type narrowing: value is iterable but not a list
        from collections.abc import Iterable

        if isinstance(value, Iterable):
            return list(value)
        return []

    @override
    async def pttl(self, name: bytes | str) -> RedisResponseType:
        """Get the time to live in milliseconds for a key asynchronously.

        Args:
            name (bytes | str): The key name.

        Returns:
            RedisResponseType: Time to live in milliseconds.
        """
        return await self.read_only_client.pttl(name)

    @override
    async def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
        """Increment the integer value of a key by the given amount asynchronously.

        Args:
            name (RedisKeyType): The key name.
            amount (int): Amount to increment by. Defaults to 1.

        Returns:
            RedisResponseType: The new value after increment.
        """
        return await self.client.incrby(name, amount)

    @override
    async def set(
        self,
        name: RedisKeyType,
        value: RedisSetType,
        ex: RedisExpiryType | None = None,
        px: RedisExpiryType | None = None,
        nx: bool = False,
        xx: bool = False,
        keepttl: bool = False,
        get: bool = False,
        exat: RedisAbsExpiryType | None = None,
        pxat: RedisAbsExpiryType | None = None,
    ) -> RedisResponseType:
        """Set the value of a key with optional expiration asynchronously.

        Args:
            name (RedisKeyType): The key name.
            value (RedisSetType): The value to set.
            ex (RedisExpiryType | None): Expire time in seconds.
            px (RedisExpiryType | None): Expire time in milliseconds.
            nx (bool): Only set if key doesn't exist.
            xx (bool): Only set if key exists.
            keepttl (bool): Retain the TTL from the previous value.
            get (bool): Return the old value.
            exat (RedisAbsExpiryType | None): Absolute expiration time in seconds.
            pxat (RedisAbsExpiryType | None): Absolute expiration time in milliseconds.

        Returns:
            RedisResponseType: Result of the operation.
        """
        return await self.client.set(name, value, ex, px, nx, xx, keepttl, get, exat, pxat)

    @override
    async def get(self, key: str) -> RedisResponseType:
        """Get the value of a key asynchronously.

        Args:
            key (str): The key name.

        Returns:
            RedisResponseType: The value of the key or None if not exists.
        """
        return await self.read_only_client.get(key)

    @override
    async def mget(
        self,
        keys: RedisKeyType | Iterable[RedisKeyType],
        *args: bytes | str,
    ) -> RedisResponseType:
        """Get the values of multiple keys asynchronously.

        Args:
            keys (RedisKeyType | Iterable[RedisKeyType]): Single key or iterable of keys.
            *args (bytes | str): Additional keys.

        Returns:
            RedisResponseType: List of values.
        """
        return await self.read_only_client.mget(keys, *args)

    @override
    async def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
        """Set multiple keys to their values asynchronously.

        Args:
            mapping (Mapping[RedisKeyType, bytes | str | float]): Dictionary of key-value pairs.

        Returns:
            RedisResponseType: Always returns 'OK'.
        """
        # Convert Mapping to dict for type compatibility with Redis client
        dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
        return await self.client.mset(dict_mapping)

    @override
    async def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """Find all keys matching the pattern asynchronously.

        Args:
            pattern (RedisPatternType): Pattern to match keys against. Defaults to "*".
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: List of matching keys.
        """
        return await self.read_only_client.keys(pattern, **kwargs)

    @override
    async def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Set a key's value and return its old value asynchronously.

        Args:
            key (RedisKeyType): The key name.
            value (bytes | str | float): The new value.

        Returns:
            RedisResponseType: The previous value or None.
        """
        return await self.client.getset(key, value)

    @override
    async def getdel(self, key: bytes | str) -> RedisResponseType:
        """Get a key's value and delete it asynchronously.

        Args:
            key (bytes | str): The key name.

        Returns:
            RedisResponseType: The value of the key or None.
        """
        return await self.client.getdel(key)

    @override
    async def exists(self, *names: bytes | str) -> RedisResponseType:
        """Check if keys exist asynchronously.

        Args:
            *names (bytes | str): Variable number of key names.

        Returns:
            RedisResponseType: Number of keys that exist.
        """
        return await self.read_only_client.exists(*names)

    @override
    async def delete(self, *names: bytes | str) -> RedisResponseType:
        """Delete keys asynchronously.

        Args:
            *names (bytes | str): Variable number of key names.

        Returns:
            RedisResponseType: Number of keys deleted.
        """
        return await self.client.delete(*names)

    @override
    async def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Append a value to a key asynchronously.

        Args:
            key (RedisKeyType): The key name.
            value (bytes | str | float): The value to append.

        Returns:
            RedisResponseType: Length of the string after append.
        """
        return await self.client.append(key, value)

    @override
    async def ttl(self, name: bytes | str) -> RedisResponseType:
        """Get the time to live in seconds for a key asynchronously.

        Args:
            name (bytes | str): The key name.

        Returns:
            RedisResponseType: Time to live in seconds.
        """
        return await self.read_only_client.ttl(name)

    @override
    async def type(self, name: bytes | str) -> RedisResponseType:
        """Determine the type stored at key asynchronously.

        Args:
            name (bytes | str): The key name.

        Returns:
            RedisResponseType: Type of the key's value.
        """
        return await self.read_only_client.type(name)

    @override
    async def llen(self, name: str) -> RedisIntegerResponseType:
        """Get the length of a list asynchronously.

        Args:
            name (str): The key name of the list.

        Returns:
            RedisIntegerResponseType: Length of the list.
        """
        result = self.read_only_client.llen(name)
        return await self._ensure_async_int(result)

    @override
    async def lpop(self, name: str, count: int | None = None) -> Any:
        """Remove and return elements from list left asynchronously.

        Args:
            name (str): The key name of the list.
            count (int | None): Number of elements to pop. Defaults to None.

        Returns:
            Any: Popped element(s) or None if list is empty.
        """
        result = self.client.lpop(name, count)
        if isinstance(result, Awaitable):
            return await result
        return result

    @override
    async def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Push elements to list left asynchronously.

        Args:
            name (str): The key name of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: Length of the list after push.
        """
        result = self.client.lpush(name, *values)
        return await self._ensure_async_int(result)

    @override
    async def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
        """Get a range of elements from a list asynchronously.

        Args:
            name (str): The key name of the list.
            start (int): Start index.
            end (int): End index.

        Returns:
            RedisListResponseType: List of elements in range.
        """
        result = self.read_only_client.lrange(name, start, end)
        if isinstance(result, Awaitable):
            result = await result
        if result is None:
            return []
        if isinstance(result, list):
            return result
        from collections.abc import Iterable

        if isinstance(result, Iterable):
            return list(result)
        return []

    @override
    async def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
        """Remove elements from a list asynchronously.

        Args:
            name (str): The key name of the list.
            count (int): Number of occurrences to remove.
            value (str): Value to remove.

        Returns:
            RedisIntegerResponseType: Number of elements removed.
        """
        result = self.client.lrem(name, count, value)
        return await self._ensure_async_int(result)

    @override
    async def lset(self, name: str, index: int, value: str) -> bool:
        """Set list element by index asynchronously.

        Args:
            name (str): The key name of the list.
            index (int): Index of the element.
            value (str): New value.

        Returns:
            bool: True if successful.
        """
        result = self.client.lset(name, index, value)
        if isinstance(result, Awaitable):
            result = await result
        return bool(result)

    @override
    async def rpop(self, name: str, count: int | None = None) -> Any:
        """Remove and return elements from list right asynchronously.

        Args:
            name (str): The key name of the list.
            count (int | None): Number of elements to pop. Defaults to None.

        Returns:
            Any: Popped element(s) or None if list is empty.
        """
        result = self.client.rpop(name, count)
        if isinstance(result, Awaitable):
            return await result
        return result

    @override
    async def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Push elements to list right asynchronously.

        Args:
            name (str): The key name of the list.
            *values (bytes | str | float): Values to push.

        Returns:
            RedisIntegerResponseType: Length of the list after push.
        """
        result = self.client.rpush(name, *values)
        return await self._ensure_async_int(result)

    @override
    async def scan(
        self,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> RedisResponseType:
        """Scan keys in database incrementally asynchronously.

        Args:
            cursor (int): Cursor position. Defaults to 0.
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of keys. Defaults to None.
            _type (str | None): Filter by type. Defaults to None.
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: Tuple of cursor and list of keys.
        """
        return await self.read_only_client.scan(cursor, match, count, _type, **kwargs)

    @override
    async def scan_iter(
        self,
        match: bytes | str | None = None,
        count: int | None = None,
        _type: str | None = None,
        **kwargs: Any,
    ) -> Iterator[Any]:
        """Iterate over keys in database asynchronously.

        Args:
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of keys. Defaults to None.
            _type (str | None): Filter by type. Defaults to None.
            **kwargs (Any): Additional arguments.

        Returns:
            Iterator[Any]: Iterator over matching keys.
        """
        result = self.read_only_client.scan_iter(match, count, _type, **kwargs)
        if isinstance(result, Awaitable):
            raise TypeError("Unexpected awaitable from sync Redis client")
        # Type narrowing: result is an Iterator
        if not isinstance(result, Iterator):
            raise TypeError(f"Expected Iterator, got {type(result)}")
        return result

    @override
    async def sscan(
        self,
        name: RedisKeyType,
        cursor: int = 0,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> RedisResponseType:
        """Scan set members incrementally asynchronously.

        Args:
            name (RedisKeyType): The set key name.
            cursor (int): Cursor position. Defaults to 0.
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of elements. Defaults to None.

        Returns:
            RedisResponseType: Tuple of cursor and list of members.
        """
        result = self.read_only_client.sscan(name, cursor, match, count)
        if isinstance(result, Awaitable):
            awaited_result: RedisResponseType = await result
            return awaited_result
        return result

    @override
    async def sscan_iter(
        self,
        name: RedisKeyType,
        match: bytes | str | None = None,
        count: int | None = None,
    ) -> Iterator[Any]:
        """Iterate over set members asynchronously.

        Args:
            name (RedisKeyType): The set key name.
            match (bytes | str | None): Pattern to match. Defaults to None.
            count (int | None): Hint for number of elements. Defaults to None.

        Returns:
            Iterator[Any]: Iterator over set members.
        """
        result = self.read_only_client.sscan_iter(name, match, count)
        if isinstance(result, Awaitable):
            awaited_result = await result
            if not isinstance(awaited_result, Iterator):
                raise TypeError(f"Expected Iterator, got {type(awaited_result)}")
            return awaited_result
        # Type narrowing: result is an Iterator
        if not isinstance(result, Iterator):
            raise TypeError(f"Expected Iterator, got {type(result)}")
        return result

    @override
    async def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Add members to a set asynchronously.

        Args:
            name (str): The set key name.
            *values (bytes | str | float): Members to add.

        Returns:
            RedisIntegerResponseType: Number of elements added.
        """
        result = self.client.sadd(name, *values)
        return await self._ensure_async_int(result)

    @override
    async def scard(self, name: str) -> RedisIntegerResponseType:
        """Get number of members in a set asynchronously.

        Args:
            name (str): The set key name.

        Returns:
            RedisIntegerResponseType: Number of members.
        """
        result = self.client.scard(name)
        return await self._ensure_async_int(result)

    @override
    async def sismember(self, name: str, value: str) -> bool:
        """Check if value is in set asynchronously.

        Args:
            name (str): The set key name.
            value (str): Value to check.

        Returns:
            bool: True if value is member, False otherwise.
        """
        result = self.read_only_client.sismember(name, value)
        if isinstance(result, Awaitable):
            result = await result
        return bool(result)

    @override
    async def smembers(self, name: str) -> RedisSetResponseType:
        """Get all members of a set asynchronously.

        Args:
            name (str): The set key name.

        Returns:
            RedisSetResponseType: Set of all members.
        """
        result = self.read_only_client.smembers(name)
        if isinstance(result, Awaitable):
            result = await result
        if result is None:
            return set()
        if isinstance(result, set):
            return result
        from collections.abc import Iterable

        if isinstance(result, Iterable):
            return set(result)
        return set()

    @override
    async def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
        """Remove and return random set members asynchronously.

        Args:
            name (str): The set key name.
            count (int | None): Number of members to pop. Defaults to None.

        Returns:
            bytes | float | int | str | list | None: Popped member(s) or None.
        """
        result = self.client.spop(name, count)
        if isinstance(result, Awaitable):
            awaited_result = await result
            # Type narrowing: result can be any of the return types
            if awaited_result is None or isinstance(awaited_result, (bytes, float, int, str, list)):
                return awaited_result
            raise TypeError(f"Unexpected type from spop: {type(awaited_result)}")
        return result

    @override
    async def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
        """Remove members from a set asynchronously.

        Args:
            name (str): The set key name.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisIntegerResponseType: Number of members removed.
        """
        result = self.client.srem(name, *values)
        return await self._ensure_async_int(result)

    @override
    async def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
        """Get union of multiple sets asynchronously.

        Args:
            keys (RedisKeyType): First set key.
            *args (bytes | str): Additional set keys.

        Returns:
            RedisSetResponseType: Set containing union of all sets.
        """
        # Convert keys to str for type compatibility, combine into list
        keys_list: list[str] = [str(keys)] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
        result = self.client.sunion(keys_list)
        if isinstance(result, Awaitable):
            result = await result
        if result is None:
            return set()
        if isinstance(result, set):
            return result
        from collections.abc import Iterable

        if isinstance(result, Iterable):
            return set(result)
        return set()

    @override
    async def zadd(
        self,
        name: RedisKeyType,
        mapping: Mapping[RedisKeyType, bytes | str | float],
        nx: bool = False,
        xx: bool = False,
        ch: bool = False,
        incr: bool = False,
        gt: bool = False,
        lt: bool = False,
    ) -> RedisResponseType:
        """Add members to sorted set asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            mapping (Mapping[RedisKeyType, bytes | str | float]): Member-score pairs.
            nx (bool): Only add new elements. Defaults to False.
            xx (bool): Only update existing. Defaults to False.
            ch (bool): Return changed count. Defaults to False.
            incr (bool): Increment scores. Defaults to False.
            gt (bool): Only if greater. Defaults to False.
            lt (bool): Only if less. Defaults to False.

        Returns:
            RedisResponseType: Number of elements added or modified.
        """
        # Convert Mapping to dict for type compatibility with Redis client
        if isinstance(mapping, dict):
            dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
        else:
            dict_mapping = {str(k): v for k, v in mapping.items()}
        str_name = str(name)
        result = self.client.zadd(str_name, dict_mapping, nx, xx, ch, incr, gt, lt)
        if isinstance(result, Awaitable):
            return await result
        return result

    @override
    async def zcard(self, name: bytes | str) -> RedisResponseType:
        """Get number of members in sorted set asynchronously.

        Args:
            name (bytes | str): The sorted set key name.

        Returns:
            RedisResponseType: Number of members.
        """
        return await self.client.zcard(name)

    @override
    async def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
        """Count members in score range asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            min (float | str): Minimum score.
            max (float | str): Maximum score.

        Returns:
            RedisResponseType: Number of members in range.
        """
        return await self.client.zcount(name, min, max)

    @override
    async def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Pop highest scored members asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            count (int | None): Number to pop. Defaults to None.

        Returns:
            RedisResponseType: List of popped member-score pairs.
        """
        return await self.client.zpopmax(name, count)

    @override
    async def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
        """Pop lowest scored members asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            count (int | None): Number to pop. Defaults to None.

        Returns:
            RedisResponseType: List of popped member-score pairs.
        """
        return await self.client.zpopmin(name, count)

    @override
    async def zrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        desc: bool = False,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
        byscore: bool = False,
        bylex: bool = False,
        offset: int | None = None,
        num: int | None = None,
    ) -> RedisResponseType:
        """Get range from sorted set asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            start (int): Start index or score.
            end (int): End index or score.
            desc (bool): Descending order. Defaults to False.
            withscores (bool): Include scores. Defaults to False.
            score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.
            byscore (bool): Range by score. Defaults to False.
            bylex (bool): Range by lex. Defaults to False.
            offset (int | None): Offset for byscore/bylex. Defaults to None.
            num (int | None): Count for byscore/bylex. Defaults to None.

        Returns:
            RedisResponseType: List of members or member-score pairs.
        """
        return await self.client.zrange(
            name,
            start,
            end,
            desc,
            withscores,
            score_cast_func,
            byscore,
            bylex,
            offset,
            num,
        )

    @override
    async def zrevrange(
        self,
        name: RedisKeyType,
        start: int,
        end: int,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Get reverse range from sorted set asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            start (int): Start index.
            end (int): End index.
            withscores (bool): Include scores. Defaults to False.
            score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.

        Returns:
            RedisResponseType: List of members or member-score pairs.
        """
        return await self.client.zrevrange(name, start, end, withscores, score_cast_func)

    @override
    async def zrangebyscore(
        self,
        name: RedisKeyType,
        min: float | str,
        max: float | str,
        start: int | None = None,
        num: int | None = None,
        withscores: bool = False,
        score_cast_func: RedisScoreCastType = float,
    ) -> RedisResponseType:
        """Get members by score range asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            min (float | str): Minimum score.
            max (float | str): Maximum score.
            start (int | None): Offset. Defaults to None.
            num (int | None): Count. Defaults to None.
            withscores (bool): Include scores. Defaults to False.
            score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.

        Returns:
            RedisResponseType: List of members or member-score pairs.
        """
        return await self.client.zrangebyscore(name, min, max, start, num, withscores, score_cast_func)

    @override
    async def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Get rank of member in sorted set asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            value (bytes | str | float): Member to find rank for.

        Returns:
            RedisResponseType: Rank or None if not found.
        """
        return await self.client.zrank(name, value)

    @override
    async def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
        """Remove members from sorted set asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            *values (bytes | str | float): Members to remove.

        Returns:
            RedisResponseType: Number of members removed.
        """
        return await self.client.zrem(name, *values)

    @override
    async def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
        """Get score of member in sorted set asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            value (bytes | str | float): Member to get score for.

        Returns:
            RedisResponseType: Score or None if not found.
        """
        return await self.client.zscore(name, value)

    @override
    async def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
        """Delete fields from hash asynchronously.

        Args:
            name (str): The hash key name.
            *keys (str | bytes): Fields to delete.

        Returns:
            RedisIntegerResponseType: Number of fields deleted.
        """
        # Convert keys to str for type compatibility
        str_keys: tuple[str, ...] = tuple(str(k) if isinstance(k, bytes) else k for k in keys)
        result = self.client.hdel(name, *str_keys)
        return await self._ensure_async_int(result)

    @override
    async def hexists(self, name: str, key: str) -> bool:
        """Check if field exists in hash asynchronously.

        Args:
            name (str): The hash key name.
            key (str): Field to check.

        Returns:
            bool: True if exists, False otherwise.
        """
        result = self.read_only_client.hexists(name, key)
        return await self._ensure_async_bool(result)

    @override
    async def hget(self, name: str, key: str) -> str | None:
        """Get field value from hash asynchronously.

        Args:
            name (str): The hash key name.
            key (str): Field to get.

        Returns:
            str | None: Value or None.
        """
        result = self.read_only_client.hget(name, key)
        resolved = await self._ensure_async_str(result)
        return str(resolved) if resolved is not None else None

    @override
    async def hgetall(self, name: str) -> dict[str, Any]:
        """Get all fields and values from hash asynchronously.

        Args:
            name (str): The hash key name.

        Returns:
            dict[str, Any]: Dictionary of field-value pairs.
        """
        result = self.read_only_client.hgetall(name)
        if isinstance(result, Awaitable):
            awaited_result = await result
            if awaited_result is None:
                return {}
            if isinstance(awaited_result, dict):
                return {str(k): v for k, v in awaited_result.items()}
            from collections.abc import Mapping

            if isinstance(awaited_result, Mapping):
                return {str(k): v for k, v in awaited_result.items()}
            return {}
        if result is None:
            return {}
        if isinstance(result, dict):
            return {str(k): v for k, v in result.items()}
        from collections.abc import Mapping

        if isinstance(result, Mapping):
            return {str(k): v for k, v in result.items()}
        return {}

    @override
    async def hkeys(self, name: str) -> RedisListResponseType:
        """Get all fields from hash asynchronously.

        Args:
            name (str): The hash key name.

        Returns:
            RedisListResponseType: List of field names.
        """
        result = self.read_only_client.hkeys(name)
        return await self._ensure_async_list(result)

    @override
    async def hlen(self, name: str) -> RedisIntegerResponseType:
        """Get number of fields in hash asynchronously.

        Args:
            name (str): The hash key name.

        Returns:
            RedisIntegerResponseType: Number of fields.
        """
        result = self.read_only_client.hlen(name)
        return await self._ensure_async_int(result)

    @override
    async def hset(
        self,
        name: str,
        key: str | bytes | None = None,
        value: str | bytes | None = None,
        mapping: dict | None = None,
        items: list | None = None,
    ) -> RedisIntegerResponseType:
        """Set fields in hash asynchronously.

        Args:
            name (str): The hash key name.
            key (str | bytes | None): Single field name. Defaults to None.
            value (str | bytes | None): Single field value. Defaults to None.
            mapping (dict | None): Field-value pairs dict. Defaults to None.
            items (list | None): Field-value pairs list. Defaults to None.

        Returns:
            RedisIntegerResponseType: Number of fields set.
        """
        # Convert bytes to str for type compatibility with Redis client
        str_key: str | None = str(key) if key is not None and isinstance(key, bytes) else key
        str_value: str | None = str(value) if value is not None and isinstance(value, bytes) else value
        result = self.client.hset(name, str_key, str_value, mapping, items)
        return await self._ensure_async_int(result)

    @override
    async def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
        """Get multiple field values from hash asynchronously.

        Args:
            name (str): The hash key name.
            keys (list): List of field names.
            *args (str | bytes): Additional field names.

        Returns:
            RedisListResponseType: List of field values.
        """
        # Convert keys list and args for type compatibility, combine into single list
        keys_list: list[str] = [str(k) for k in keys] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
        result = self.read_only_client.hmget(name, keys_list)
        return await self._ensure_async_list(result)

    @override
    async def hvals(self, name: str) -> RedisListResponseType:
        """Get all values from hash asynchronously.

        Args:
            name (str): The hash key name.

        Returns:
            RedisListResponseType: List of values.
        """
        result = self.read_only_client.hvals(name)
        return await self._ensure_async_list(result)

    @override
    async def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
        """Publish message to channel asynchronously.

        Args:
            channel (RedisKeyType): Channel name.
            message (bytes | str): Message to publish.
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: Number of subscribers received message.
        """
        # AsyncRedis client has publish method, type stubs may be incomplete
        publish_method = getattr(self.client, "publish", None)
        if publish_method and callable(publish_method):
            result = publish_method(channel, message, **kwargs)
            if isinstance(result, Awaitable):
                return await result
            return result
        raise AttributeError("publish method not available on Redis client")

    @override
    async def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
        """List active channels matching pattern asynchronously.

        Args:
            pattern (RedisPatternType): Pattern to match. Defaults to "*".
            **kwargs (Any): Additional arguments.

        Returns:
            RedisResponseType: List of channel names.
        """
        # AsyncRedis client has pubsub_channels method, type stubs may be incomplete
        pubsub_channels_method = getattr(self.client, "pubsub_channels", None)
        if pubsub_channels_method and callable(pubsub_channels_method):
            result = pubsub_channels_method(pattern, **kwargs)
            if isinstance(result, Awaitable):
                return await result
            return result
        raise AttributeError("pubsub_channels method not available on Redis client")

    @override
    async def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
        """Increment member score in sorted set asynchronously.

        Args:
            name (RedisKeyType): The sorted set key name.
            amount (float): Amount to increment by.
            value (bytes | str | float): Member to increment.

        Returns:
            RedisResponseType: New score of the member.
        """
        return await self.client.zincrby(name, amount, value)

    @override
    async def pubsub(self, **kwargs: Any) -> AsyncPubSub:
        """Get PubSub object for channel subscription asynchronously.

        Args:
            **kwargs (Any): Additional arguments.

        Returns:
            AsyncPubSub: PubSub object.
        """
        # Redis client has pubsub method, type stubs may be incomplete
        pubsub_method = getattr(self.client, "pubsub", None)
        if pubsub_method and callable(pubsub_method):
            return pubsub_method(**kwargs)
        raise AttributeError("pubsub method not available on Redis client")

    @override
    async def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> AsyncPipeline:
        """Get pipeline for multiple commands asynchronously.

        Args:
            transaction (Any): Use transactions. Defaults to True.
            shard_hint (Any): Sharding hint. Defaults to None.

        Returns:
            AsyncPipeline: Pipeline object.
        """
        result = self.client.pipeline(transaction, shard_hint)
        # Type narrowing: result is an AsyncPipeline
        if not isinstance(result, AsyncPipeline):
            raise TypeError(f"Expected AsyncPipeline, got {type(result)}")
        return result

    @override
    async def ping(self) -> RedisResponseType:
        """Ping the Redis server asynchronously.

        Returns:
            RedisResponseType: 'PONG' if successful.
        """
        result = self.client.ping()
        if isinstance(result, Awaitable):
            return await result
        return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.cluster_info async

cluster_info() -> RedisResponseType

Get cluster information asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_info(self) -> RedisResponseType:
    """Get cluster information asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_info()
    return None

archipy.adapters.redis.adapters.AsyncRedisAdapter.cluster_nodes async

cluster_nodes() -> RedisResponseType

Get cluster nodes information asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_nodes(self) -> RedisResponseType:
    """Get cluster nodes information asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_nodes()
    return None

archipy.adapters.redis.adapters.AsyncRedisAdapter.cluster_slots async

cluster_slots() -> RedisResponseType

Get cluster slots mapping asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_slots(self) -> RedisResponseType:
    """Get cluster slots mapping asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_slots()
    return None

archipy.adapters.redis.adapters.AsyncRedisAdapter.cluster_key_slot async

cluster_key_slot(key: str) -> RedisResponseType

Get the hash slot for a key asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_key_slot(self, key: str) -> RedisResponseType:
    """Get the hash slot for a key asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_keyslot(key)
    return None

archipy.adapters.redis.adapters.AsyncRedisAdapter.cluster_count_keys_in_slot async

cluster_count_keys_in_slot(slot: int) -> RedisResponseType

Count keys in a specific slot asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
    """Count keys in a specific slot asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_countkeysinslot(slot)
    return None

archipy.adapters.redis.adapters.AsyncRedisAdapter.cluster_get_keys_in_slot async

cluster_get_keys_in_slot(
    slot: int, count: int
) -> RedisResponseType

Get keys in a specific slot asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
    """Get keys in a specific slot asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_get_keys_in_slot(slot, count)
    return None

archipy.adapters.redis.adapters.AsyncRedisAdapter.pttl async

pttl(name: bytes | str) -> RedisResponseType

Get the time to live in milliseconds for a key asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in milliseconds.

Source code in archipy/adapters/redis/adapters.py
@override
async def pttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in milliseconds for a key asynchronously.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in milliseconds.
    """
    return await self.read_only_client.pttl(name)

archipy.adapters.redis.adapters.AsyncRedisAdapter.incrby async

incrby(
    name: RedisKeyType, amount: int = 1
) -> RedisResponseType

Increment the integer value of a key by the given amount asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
amount int

Amount to increment by. Defaults to 1.

1

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new value after increment.

Source code in archipy/adapters/redis/adapters.py
@override
async def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
    """Increment the integer value of a key by the given amount asynchronously.

    Args:
        name (RedisKeyType): The key name.
        amount (int): Amount to increment by. Defaults to 1.

    Returns:
        RedisResponseType: The new value after increment.
    """
    return await self.client.incrby(name, amount)

archipy.adapters.redis.adapters.AsyncRedisAdapter.set async

set(
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType

Set the value of a key with optional expiration asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
value RedisSetType

The value to set.

required
ex RedisExpiryType | None

Expire time in seconds.

None
px RedisExpiryType | None

Expire time in milliseconds.

None
nx bool

Only set if key doesn't exist.

False
xx bool

Only set if key exists.

False
keepttl bool

Retain the TTL from the previous value.

False
get bool

Return the old value.

False
exat RedisAbsExpiryType | None

Absolute expiration time in seconds.

None
pxat RedisAbsExpiryType | None

Absolute expiration time in milliseconds.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Result of the operation.

Source code in archipy/adapters/redis/adapters.py
@override
async def set(
    self,
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType:
    """Set the value of a key with optional expiration asynchronously.

    Args:
        name (RedisKeyType): The key name.
        value (RedisSetType): The value to set.
        ex (RedisExpiryType | None): Expire time in seconds.
        px (RedisExpiryType | None): Expire time in milliseconds.
        nx (bool): Only set if key doesn't exist.
        xx (bool): Only set if key exists.
        keepttl (bool): Retain the TTL from the previous value.
        get (bool): Return the old value.
        exat (RedisAbsExpiryType | None): Absolute expiration time in seconds.
        pxat (RedisAbsExpiryType | None): Absolute expiration time in milliseconds.

    Returns:
        RedisResponseType: Result of the operation.
    """
    return await self.client.set(name, value, ex, px, nx, xx, keepttl, get, exat, pxat)

archipy.adapters.redis.adapters.AsyncRedisAdapter.get async

get(key: str) -> RedisResponseType

Get the value of a key asynchronously.

Parameters:

Name Type Description Default
key str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None if not exists.

Source code in archipy/adapters/redis/adapters.py
@override
async def get(self, key: str) -> RedisResponseType:
    """Get the value of a key asynchronously.

    Args:
        key (str): The key name.

    Returns:
        RedisResponseType: The value of the key or None if not exists.
    """
    return await self.read_only_client.get(key)

archipy.adapters.redis.adapters.AsyncRedisAdapter.mget async

mget(
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType

Get the values of multiple keys asynchronously.

Parameters:

Name Type Description Default
keys RedisKeyType | Iterable[RedisKeyType]

Single key or iterable of keys.

required
*args bytes | str

Additional keys.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
async def mget(
    self,
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType:
    """Get the values of multiple keys asynchronously.

    Args:
        keys (RedisKeyType | Iterable[RedisKeyType]): Single key or iterable of keys.
        *args (bytes | str): Additional keys.

    Returns:
        RedisResponseType: List of values.
    """
    return await self.read_only_client.mget(keys, *args)

archipy.adapters.redis.adapters.AsyncRedisAdapter.mset async

mset(
    mapping: Mapping[RedisKeyType, bytes | str | float],
) -> RedisResponseType

Set multiple keys to their values asynchronously.

Parameters:

Name Type Description Default
mapping Mapping[RedisKeyType, bytes | str | float]

Dictionary of key-value pairs.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Always returns 'OK'.

Source code in archipy/adapters/redis/adapters.py
@override
async def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
    """Set multiple keys to their values asynchronously.

    Args:
        mapping (Mapping[RedisKeyType, bytes | str | float]): Dictionary of key-value pairs.

    Returns:
        RedisResponseType: Always returns 'OK'.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    return await self.client.mset(dict_mapping)

archipy.adapters.redis.adapters.AsyncRedisAdapter.keys async

keys(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Find all keys matching the pattern asynchronously.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match keys against. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
async def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Find all keys matching the pattern asynchronously.

    Args:
        pattern (RedisPatternType): Pattern to match keys against. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of matching keys.
    """
    return await self.read_only_client.keys(pattern, **kwargs)

archipy.adapters.redis.adapters.AsyncRedisAdapter.getset async

getset(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Set a key's value and return its old value asynchronously.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The new value.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The previous value or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Set a key's value and return its old value asynchronously.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The new value.

    Returns:
        RedisResponseType: The previous value or None.
    """
    return await self.client.getset(key, value)

archipy.adapters.redis.adapters.AsyncRedisAdapter.getdel async

getdel(key: bytes | str) -> RedisResponseType

Get a key's value and delete it asynchronously.

Parameters:

Name Type Description Default
key bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def getdel(self, key: bytes | str) -> RedisResponseType:
    """Get a key's value and delete it asynchronously.

    Args:
        key (bytes | str): The key name.

    Returns:
        RedisResponseType: The value of the key or None.
    """
    return await self.client.getdel(key)

archipy.adapters.redis.adapters.AsyncRedisAdapter.exists async

exists(*names: bytes | str) -> RedisResponseType

Check if keys exist asynchronously.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys that exist.

Source code in archipy/adapters/redis/adapters.py
@override
async def exists(self, *names: bytes | str) -> RedisResponseType:
    """Check if keys exist asynchronously.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys that exist.
    """
    return await self.read_only_client.exists(*names)

archipy.adapters.redis.adapters.AsyncRedisAdapter.delete async

delete(*names: bytes | str) -> RedisResponseType

Delete keys asynchronously.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys deleted.

Source code in archipy/adapters/redis/adapters.py
@override
async def delete(self, *names: bytes | str) -> RedisResponseType:
    """Delete keys asynchronously.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys deleted.
    """
    return await self.client.delete(*names)

archipy.adapters.redis.adapters.AsyncRedisAdapter.append async

append(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Append a value to a key asynchronously.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The value to append.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Length of the string after append.

Source code in archipy/adapters/redis/adapters.py
@override
async def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Append a value to a key asynchronously.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The value to append.

    Returns:
        RedisResponseType: Length of the string after append.
    """
    return await self.client.append(key, value)

archipy.adapters.redis.adapters.AsyncRedisAdapter.ttl async

ttl(name: bytes | str) -> RedisResponseType

Get the time to live in seconds for a key asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in seconds.

Source code in archipy/adapters/redis/adapters.py
@override
async def ttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in seconds for a key asynchronously.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in seconds.
    """
    return await self.read_only_client.ttl(name)

archipy.adapters.redis.adapters.AsyncRedisAdapter.type async

type(name: bytes | str) -> RedisResponseType

Determine the type stored at key asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Type of the key's value.

Source code in archipy/adapters/redis/adapters.py
@override
async def type(self, name: bytes | str) -> RedisResponseType:
    """Determine the type stored at key asynchronously.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Type of the key's value.
    """
    return await self.read_only_client.type(name)

archipy.adapters.redis.adapters.AsyncRedisAdapter.llen async

llen(name: str) -> RedisIntegerResponseType

Get the length of a list asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list.

Source code in archipy/adapters/redis/adapters.py
@override
async def llen(self, name: str) -> RedisIntegerResponseType:
    """Get the length of a list asynchronously.

    Args:
        name (str): The key name of the list.

    Returns:
        RedisIntegerResponseType: Length of the list.
    """
    result = self.read_only_client.llen(name)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.lpop async

lpop(name: str, count: int | None = None) -> Any

Remove and return elements from list left asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
async def lpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from list left asynchronously.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    result = self.client.lpop(name, count)
    if isinstance(result, Awaitable):
        return await result
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.lpush async

lpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to list left asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
async def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to list left asynchronously.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.lpush(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.lrange async

lrange(
    name: str, start: int, end: int
) -> RedisListResponseType

Get a range of elements from a list asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
start int

Start index.

required
end int

End index.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of elements in range.

Source code in archipy/adapters/redis/adapters.py
@override
async def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
    """Get a range of elements from a list asynchronously.

    Args:
        name (str): The key name of the list.
        start (int): Start index.
        end (int): End index.

    Returns:
        RedisListResponseType: List of elements in range.
    """
    result = self.read_only_client.lrange(name, start, end)
    if isinstance(result, Awaitable):
        result = await result
    if result is None:
        return []
    if isinstance(result, list):
        return result
    from collections.abc import Iterable

    if isinstance(result, Iterable):
        return list(result)
    return []

archipy.adapters.redis.adapters.AsyncRedisAdapter.lrem async

lrem(
    name: str, count: int, value: str
) -> RedisIntegerResponseType

Remove elements from a list asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int

Number of occurrences to remove.

required
value str

Value to remove.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements removed.

Source code in archipy/adapters/redis/adapters.py
@override
async def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
    """Remove elements from a list asynchronously.

    Args:
        name (str): The key name of the list.
        count (int): Number of occurrences to remove.
        value (str): Value to remove.

    Returns:
        RedisIntegerResponseType: Number of elements removed.
    """
    result = self.client.lrem(name, count, value)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.lset async

lset(name: str, index: int, value: str) -> bool

Set list element by index asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
index int

Index of the element.

required
value str

New value.

required

Returns:

Name Type Description
bool bool

True if successful.

Source code in archipy/adapters/redis/adapters.py
@override
async def lset(self, name: str, index: int, value: str) -> bool:
    """Set list element by index asynchronously.

    Args:
        name (str): The key name of the list.
        index (int): Index of the element.
        value (str): New value.

    Returns:
        bool: True if successful.
    """
    result = self.client.lset(name, index, value)
    if isinstance(result, Awaitable):
        result = await result
    return bool(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.rpop async

rpop(name: str, count: int | None = None) -> Any

Remove and return elements from list right asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
async def rpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from list right asynchronously.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    result = self.client.rpop(name, count)
    if isinstance(result, Awaitable):
        return await result
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.rpush async

rpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to list right asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
async def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to list right asynchronously.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.rpush(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.scan async

scan(
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType

Scan keys in database incrementally asynchronously.

Parameters:

Name Type Description Default
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of keys.

Source code in archipy/adapters/redis/adapters.py
@override
async def scan(
    self,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType:
    """Scan keys in database incrementally asynchronously.

    Args:
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Tuple of cursor and list of keys.
    """
    return await self.read_only_client.scan(cursor, match, count, _type, **kwargs)

archipy.adapters.redis.adapters.AsyncRedisAdapter.scan_iter async

scan_iter(
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator[Any]

Iterate over keys in database asynchronously.

Parameters:

Name Type Description Default
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Type Description
Iterator[Any]

Iterator[Any]: Iterator over matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
async def scan_iter(
    self,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator[Any]:
    """Iterate over keys in database asynchronously.

    Args:
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        Iterator[Any]: Iterator over matching keys.
    """
    result = self.read_only_client.scan_iter(match, count, _type, **kwargs)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    # Type narrowing: result is an Iterator
    if not isinstance(result, Iterator):
        raise TypeError(f"Expected Iterator, got {type(result)}")
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.sscan async

sscan(
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType

Scan set members incrementally asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of members.

Source code in archipy/adapters/redis/adapters.py
@override
async def sscan(
    self,
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType:
    """Scan set members incrementally asynchronously.

    Args:
        name (RedisKeyType): The set key name.
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        RedisResponseType: Tuple of cursor and list of members.
    """
    result = self.read_only_client.sscan(name, cursor, match, count)
    if isinstance(result, Awaitable):
        awaited_result: RedisResponseType = await result
        return awaited_result
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.sscan_iter async

sscan_iter(
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator[Any]

Iterate over set members asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Type Description
Iterator[Any]

Iterator[Any]: Iterator over set members.

Source code in archipy/adapters/redis/adapters.py
@override
async def sscan_iter(
    self,
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator[Any]:
    """Iterate over set members asynchronously.

    Args:
        name (RedisKeyType): The set key name.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        Iterator[Any]: Iterator over set members.
    """
    result = self.read_only_client.sscan_iter(name, match, count)
    if isinstance(result, Awaitable):
        awaited_result = await result
        if not isinstance(awaited_result, Iterator):
            raise TypeError(f"Expected Iterator, got {type(awaited_result)}")
        return awaited_result
    # Type narrowing: result is an Iterator
    if not isinstance(result, Iterator):
        raise TypeError(f"Expected Iterator, got {type(result)}")
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.sadd async

sadd(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Add members to a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to add.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements added.

Source code in archipy/adapters/redis/adapters.py
@override
async def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Add members to a set asynchronously.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to add.

    Returns:
        RedisIntegerResponseType: Number of elements added.
    """
    result = self.client.sadd(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.scard async

scard(name: str) -> RedisIntegerResponseType

Get number of members in a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
async def scard(self, name: str) -> RedisIntegerResponseType:
    """Get number of members in a set asynchronously.

    Args:
        name (str): The set key name.

    Returns:
        RedisIntegerResponseType: Number of members.
    """
    result = self.client.scard(name)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.sismember async

sismember(name: str, value: str) -> bool

Check if value is in set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
value str

Value to check.

required

Returns:

Name Type Description
bool bool

True if value is member, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
async def sismember(self, name: str, value: str) -> bool:
    """Check if value is in set asynchronously.

    Args:
        name (str): The set key name.
        value (str): Value to check.

    Returns:
        bool: True if value is member, False otherwise.
    """
    result = self.read_only_client.sismember(name, value)
    if isinstance(result, Awaitable):
        result = await result
    return bool(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.smembers async

smembers(name: str) -> RedisSetResponseType

Get all members of a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set of all members.

Source code in archipy/adapters/redis/adapters.py
@override
async def smembers(self, name: str) -> RedisSetResponseType:
    """Get all members of a set asynchronously.

    Args:
        name (str): The set key name.

    Returns:
        RedisSetResponseType: Set of all members.
    """
    result = self.read_only_client.smembers(name)
    if isinstance(result, Awaitable):
        result = await result
    if result is None:
        return set()
    if isinstance(result, set):
        return result
    from collections.abc import Iterable

    if isinstance(result, Iterable):
        return set(result)
    return set()

archipy.adapters.redis.adapters.AsyncRedisAdapter.spop async

spop(
    name: str, count: int | None = None
) -> bytes | float | int | str | list | None

Remove and return random set members asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Type Description
bytes | float | int | str | list | None

bytes | float | int | str | list | None: Popped member(s) or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
    """Remove and return random set members asynchronously.

    Args:
        name (str): The set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        bytes | float | int | str | list | None: Popped member(s) or None.
    """
    result = self.client.spop(name, count)
    if isinstance(result, Awaitable):
        awaited_result = await result
        # Type narrowing: result can be any of the return types
        if awaited_result is None or isinstance(awaited_result, (bytes, float, int, str, list)):
            return awaited_result
        raise TypeError(f"Unexpected type from spop: {type(awaited_result)}")
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.srem async

srem(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Remove members from a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
async def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Remove members from a set asynchronously.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisIntegerResponseType: Number of members removed.
    """
    result = self.client.srem(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.sunion async

sunion(
    keys: RedisKeyType, *args: bytes | str
) -> RedisSetResponseType

Get union of multiple sets asynchronously.

Parameters:

Name Type Description Default
keys RedisKeyType

First set key.

required
*args bytes | str

Additional set keys.

()

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set containing union of all sets.

Source code in archipy/adapters/redis/adapters.py
@override
async def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
    """Get union of multiple sets asynchronously.

    Args:
        keys (RedisKeyType): First set key.
        *args (bytes | str): Additional set keys.

    Returns:
        RedisSetResponseType: Set containing union of all sets.
    """
    # Convert keys to str for type compatibility, combine into list
    keys_list: list[str] = [str(keys)] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
    result = self.client.sunion(keys_list)
    if isinstance(result, Awaitable):
        result = await result
    if result is None:
        return set()
    if isinstance(result, set):
        return result
    from collections.abc import Iterable

    if isinstance(result, Iterable):
        return set(result)
    return set()

archipy.adapters.redis.adapters.AsyncRedisAdapter.zadd async

zadd(
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType

Add members to sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
mapping Mapping[RedisKeyType, bytes | str | float]

Member-score pairs.

required
nx bool

Only add new elements. Defaults to False.

False
xx bool

Only update existing. Defaults to False.

False
ch bool

Return changed count. Defaults to False.

False
incr bool

Increment scores. Defaults to False.

False
gt bool

Only if greater. Defaults to False.

False
lt bool

Only if less. Defaults to False.

False

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of elements added or modified.

Source code in archipy/adapters/redis/adapters.py
@override
async def zadd(
    self,
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType:
    """Add members to sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        mapping (Mapping[RedisKeyType, bytes | str | float]): Member-score pairs.
        nx (bool): Only add new elements. Defaults to False.
        xx (bool): Only update existing. Defaults to False.
        ch (bool): Return changed count. Defaults to False.
        incr (bool): Increment scores. Defaults to False.
        gt (bool): Only if greater. Defaults to False.
        lt (bool): Only if less. Defaults to False.

    Returns:
        RedisResponseType: Number of elements added or modified.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    if isinstance(mapping, dict):
        dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    else:
        dict_mapping = {str(k): v for k, v in mapping.items()}
    str_name = str(name)
    result = self.client.zadd(str_name, dict_mapping, nx, xx, ch, incr, gt, lt)
    if isinstance(result, Awaitable):
        return await result
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.zcard async

zcard(name: bytes | str) -> RedisResponseType

Get number of members in sorted set asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The sorted set key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
async def zcard(self, name: bytes | str) -> RedisResponseType:
    """Get number of members in sorted set asynchronously.

    Args:
        name (bytes | str): The sorted set key name.

    Returns:
        RedisResponseType: Number of members.
    """
    return await self.client.zcard(name)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zcount async

zcount(
    name: RedisKeyType, min: float | str, max: float | str
) -> RedisResponseType

Count members in score range asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members in range.

Source code in archipy/adapters/redis/adapters.py
@override
async def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
    """Count members in score range asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.

    Returns:
        RedisResponseType: Number of members in range.
    """
    return await self.client.zcount(name, min, max)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zpopmax async

zpopmax(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Pop highest scored members asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Pop highest scored members asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return await self.client.zpopmax(name, count)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zpopmin async

zpopmin(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Pop lowest scored members asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Pop lowest scored members asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return await self.client.zpopmin(name, count)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zrange async

zrange(
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType

Get range from sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index or score.

required
end int

End index or score.

required
desc bool

Descending order. Defaults to False.

False
withscores bool

Include scores. Defaults to False.

False
score_cast_func RedisScoreCastType

Score cast function. Defaults to float.

float
byscore bool

Range by score. Defaults to False.

False
bylex bool

Range by lex. Defaults to False.

False
offset int | None

Offset for byscore/bylex. Defaults to None.

None
num int | None

Count for byscore/bylex. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType:
    """Get range from sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index or score.
        end (int): End index or score.
        desc (bool): Descending order. Defaults to False.
        withscores (bool): Include scores. Defaults to False.
        score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.
        byscore (bool): Range by score. Defaults to False.
        bylex (bool): Range by lex. Defaults to False.
        offset (int | None): Offset for byscore/bylex. Defaults to None.
        num (int | None): Count for byscore/bylex. Defaults to None.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return await self.client.zrange(
        name,
        start,
        end,
        desc,
        withscores,
        score_cast_func,
        byscore,
        bylex,
        offset,
        num,
    )

archipy.adapters.redis.adapters.AsyncRedisAdapter.zrevrange async

zrevrange(
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get reverse range from sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index.

required
end int

End index.

required
withscores bool

Include scores. Defaults to False.

False
score_cast_func RedisScoreCastType

Score cast function. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrevrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get reverse range from sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index.
        end (int): End index.
        withscores (bool): Include scores. Defaults to False.
        score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return await self.client.zrevrange(name, start, end, withscores, score_cast_func)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zrangebyscore async

zrangebyscore(
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get members by score range asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required
start int | None

Offset. Defaults to None.

None
num int | None

Count. Defaults to None.

None
withscores bool

Include scores. Defaults to False.

False
score_cast_func RedisScoreCastType

Score cast function. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrangebyscore(
    self,
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get members by score range asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.
        start (int | None): Offset. Defaults to None.
        num (int | None): Count. Defaults to None.
        withscores (bool): Include scores. Defaults to False.
        score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return await self.client.zrangebyscore(name, min, max, start, num, withscores, score_cast_func)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zrank async

zrank(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get rank of member in sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to find rank for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Rank or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get rank of member in sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to find rank for.

    Returns:
        RedisResponseType: Rank or None if not found.
    """
    return await self.client.zrank(name, value)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zrem async

zrem(
    name: RedisKeyType, *values: bytes | str | float
) -> RedisResponseType

Remove members from sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
    """Remove members from sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisResponseType: Number of members removed.
    """
    return await self.client.zrem(name, *values)

archipy.adapters.redis.adapters.AsyncRedisAdapter.zscore async

zscore(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get score of member in sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to get score for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Score or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
async def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get score of member in sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to get score for.

    Returns:
        RedisResponseType: Score or None if not found.
    """
    return await self.client.zscore(name, value)

archipy.adapters.redis.adapters.AsyncRedisAdapter.hdel async

hdel(
    name: str, *keys: str | bytes
) -> RedisIntegerResponseType

Delete fields from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
*keys str | bytes

Fields to delete.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields deleted.

Source code in archipy/adapters/redis/adapters.py
@override
async def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
    """Delete fields from hash asynchronously.

    Args:
        name (str): The hash key name.
        *keys (str | bytes): Fields to delete.

    Returns:
        RedisIntegerResponseType: Number of fields deleted.
    """
    # Convert keys to str for type compatibility
    str_keys: tuple[str, ...] = tuple(str(k) if isinstance(k, bytes) else k for k in keys)
    result = self.client.hdel(name, *str_keys)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.hexists async

hexists(name: str, key: str) -> bool

Check if field exists in hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to check.

required

Returns:

Name Type Description
bool bool

True if exists, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
async def hexists(self, name: str, key: str) -> bool:
    """Check if field exists in hash asynchronously.

    Args:
        name (str): The hash key name.
        key (str): Field to check.

    Returns:
        bool: True if exists, False otherwise.
    """
    result = self.read_only_client.hexists(name, key)
    return await self._ensure_async_bool(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.hget async

hget(name: str, key: str) -> str | None

Get field value from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to get.

required

Returns:

Type Description
str | None

str | None: Value or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def hget(self, name: str, key: str) -> str | None:
    """Get field value from hash asynchronously.

    Args:
        name (str): The hash key name.
        key (str): Field to get.

    Returns:
        str | None: Value or None.
    """
    result = self.read_only_client.hget(name, key)
    resolved = await self._ensure_async_str(result)
    return str(resolved) if resolved is not None else None

archipy.adapters.redis.adapters.AsyncRedisAdapter.hgetall async

hgetall(name: str) -> dict[str, Any]

Get all fields and values from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Dictionary of field-value pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def hgetall(self, name: str) -> dict[str, Any]:
    """Get all fields and values from hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        dict[str, Any]: Dictionary of field-value pairs.
    """
    result = self.read_only_client.hgetall(name)
    if isinstance(result, Awaitable):
        awaited_result = await result
        if awaited_result is None:
            return {}
        if isinstance(awaited_result, dict):
            return {str(k): v for k, v in awaited_result.items()}
        from collections.abc import Mapping

        if isinstance(awaited_result, Mapping):
            return {str(k): v for k, v in awaited_result.items()}
        return {}
    if result is None:
        return {}
    if isinstance(result, dict):
        return {str(k): v for k, v in result.items()}
    from collections.abc import Mapping

    if isinstance(result, Mapping):
        return {str(k): v for k, v in result.items()}
    return {}

archipy.adapters.redis.adapters.AsyncRedisAdapter.hkeys async

hkeys(name: str) -> RedisListResponseType

Get all fields from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field names.

Source code in archipy/adapters/redis/adapters.py
@override
async def hkeys(self, name: str) -> RedisListResponseType:
    """Get all fields from hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of field names.
    """
    result = self.read_only_client.hkeys(name)
    return await self._ensure_async_list(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.hlen async

hlen(name: str) -> RedisIntegerResponseType

Get number of fields in hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields.

Source code in archipy/adapters/redis/adapters.py
@override
async def hlen(self, name: str) -> RedisIntegerResponseType:
    """Get number of fields in hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        RedisIntegerResponseType: Number of fields.
    """
    result = self.read_only_client.hlen(name)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.hset async

hset(
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType

Set fields in hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str | bytes | None

Single field name. Defaults to None.

None
value str | bytes | None

Single field value. Defaults to None.

None
mapping dict | None

Field-value pairs dict. Defaults to None.

None
items list | None

Field-value pairs list. Defaults to None.

None

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields set.

Source code in archipy/adapters/redis/adapters.py
@override
async def hset(
    self,
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType:
    """Set fields in hash asynchronously.

    Args:
        name (str): The hash key name.
        key (str | bytes | None): Single field name. Defaults to None.
        value (str | bytes | None): Single field value. Defaults to None.
        mapping (dict | None): Field-value pairs dict. Defaults to None.
        items (list | None): Field-value pairs list. Defaults to None.

    Returns:
        RedisIntegerResponseType: Number of fields set.
    """
    # Convert bytes to str for type compatibility with Redis client
    str_key: str | None = str(key) if key is not None and isinstance(key, bytes) else key
    str_value: str | None = str(value) if value is not None and isinstance(value, bytes) else value
    result = self.client.hset(name, str_key, str_value, mapping, items)
    return await self._ensure_async_int(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.hmget async

hmget(
    name: str, keys: list, *args: str | bytes
) -> RedisListResponseType

Get multiple field values from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
keys list

List of field names.

required
*args str | bytes

Additional field names.

()

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field values.

Source code in archipy/adapters/redis/adapters.py
@override
async def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
    """Get multiple field values from hash asynchronously.

    Args:
        name (str): The hash key name.
        keys (list): List of field names.
        *args (str | bytes): Additional field names.

    Returns:
        RedisListResponseType: List of field values.
    """
    # Convert keys list and args for type compatibility, combine into single list
    keys_list: list[str] = [str(k) for k in keys] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
    result = self.read_only_client.hmget(name, keys_list)
    return await self._ensure_async_list(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.hvals async

hvals(name: str) -> RedisListResponseType

Get all values from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
async def hvals(self, name: str) -> RedisListResponseType:
    """Get all values from hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of values.
    """
    result = self.read_only_client.hvals(name)
    return await self._ensure_async_list(result)

archipy.adapters.redis.adapters.AsyncRedisAdapter.publish async

publish(
    channel: RedisKeyType,
    message: bytes | str,
    **kwargs: Any,
) -> RedisResponseType

Publish message to channel asynchronously.

Parameters:

Name Type Description Default
channel RedisKeyType

Channel name.

required
message bytes | str

Message to publish.

required
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of subscribers received message.

Source code in archipy/adapters/redis/adapters.py
@override
async def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
    """Publish message to channel asynchronously.

    Args:
        channel (RedisKeyType): Channel name.
        message (bytes | str): Message to publish.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Number of subscribers received message.
    """
    # AsyncRedis client has publish method, type stubs may be incomplete
    publish_method = getattr(self.client, "publish", None)
    if publish_method and callable(publish_method):
        result = publish_method(channel, message, **kwargs)
        if isinstance(result, Awaitable):
            return await result
        return result
    raise AttributeError("publish method not available on Redis client")

archipy.adapters.redis.adapters.AsyncRedisAdapter.pubsub_channels async

pubsub_channels(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

List active channels matching pattern asynchronously.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of channel names.

Source code in archipy/adapters/redis/adapters.py
@override
async def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """List active channels matching pattern asynchronously.

    Args:
        pattern (RedisPatternType): Pattern to match. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of channel names.
    """
    # AsyncRedis client has pubsub_channels method, type stubs may be incomplete
    pubsub_channels_method = getattr(self.client, "pubsub_channels", None)
    if pubsub_channels_method and callable(pubsub_channels_method):
        result = pubsub_channels_method(pattern, **kwargs)
        if isinstance(result, Awaitable):
            return await result
        return result
    raise AttributeError("pubsub_channels method not available on Redis client")

archipy.adapters.redis.adapters.AsyncRedisAdapter.zincrby async

zincrby(
    name: RedisKeyType,
    amount: float,
    value: bytes | str | float,
) -> RedisResponseType

Increment member score in sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
amount float

Amount to increment by.

required
value bytes | str | float

Member to increment.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

New score of the member.

Source code in archipy/adapters/redis/adapters.py
@override
async def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
    """Increment member score in sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        amount (float): Amount to increment by.
        value (bytes | str | float): Member to increment.

    Returns:
        RedisResponseType: New score of the member.
    """
    return await self.client.zincrby(name, amount, value)

archipy.adapters.redis.adapters.AsyncRedisAdapter.pubsub async

pubsub(**kwargs: Any) -> AsyncPubSub

Get PubSub object for channel subscription asynchronously.

Parameters:

Name Type Description Default
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
AsyncPubSub PubSub

PubSub object.

Source code in archipy/adapters/redis/adapters.py
@override
async def pubsub(self, **kwargs: Any) -> AsyncPubSub:
    """Get PubSub object for channel subscription asynchronously.

    Args:
        **kwargs (Any): Additional arguments.

    Returns:
        AsyncPubSub: PubSub object.
    """
    # Redis client has pubsub method, type stubs may be incomplete
    pubsub_method = getattr(self.client, "pubsub", None)
    if pubsub_method and callable(pubsub_method):
        return pubsub_method(**kwargs)
    raise AttributeError("pubsub method not available on Redis client")

archipy.adapters.redis.adapters.AsyncRedisAdapter.get_pipeline async

get_pipeline(
    transaction: Any = True, shard_hint: Any = None
) -> AsyncPipeline

Get pipeline for multiple commands asynchronously.

Parameters:

Name Type Description Default
transaction Any

Use transactions. Defaults to True.

True
shard_hint Any

Sharding hint. Defaults to None.

None

Returns:

Name Type Description
AsyncPipeline Pipeline

Pipeline object.

Source code in archipy/adapters/redis/adapters.py
@override
async def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> AsyncPipeline:
    """Get pipeline for multiple commands asynchronously.

    Args:
        transaction (Any): Use transactions. Defaults to True.
        shard_hint (Any): Sharding hint. Defaults to None.

    Returns:
        AsyncPipeline: Pipeline object.
    """
    result = self.client.pipeline(transaction, shard_hint)
    # Type narrowing: result is an AsyncPipeline
    if not isinstance(result, AsyncPipeline):
        raise TypeError(f"Expected AsyncPipeline, got {type(result)}")
    return result

archipy.adapters.redis.adapters.AsyncRedisAdapter.ping async

ping() -> RedisResponseType

Ping the Redis server asynchronously.

Returns:

Name Type Description
RedisResponseType RedisResponseType

'PONG' if successful.

Source code in archipy/adapters/redis/adapters.py
@override
async def ping(self) -> RedisResponseType:
    """Ping the Redis server asynchronously.

    Returns:
        RedisResponseType: 'PONG' if successful.
    """
    result = self.client.ping()
    if isinstance(result, Awaitable):
        return await result
    return result

options: show_root_toc_entry: false heading_level: 3

Mocks

In-memory mock implementation of the Redis port for use in unit tests and BDD scenarios.

archipy.adapters.redis.mocks.FakeRedisClusterWrapper

Bases: FakeRedis

Wrapper around FakeRedis that adds cluster-specific methods.

Source code in archipy/adapters/redis/mocks.py
class FakeRedisClusterWrapper(fakeredis.FakeRedis):
    """Wrapper around FakeRedis that adds cluster-specific methods."""

    def cluster_info(self) -> dict[str, Any]:
        """Return fake cluster info."""
        return {
            "cluster_state": "ok",
            "cluster_slots_assigned": 16384,
            "cluster_slots_ok": 16384,
            "cluster_slots_pfail": 0,
            "cluster_slots_fail": 0,
            "cluster_known_nodes": 6,
            "cluster_size": 3,
        }

    def cluster_nodes(self) -> str:
        """Return fake cluster nodes info."""
        return "fake cluster nodes info"

    def cluster_slots(self) -> list[tuple[int, int, list[str]]]:
        """Return fake cluster slots info."""
        slot1: tuple[int, int, list[str]] = (0, 5460, ["127.0.0.1", "7000"])
        slot2: tuple[int, int, list[str]] = (5461, 10922, ["127.0.0.1", "7001"])
        slot3: tuple[int, int, list[str]] = (10923, 16383, ["127.0.0.1", "7002"])
        return [slot1, slot2, slot3]

    def cluster_keyslot(self, key: str) -> int:
        """Return fake cluster keyslot for a key."""
        return hash(key) % 16384

    def cluster_countkeysinslot(self, slot: int) -> int:
        """Return fake count of keys in a slot."""
        return 0

    def cluster_get_keys_in_slot(self, slot: int, count: int) -> list[str]:
        """Return fake keys in a slot."""
        return []

archipy.adapters.redis.mocks.FakeRedisClusterWrapper.cluster_info

cluster_info() -> dict[str, Any]

Return fake cluster info.

Source code in archipy/adapters/redis/mocks.py
def cluster_info(self) -> dict[str, Any]:
    """Return fake cluster info."""
    return {
        "cluster_state": "ok",
        "cluster_slots_assigned": 16384,
        "cluster_slots_ok": 16384,
        "cluster_slots_pfail": 0,
        "cluster_slots_fail": 0,
        "cluster_known_nodes": 6,
        "cluster_size": 3,
    }

archipy.adapters.redis.mocks.FakeRedisClusterWrapper.cluster_nodes

cluster_nodes() -> str

Return fake cluster nodes info.

Source code in archipy/adapters/redis/mocks.py
def cluster_nodes(self) -> str:
    """Return fake cluster nodes info."""
    return "fake cluster nodes info"

archipy.adapters.redis.mocks.FakeRedisClusterWrapper.cluster_slots

cluster_slots() -> list[tuple[int, int, list[str]]]

Return fake cluster slots info.

Source code in archipy/adapters/redis/mocks.py
def cluster_slots(self) -> list[tuple[int, int, list[str]]]:
    """Return fake cluster slots info."""
    slot1: tuple[int, int, list[str]] = (0, 5460, ["127.0.0.1", "7000"])
    slot2: tuple[int, int, list[str]] = (5461, 10922, ["127.0.0.1", "7001"])
    slot3: tuple[int, int, list[str]] = (10923, 16383, ["127.0.0.1", "7002"])
    return [slot1, slot2, slot3]

archipy.adapters.redis.mocks.FakeRedisClusterWrapper.cluster_keyslot

cluster_keyslot(key: str) -> int

Return fake cluster keyslot for a key.

Source code in archipy/adapters/redis/mocks.py
def cluster_keyslot(self, key: str) -> int:
    """Return fake cluster keyslot for a key."""
    return hash(key) % 16384

archipy.adapters.redis.mocks.FakeRedisClusterWrapper.cluster_countkeysinslot

cluster_countkeysinslot(slot: int) -> int

Return fake count of keys in a slot.

Source code in archipy/adapters/redis/mocks.py
def cluster_countkeysinslot(self, slot: int) -> int:
    """Return fake count of keys in a slot."""
    return 0

archipy.adapters.redis.mocks.FakeRedisClusterWrapper.cluster_get_keys_in_slot

cluster_get_keys_in_slot(
    slot: int, count: int
) -> list[str]

Return fake keys in a slot.

Source code in archipy/adapters/redis/mocks.py
def cluster_get_keys_in_slot(self, slot: int, count: int) -> list[str]:
    """Return fake keys in a slot."""
    return []

archipy.adapters.redis.mocks.RedisMock

Bases: RedisAdapter

A Redis adapter implementation using fakeredis for testing.

Source code in archipy/adapters/redis/mocks.py
class RedisMock(RedisAdapter):
    """A Redis adapter implementation using fakeredis for testing."""

    def __init__(self, redis_config: RedisConfig | None = None) -> None:
        # Skip the parent's __init__ which would create real Redis connections
        from archipy.configs.base_config import BaseConfig

        self.config = redis_config or BaseConfig.global_config().REDIS

        # Create fake redis clients based on mode
        self._setup_fake_clients()

    def _setup_fake_clients(self) -> None:
        """Setup fake Redis clients that simulate different modes."""
        if self.config.MODE == RedisMode.CLUSTER:
            fake_client: Redis = FakeRedisClusterWrapper(decode_responses=True)
        else:
            fake_client = fakeredis.FakeRedis(decode_responses=True)

        self.client = fake_client
        self.read_only_client = fake_client

    def _set_clients(self, configs: RedisConfig) -> None:
        # Override to prevent actual connection setup
        pass

    @staticmethod
    def _get_client(host: str, configs: RedisConfig) -> Redis:
        # Override to return fakeredis instead
        return fakeredis.FakeRedis(decode_responses=configs.DECODE_RESPONSES)

archipy.adapters.redis.mocks.RedisMock.config instance-attribute

config = redis_config or REDIS

archipy.adapters.redis.mocks.RedisMock.ping

ping() -> RedisResponseType

Ping the Redis server.

Returns:

Name Type Description
RedisResponseType RedisResponseType

'PONG' if successful.

Source code in archipy/adapters/redis/adapters.py
@override
def ping(self) -> RedisResponseType:
    """Ping the Redis server.

    Returns:
        RedisResponseType: 'PONG' if successful.
    """
    return self.client.ping()

archipy.adapters.redis.mocks.RedisMock.pttl

pttl(name: bytes | str) -> RedisResponseType

Get the time to live in milliseconds for a key.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in milliseconds.

Source code in archipy/adapters/redis/adapters.py
@override
def pttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in milliseconds for a key.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in milliseconds.
    """
    return self.read_only_client.pttl(name)

archipy.adapters.redis.mocks.RedisMock.incrby

incrby(
    name: RedisKeyType, amount: int = 1
) -> RedisResponseType

Increment the integer value of a key by the given amount.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
amount int

Amount to increment by. Defaults to 1.

1

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new value after increment.

Source code in archipy/adapters/redis/adapters.py
@override
def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
    """Increment the integer value of a key by the given amount.

    Args:
        name (RedisKeyType): The key name.
        amount (int): Amount to increment by. Defaults to 1.

    Returns:
        RedisResponseType: The new value after increment.
    """
    return self.client.incrby(name, amount)

archipy.adapters.redis.mocks.RedisMock.set

set(
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType

Set the value of a key with optional expiration and conditions.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
value RedisSetType

The value to set.

required
ex RedisExpiryType | None

Expire time in seconds.

None
px RedisExpiryType | None

Expire time in milliseconds.

None
nx bool

Only set if key doesn't exist.

False
xx bool

Only set if key exists.

False
keepttl bool

Retain the TTL from the previous value.

False
get bool

Return the old value.

False
exat RedisAbsExpiryType | None

Absolute expiration time in seconds.

None
pxat RedisAbsExpiryType | None

Absolute expiration time in milliseconds.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Result of the operation.

Source code in archipy/adapters/redis/adapters.py
@override
def set(
    self,
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType:
    """Set the value of a key with optional expiration and conditions.

    Args:
        name (RedisKeyType): The key name.
        value (RedisSetType): The value to set.
        ex (RedisExpiryType | None): Expire time in seconds.
        px (RedisExpiryType | None): Expire time in milliseconds.
        nx (bool): Only set if key doesn't exist.
        xx (bool): Only set if key exists.
        keepttl (bool): Retain the TTL from the previous value.
        get (bool): Return the old value.
        exat (RedisAbsExpiryType | None): Absolute expiration time in seconds.
        pxat (RedisAbsExpiryType | None): Absolute expiration time in milliseconds.

    Returns:
        RedisResponseType: Result of the operation.
    """
    return self.client.set(name, value, ex, px, nx, xx, keepttl, get, exat, pxat)

archipy.adapters.redis.mocks.RedisMock.get

get(key: str) -> RedisResponseType

Get the value of a key.

Parameters:

Name Type Description Default
key str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None if not exists.

Source code in archipy/adapters/redis/adapters.py
@override
def get(self, key: str) -> RedisResponseType:
    """Get the value of a key.

    Args:
        key (str): The key name.

    Returns:
        RedisResponseType: The value of the key or None if not exists.
    """
    return self.read_only_client.get(key)

archipy.adapters.redis.mocks.RedisMock.mget

mget(
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType

Get the values of multiple keys.

Parameters:

Name Type Description Default
keys RedisKeyType | Iterable[RedisKeyType]

Single key or iterable of keys.

required
*args bytes | str

Additional keys.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
def mget(
    self,
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType:
    """Get the values of multiple keys.

    Args:
        keys (RedisKeyType | Iterable[RedisKeyType]): Single key or iterable of keys.
        *args (bytes | str): Additional keys.

    Returns:
        RedisResponseType: List of values.
    """
    return self.read_only_client.mget(keys, *args)

archipy.adapters.redis.mocks.RedisMock.mset

mset(
    mapping: Mapping[RedisKeyType, bytes | str | float],
) -> RedisResponseType

Set multiple keys to their respective values.

Parameters:

Name Type Description Default
mapping Mapping[RedisKeyType, bytes | str | float]

Dictionary of key-value pairs.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Always returns 'OK'.

Source code in archipy/adapters/redis/adapters.py
@override
def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
    """Set multiple keys to their respective values.

    Args:
        mapping (Mapping[RedisKeyType, bytes | str | float]): Dictionary of key-value pairs.

    Returns:
        RedisResponseType: Always returns 'OK'.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    return self.client.mset(dict_mapping)

archipy.adapters.redis.mocks.RedisMock.keys

keys(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Find all keys matching the given pattern.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match keys against. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Find all keys matching the given pattern.

    Args:
        pattern (RedisPatternType): Pattern to match keys against. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of matching keys.
    """
    return self.read_only_client.keys(pattern, **kwargs)

archipy.adapters.redis.mocks.RedisMock.getset

getset(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Set the value of a key and return its old value.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The new value.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The previous value or None.

Source code in archipy/adapters/redis/adapters.py
@override
def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Set the value of a key and return its old value.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The new value.

    Returns:
        RedisResponseType: The previous value or None.
    """
    return self.client.getset(key, value)

archipy.adapters.redis.mocks.RedisMock.getdel

getdel(key: bytes | str) -> RedisResponseType

Get the value of a key and delete it.

Parameters:

Name Type Description Default
key bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None.

Source code in archipy/adapters/redis/adapters.py
@override
def getdel(self, key: bytes | str) -> RedisResponseType:
    """Get the value of a key and delete it.

    Args:
        key (bytes | str): The key name.

    Returns:
        RedisResponseType: The value of the key or None.
    """
    return self.client.getdel(key)

archipy.adapters.redis.mocks.RedisMock.exists

exists(*names: bytes | str) -> RedisResponseType

Check if one or more keys exist.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys that exist.

Source code in archipy/adapters/redis/adapters.py
@override
def exists(self, *names: bytes | str) -> RedisResponseType:
    """Check if one or more keys exist.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys that exist.
    """
    return self.read_only_client.exists(*names)

archipy.adapters.redis.mocks.RedisMock.delete

delete(*names: bytes | str) -> RedisResponseType

Delete one or more keys.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys deleted.

Source code in archipy/adapters/redis/adapters.py
@override
def delete(self, *names: bytes | str) -> RedisResponseType:
    """Delete one or more keys.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys deleted.
    """
    return self.client.delete(*names)

archipy.adapters.redis.mocks.RedisMock.append

append(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Append a value to a key.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The value to append.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Length of the string after append.

Source code in archipy/adapters/redis/adapters.py
@override
def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Append a value to a key.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The value to append.

    Returns:
        RedisResponseType: Length of the string after append.
    """
    return self.client.append(key, value)

archipy.adapters.redis.mocks.RedisMock.ttl

ttl(name: bytes | str) -> RedisResponseType

Get the time to live in seconds for a key.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in seconds.

Source code in archipy/adapters/redis/adapters.py
@override
def ttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in seconds for a key.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in seconds.
    """
    return self.read_only_client.ttl(name)

archipy.adapters.redis.mocks.RedisMock.type

type(name: bytes | str) -> RedisResponseType

Determine the type stored at key.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Type of the key's value.

Source code in archipy/adapters/redis/adapters.py
@override
def type(self, name: bytes | str) -> RedisResponseType:
    """Determine the type stored at key.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Type of the key's value.
    """
    return self.read_only_client.type(name)

archipy.adapters.redis.mocks.RedisMock.llen

llen(name: str) -> RedisIntegerResponseType

Get the length of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list.

Source code in archipy/adapters/redis/adapters.py
@override
def llen(self, name: str) -> RedisIntegerResponseType:
    """Get the length of a list.

    Args:
        name (str): The key name of the list.

    Returns:
        RedisIntegerResponseType: Length of the list.
    """
    client: Redis | RedisCluster = self.read_only_client
    result = client.llen(name)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.lpop

lpop(name: str, count: int | None = None) -> Any

Remove and return elements from the left of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
def lpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from the left of a list.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    return self.client.lpop(name, count)

archipy.adapters.redis.mocks.RedisMock.lpush

lpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to the left of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to the left of a list.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.lpush(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.lrange

lrange(
    name: str, start: int, end: int
) -> RedisListResponseType

Get a range of elements from a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
start int

Start index.

required
end int

End index.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of elements in the specified range.

Source code in archipy/adapters/redis/adapters.py
@override
def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
    """Get a range of elements from a list.

    Args:
        name (str): The key name of the list.
        start (int): Start index.
        end (int): End index.

    Returns:
        RedisListResponseType: List of elements in the specified range.
    """
    result = self.read_only_client.lrange(name, start, end)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result)

archipy.adapters.redis.mocks.RedisMock.lrem

lrem(
    name: str, count: int, value: str
) -> RedisIntegerResponseType

Remove elements from a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int

Number of occurrences to remove.

required
value str

Value to remove.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements removed.

Source code in archipy/adapters/redis/adapters.py
@override
def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
    """Remove elements from a list.

    Args:
        name (str): The key name of the list.
        count (int): Number of occurrences to remove.
        value (str): Value to remove.

    Returns:
        RedisIntegerResponseType: Number of elements removed.
    """
    result = self.client.lrem(name, count, value)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.lset

lset(name: str, index: int, value: str) -> bool

Set the value of an element in a list by its index.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
index int

Index of the element.

required
value str

New value.

required

Returns:

Name Type Description
bool bool

True if successful.

Source code in archipy/adapters/redis/adapters.py
@override
def lset(self, name: str, index: int, value: str) -> bool:
    """Set the value of an element in a list by its index.

    Args:
        name (str): The key name of the list.
        index (int): Index of the element.
        value (str): New value.

    Returns:
        bool: True if successful.
    """
    return bool(self.client.lset(name, index, value))

archipy.adapters.redis.mocks.RedisMock.rpop

rpop(name: str, count: int | None = None) -> Any

Remove and return elements from the right of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
def rpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from the right of a list.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    return self.client.rpop(name, count)

archipy.adapters.redis.mocks.RedisMock.rpush

rpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to the right of a list.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to the right of a list.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.rpush(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.scan

scan(
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType

Scan keys in the database incrementally.

Parameters:

Name Type Description Default
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys to return. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of keys.

Source code in archipy/adapters/redis/adapters.py
@override
def scan(
    self,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType:
    """Scan keys in the database incrementally.

    Args:
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys to return. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Tuple of cursor and list of keys.
    """
    return self.read_only_client.scan(cursor, match, count, _type, **kwargs)

archipy.adapters.redis.mocks.RedisMock.scan_iter

scan_iter(
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator

Iterate over keys in the database.

Parameters:

Name Type Description Default
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys to return. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
Iterator Iterator

Iterator over matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
def scan_iter(
    self,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator:
    """Iterate over keys in the database.

    Args:
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys to return. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        Iterator: Iterator over matching keys.
    """
    return self.read_only_client.scan_iter(match, count, _type, **kwargs)

archipy.adapters.redis.mocks.RedisMock.sscan

sscan(
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType

Scan members of a set incrementally.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of members.

Source code in archipy/adapters/redis/adapters.py
@override
def sscan(
    self,
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType:
    """Scan members of a set incrementally.

    Args:
        name (RedisKeyType): The set key name.
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        RedisResponseType: Tuple of cursor and list of members.
    """
    return self.read_only_client.sscan(name, cursor, match, count)

archipy.adapters.redis.mocks.RedisMock.sscan_iter

sscan_iter(
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator

Iterate over members of a set.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Name Type Description
Iterator Iterator

Iterator over set members.

Source code in archipy/adapters/redis/adapters.py
@override
def sscan_iter(
    self,
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator:
    """Iterate over members of a set.

    Args:
        name (RedisKeyType): The set key name.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        Iterator: Iterator over set members.
    """
    return self.read_only_client.sscan_iter(name, match, count)

archipy.adapters.redis.mocks.RedisMock.sadd

sadd(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Add members to a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to add.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements added.

Source code in archipy/adapters/redis/adapters.py
@override
def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Add members to a set.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to add.

    Returns:
        RedisIntegerResponseType: Number of elements added.
    """
    result = self.client.sadd(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.scard

scard(name: str) -> RedisIntegerResponseType

Get the number of members in a set.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
def scard(self, name: str) -> RedisIntegerResponseType:
    """Get the number of members in a set.

    Args:
        name (str): The set key name.

    Returns:
        RedisIntegerResponseType: Number of members.
    """
    result = self.client.scard(name)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.sismember

sismember(name: str, value: str) -> bool

Check if a value is a member of a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
value str

Value to check.

required

Returns:

Name Type Description
bool bool

True if value is a member, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
def sismember(self, name: str, value: str) -> bool:
    """Check if a value is a member of a set.

    Args:
        name (str): The set key name.
        value (str): Value to check.

    Returns:
        bool: True if value is a member, False otherwise.
    """
    result = self.read_only_client.sismember(name, value)
    return bool(result)

archipy.adapters.redis.mocks.RedisMock.smembers

smembers(name: str) -> RedisSetResponseType

Get all members of a set.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set of all members.

Source code in archipy/adapters/redis/adapters.py
@override
def smembers(self, name: str) -> RedisSetResponseType:
    """Get all members of a set.

    Args:
        name (str): The set key name.

    Returns:
        RedisSetResponseType: Set of all members.
    """
    result = self.read_only_client.smembers(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return set(result) if result else set()

archipy.adapters.redis.mocks.RedisMock.spop

spop(
    name: str, count: int | None = None
) -> bytes | float | int | str | list | None

Remove and return random members from a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Type Description
bytes | float | int | str | list | None

bytes | float | int | str | list | None: Popped member(s) or None.

Source code in archipy/adapters/redis/adapters.py
@override
def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
    """Remove and return random members from a set.

    Args:
        name (str): The set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        bytes | float | int | str | list | None: Popped member(s) or None.
    """
    result = self.client.spop(name, count)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return result

archipy.adapters.redis.mocks.RedisMock.srem

srem(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Remove members from a set.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Remove members from a set.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisIntegerResponseType: Number of members removed.
    """
    result = self.client.srem(name, *values)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.sunion

sunion(
    keys: RedisKeyType, *args: bytes | str
) -> RedisSetResponseType

Get the union of multiple sets.

Parameters:

Name Type Description Default
keys RedisKeyType

First set key.

required
*args bytes | str

Additional set keys.

()

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set containing union of all sets.

Source code in archipy/adapters/redis/adapters.py
@override
def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
    """Get the union of multiple sets.

    Args:
        keys (RedisKeyType): First set key.
        *args (bytes | str): Additional set keys.

    Returns:
        RedisSetResponseType: Set containing union of all sets.
    """
    # Redis sunion expects a list of keys as first argument
    keys_list: list[str | bytes] = [keys, *list(args)]
    result = self.client.sunion(keys_list)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return set(result) if result else set()

archipy.adapters.redis.mocks.RedisMock.zadd

zadd(
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType

Add members to a sorted set with scores.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
mapping Mapping[RedisKeyType, bytes | str | float]

Member-score pairs.

required
nx bool

Only add new elements. Defaults to False.

False
xx bool

Only update existing elements. Defaults to False.

False
ch bool

Return number of changed elements. Defaults to False.

False
incr bool

Increment existing scores. Defaults to False.

False
gt bool

Only update if score is greater. Defaults to False.

False
lt bool

Only update if score is less. Defaults to False.

False

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of elements added or modified.

Source code in archipy/adapters/redis/adapters.py
@override
def zadd(
    self,
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType:
    """Add members to a sorted set with scores.

    Args:
        name (RedisKeyType): The sorted set key name.
        mapping (Mapping[RedisKeyType, bytes | str | float]): Member-score pairs.
        nx (bool): Only add new elements. Defaults to False.
        xx (bool): Only update existing elements. Defaults to False.
        ch (bool): Return number of changed elements. Defaults to False.
        incr (bool): Increment existing scores. Defaults to False.
        gt (bool): Only update if score is greater. Defaults to False.
        lt (bool): Only update if score is less. Defaults to False.

    Returns:
        RedisResponseType: Number of elements added or modified.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    str_name = str(name)
    return self.client.zadd(str_name, dict_mapping, nx, xx, ch, incr, gt, lt)

archipy.adapters.redis.mocks.RedisMock.zcard

zcard(name: bytes | str) -> RedisResponseType

Get the number of members in a sorted set.

Parameters:

Name Type Description Default
name bytes | str

The sorted set key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
def zcard(self, name: bytes | str) -> RedisResponseType:
    """Get the number of members in a sorted set.

    Args:
        name (bytes | str): The sorted set key name.

    Returns:
        RedisResponseType: Number of members.
    """
    return self.client.zcard(name)

archipy.adapters.redis.mocks.RedisMock.zcount

zcount(
    name: RedisKeyType, min: float | str, max: float | str
) -> RedisResponseType

Count members in a sorted set with scores in range.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members in range.

Source code in archipy/adapters/redis/adapters.py
@override
def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
    """Count members in a sorted set with scores in range.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.

    Returns:
        RedisResponseType: Number of members in range.
    """
    return self.client.zcount(name, min, max)

archipy.adapters.redis.mocks.RedisMock.zpopmax

zpopmax(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Remove and return members with highest scores from sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Remove and return members with highest scores from sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return self.client.zpopmax(name, count)

archipy.adapters.redis.mocks.RedisMock.zpopmin

zpopmin(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Remove and return members with lowest scores from sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Remove and return members with lowest scores from sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return self.client.zpopmin(name, count)

archipy.adapters.redis.mocks.RedisMock.zrange

zrange(
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType

Get a range of members from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index or score.

required
end int

End index or score.

required
desc bool

Sort in descending order. Defaults to False.

False
withscores bool

Include scores in result. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float
byscore bool

Range by score. Defaults to False.

False
bylex bool

Range by lexicographical order. Defaults to False.

False
offset int | None

Offset for byscore/bylex. Defaults to None.

None
num int | None

Count for byscore/bylex. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType:
    """Get a range of members from a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index or score.
        end (int): End index or score.
        desc (bool): Sort in descending order. Defaults to False.
        withscores (bool): Include scores in result. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.
        byscore (bool): Range by score. Defaults to False.
        bylex (bool): Range by lexicographical order. Defaults to False.
        offset (int | None): Offset for byscore/bylex. Defaults to None.
        num (int | None): Count for byscore/bylex. Defaults to None.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return self.client.zrange(
        name,
        start,
        end,
        desc,
        withscores,
        score_cast_func,
        byscore,
        bylex,
        offset,
        num,
    )

archipy.adapters.redis.mocks.RedisMock.zrevrange

zrevrange(
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get a range of members from a sorted set in reverse order.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index.

required
end int

End index.

required
withscores bool

Include scores in result. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zrevrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get a range of members from a sorted set in reverse order.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index.
        end (int): End index.
        withscores (bool): Include scores in result. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return self.client.zrevrange(name, start, end, withscores, score_cast_func)

archipy.adapters.redis.mocks.RedisMock.zrangebyscore

zrangebyscore(
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get members from a sorted set by score range.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required
start int | None

Offset. Defaults to None.

None
num int | None

Count. Defaults to None.

None
withscores bool

Include scores in result. Defaults to False.

False
score_cast_func RedisScoreCastType

Function to cast scores. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def zrangebyscore(
    self,
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get members from a sorted set by score range.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.
        start (int | None): Offset. Defaults to None.
        num (int | None): Count. Defaults to None.
        withscores (bool): Include scores in result. Defaults to False.
        score_cast_func (RedisScoreCastType): Function to cast scores. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return self.client.zrangebyscore(name, min, max, start, num, withscores, score_cast_func)

archipy.adapters.redis.mocks.RedisMock.zrank

zrank(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get the rank of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to find rank for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Rank of the member or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get the rank of a member in a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to find rank for.

    Returns:
        RedisResponseType: Rank of the member or None if not found.
    """
    return self.client.zrank(name, value)

archipy.adapters.redis.mocks.RedisMock.zrem

zrem(
    name: RedisKeyType, *values: bytes | str | float
) -> RedisResponseType

Remove members from a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
    """Remove members from a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisResponseType: Number of members removed.
    """
    return self.client.zrem(name, *values)

archipy.adapters.redis.mocks.RedisMock.zscore

zscore(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get the score of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to get score for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Score of the member or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get the score of a member in a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to get score for.

    Returns:
        RedisResponseType: Score of the member or None if not found.
    """
    return self.client.zscore(name, value)

archipy.adapters.redis.mocks.RedisMock.hdel

hdel(
    name: str, *keys: str | bytes
) -> RedisIntegerResponseType

Delete fields from a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
*keys str | bytes

Fields to delete.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields deleted.

Source code in archipy/adapters/redis/adapters.py
@override
def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
    """Delete fields from a hash.

    Args:
        name (str): The hash key name.
        *keys (str | bytes): Fields to delete.

    Returns:
        RedisIntegerResponseType: Number of fields deleted.
    """
    # Convert keys to str for type compatibility with Redis client
    str_keys: tuple[str, ...] = tuple(str(k) if isinstance(k, bytes) else k for k in keys)
    result = self.client.hdel(name, *str_keys)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.hexists

hexists(name: str, key: str) -> bool

Check if a field exists in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to check.

required

Returns:

Name Type Description
bool bool

True if field exists, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
def hexists(self, name: str, key: str) -> bool:
    """Check if a field exists in a hash.

    Args:
        name (str): The hash key name.
        key (str): Field to check.

    Returns:
        bool: True if field exists, False otherwise.
    """
    result = self.read_only_client.hexists(name, key)
    return bool(result)

archipy.adapters.redis.mocks.RedisMock.hget

hget(name: str, key: str) -> str | None

Get the value of a field in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to get.

required

Returns:

Type Description
str | None

str | None: Value of the field or None.

Source code in archipy/adapters/redis/adapters.py
@override
def hget(self, name: str, key: str) -> str | None:
    """Get the value of a field in a hash.

    Args:
        name (str): The hash key name.
        key (str): Field to get.

    Returns:
        str | None: Value of the field or None.
    """
    result = self.read_only_client.hget(name, key)
    return str(result) if result is not None else None

archipy.adapters.redis.mocks.RedisMock.hgetall

hgetall(name: str) -> dict[str, Any]

Get all fields and values in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Dictionary of field-value pairs.

Source code in archipy/adapters/redis/adapters.py
@override
def hgetall(self, name: str) -> dict[str, Any]:
    """Get all fields and values in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        dict[str, Any]: Dictionary of field-value pairs.
    """
    result = self.read_only_client.hgetall(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    if result:
        return {str(k): v for k, v in result.items()}
    return {}

archipy.adapters.redis.mocks.RedisMock.hkeys

hkeys(name: str) -> RedisListResponseType

Get all fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field names.

Source code in archipy/adapters/redis/adapters.py
@override
def hkeys(self, name: str) -> RedisListResponseType:
    """Get all fields in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of field names.
    """
    result = self.read_only_client.hkeys(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result) if result else []

archipy.adapters.redis.mocks.RedisMock.hlen

hlen(name: str) -> RedisIntegerResponseType

Get the number of fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields.

Source code in archipy/adapters/redis/adapters.py
@override
def hlen(self, name: str) -> RedisIntegerResponseType:
    """Get the number of fields in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        RedisIntegerResponseType: Number of fields.
    """
    result = self.read_only_client.hlen(name)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.hset

hset(
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType

Set fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str | bytes | None

Single field name. Defaults to None.

None
value str | bytes | None

Single field value. Defaults to None.

None
mapping dict | None

Dictionary of field-value pairs. Defaults to None.

None
items list | None

List of field-value pairs. Defaults to None.

None

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields set.

Source code in archipy/adapters/redis/adapters.py
@override
def hset(
    self,
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType:
    """Set fields in a hash.

    Args:
        name (str): The hash key name.
        key (str | bytes | None): Single field name. Defaults to None.
        value (str | bytes | None): Single field value. Defaults to None.
        mapping (dict | None): Dictionary of field-value pairs. Defaults to None.
        items (list | None): List of field-value pairs. Defaults to None.

    Returns:
        RedisIntegerResponseType: Number of fields set.
    """
    # Convert bytes to str for type compatibility with Redis client
    str_key: str | None = str(key) if key is not None and isinstance(key, bytes) else key
    str_value: str | None = str(value) if value is not None and isinstance(value, bytes) else value
    result = self.client.hset(name, str_key, str_value, mapping, items)
    return self._ensure_sync_int(result)

archipy.adapters.redis.mocks.RedisMock.hmget

hmget(
    name: str, keys: list, *args: str | bytes
) -> RedisListResponseType

Get values of multiple fields in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required
keys list

List of field names.

required
*args str | bytes

Additional field names.

()

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field values.

Source code in archipy/adapters/redis/adapters.py
@override
def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
    """Get values of multiple fields in a hash.

    Args:
        name (str): The hash key name.
        keys (list): List of field names.
        *args (str | bytes): Additional field names.

    Returns:
        RedisListResponseType: List of field values.
    """
    # Convert keys list and args for type compatibility, combine into single list
    keys_list: list[str] = [str(k) for k in keys] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
    result = self.read_only_client.hmget(name, keys_list)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result) if result else []

archipy.adapters.redis.mocks.RedisMock.hvals

hvals(name: str) -> RedisListResponseType

Get all values in a hash.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
def hvals(self, name: str) -> RedisListResponseType:
    """Get all values in a hash.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of values.
    """
    result = self.read_only_client.hvals(name)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    return list(result) if result else []

archipy.adapters.redis.mocks.RedisMock.publish

publish(
    channel: RedisKeyType,
    message: bytes | str,
    **kwargs: Any,
) -> RedisResponseType

Publish a message to a channel.

Parameters:

Name Type Description Default
channel RedisKeyType

Channel name.

required
message bytes | str

Message to publish.

required
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of subscribers that received the message.

Source code in archipy/adapters/redis/adapters.py
@override
def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
    """Publish a message to a channel.

    Args:
        channel (RedisKeyType): Channel name.
        message (bytes | str): Message to publish.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Number of subscribers that received the message.
    """
    return self.client.publish(channel, message, **kwargs)

archipy.adapters.redis.mocks.RedisMock.pubsub_channels

pubsub_channels(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

List active channels matching a pattern.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match channels. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of channel names.

Source code in archipy/adapters/redis/adapters.py
@override
def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """List active channels matching a pattern.

    Args:
        pattern (RedisPatternType): Pattern to match channels. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of channel names.
    """
    return self.client.pubsub_channels(pattern, **kwargs)

archipy.adapters.redis.mocks.RedisMock.zincrby

zincrby(
    name: RedisKeyType,
    amount: float,
    value: bytes | str | float,
) -> RedisResponseType

Increment the score of a member in a sorted set.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
amount float

Amount to increment by.

required
value bytes | str | float

Member to increment.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

New score of the member.

Source code in archipy/adapters/redis/adapters.py
@override
def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
    """Increment the score of a member in a sorted set.

    Args:
        name (RedisKeyType): The sorted set key name.
        amount (float): Amount to increment by.
        value (bytes | str | float): Member to increment.

    Returns:
        RedisResponseType: New score of the member.
    """
    return self.client.zincrby(name, amount, value)

archipy.adapters.redis.mocks.RedisMock.pubsub

pubsub(**kwargs: Any) -> PubSub

Get a PubSub object for subscribing to channels.

Parameters:

Name Type Description Default
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
PubSub PubSub

PubSub object.

Source code in archipy/adapters/redis/adapters.py
@override
def pubsub(self, **kwargs: Any) -> PubSub:
    """Get a PubSub object for subscribing to channels.

    Args:
        **kwargs (Any): Additional arguments.

    Returns:
        PubSub: PubSub object.
    """
    return self.client.pubsub(**kwargs)

archipy.adapters.redis.mocks.RedisMock.get_pipeline

get_pipeline(
    transaction: Any = True, shard_hint: Any = None
) -> Pipeline

Get a pipeline object for executing multiple commands.

Parameters:

Name Type Description Default
transaction Any

Whether to use transactions. Defaults to True.

True
shard_hint Any

Hint for sharding. Defaults to None.

None

Returns:

Name Type Description
Pipeline Pipeline

Pipeline object.

Source code in archipy/adapters/redis/adapters.py
@override
def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> Pipeline:
    """Get a pipeline object for executing multiple commands.

    Args:
        transaction (Any): Whether to use transactions. Defaults to True.
        shard_hint (Any): Hint for sharding. Defaults to None.

    Returns:
        Pipeline: Pipeline object.
    """
    return self.client.pipeline(transaction, shard_hint)

archipy.adapters.redis.mocks.RedisMock.cluster_info

cluster_info() -> RedisResponseType

Get cluster information.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_info(self) -> RedisResponseType:
    """Get cluster information."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_info()
    return None

archipy.adapters.redis.mocks.RedisMock.cluster_nodes

cluster_nodes() -> RedisResponseType

Get cluster nodes information.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_nodes(self) -> RedisResponseType:
    """Get cluster nodes information."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_nodes()
    return None

archipy.adapters.redis.mocks.RedisMock.cluster_slots

cluster_slots() -> RedisResponseType

Get cluster slots mapping.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_slots(self) -> RedisResponseType:
    """Get cluster slots mapping."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_slots()
    return None

archipy.adapters.redis.mocks.RedisMock.cluster_key_slot

cluster_key_slot(key: str) -> RedisResponseType

Get the hash slot for a key.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_key_slot(self, key: str) -> RedisResponseType:
    """Get the hash slot for a key."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_keyslot(key)
    return None

archipy.adapters.redis.mocks.RedisMock.cluster_count_keys_in_slot

cluster_count_keys_in_slot(slot: int) -> RedisResponseType

Count keys in a specific slot.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
    """Count keys in a specific slot."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_countkeysinslot(slot)
    return None

archipy.adapters.redis.mocks.RedisMock.cluster_get_keys_in_slot

cluster_get_keys_in_slot(
    slot: int, count: int
) -> RedisResponseType

Get keys in a specific slot.

Source code in archipy/adapters/redis/adapters.py
@override
def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
    """Get keys in a specific slot."""
    if isinstance(self.client, RedisCluster):
        return self.client.cluster_get_keys_in_slot(slot, count)
    return None

archipy.adapters.redis.mocks.AsyncRedisMock

Bases: AsyncRedisAdapter

An async Redis adapter implementation using fakeredis for testing.

Source code in archipy/adapters/redis/mocks.py
class AsyncRedisMock(AsyncRedisAdapter):
    """An async Redis adapter implementation using fakeredis for testing."""

    def __init__(self, redis_config: RedisConfig | None = None) -> None:
        # Skip the parent's __init__ which would create real Redis connections
        from archipy.configs.base_config import BaseConfig

        self.config = redis_config or BaseConfig.global_config().REDIS

        # Create fake async redis clients based on mode
        self._setup_async_fake_clients()

    def _setup_async_fake_clients(self) -> None:
        """Setup fake async Redis clients that simulate different modes."""
        self.client = AsyncMock()
        self.read_only_client = self.client

        # Create a synchronous fakeredis instance to handle the actual operations
        self._fake_redis = fakeredis.FakeRedis(decode_responses=True)

        # Set up basic async methods
        self._setup_async_methods()

        # Add mode-specific methods
        if self.config.MODE == RedisMode.CLUSTER:
            # Add cluster-specific async mock methods
            self.client.cluster_info.side_effect = lambda: {
                "cluster_state": "ok",
                "cluster_slots_assigned": 16384,
                "cluster_slots_ok": 16384,
                "cluster_slots_pfail": 0,
                "cluster_slots_fail": 0,
                "cluster_known_nodes": 6,
                "cluster_size": 3,
            }
            self.client.cluster_nodes.side_effect = lambda: "fake cluster nodes info"
            self.client.cluster_slots.side_effect = lambda: [
                (0, 5460, ["127.0.0.1", 7000]),
                (5461, 10922, ["127.0.0.1", 7001]),
                (10923, 16383, ["127.0.0.1", 7002]),
            ]
            self.client.cluster_keyslot.side_effect = lambda key: hash(key) % 16384
            self.client.cluster_countkeysinslot.side_effect = lambda slot: 0
            self.client.cluster_get_keys_in_slot.side_effect = lambda slot, count: []

    def _set_clients(self, configs: RedisConfig) -> None:
        # Override to prevent actual connection setup
        pass

    @staticmethod
    def _get_client(host: str, configs: RedisConfig) -> AsyncRedis:
        # Override to return a mocked async client
        return AsyncMock()

    def _setup_async_methods(self) -> None:
        """Set up all async methods to use a synchronous fakeredis under the hood."""
        # For each async method, implement it to use the synchronous fakeredis
        for method_name in dir(AsyncRedisPort):
            if not method_name.startswith("_") and method_name not in ("pubsub", "get_pipeline"):
                sync_method = getattr(self._fake_redis, method_name, None)
                if sync_method and callable(sync_method):
                    async_method = self._create_async_wrapper(method_name, sync_method)
                    setattr(self.client, method_name, async_method)
                    setattr(self.read_only_client, method_name, async_method)

    def _create_async_wrapper(
        self,
        method_name: str,
        sync_method: Callable[..., Any],
    ) -> Callable[..., Awaitable[RedisResponseType]]:
        """Create an async wrapper around a synchronous method."""

        async def wrapper(*args: Any, **kwargs: Any) -> RedisResponseType:
            # Remove 'self' from args when calling the sync method
            if args and args[0] is self:
                args = args[1:]
            return sync_method(*args, **kwargs)

        return wrapper

archipy.adapters.redis.mocks.AsyncRedisMock.config instance-attribute

config = redis_config or REDIS

archipy.adapters.redis.mocks.AsyncRedisMock.ping async

ping() -> RedisResponseType

Ping the Redis server asynchronously.

Returns:

Name Type Description
RedisResponseType RedisResponseType

'PONG' if successful.

Source code in archipy/adapters/redis/adapters.py
@override
async def ping(self) -> RedisResponseType:
    """Ping the Redis server asynchronously.

    Returns:
        RedisResponseType: 'PONG' if successful.
    """
    result = self.client.ping()
    if isinstance(result, Awaitable):
        return await result
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.pttl async

pttl(name: bytes | str) -> RedisResponseType

Get the time to live in milliseconds for a key asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in milliseconds.

Source code in archipy/adapters/redis/adapters.py
@override
async def pttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in milliseconds for a key asynchronously.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in milliseconds.
    """
    return await self.read_only_client.pttl(name)

archipy.adapters.redis.mocks.AsyncRedisMock.incrby async

incrby(
    name: RedisKeyType, amount: int = 1
) -> RedisResponseType

Increment the integer value of a key by the given amount asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
amount int

Amount to increment by. Defaults to 1.

1

Returns:

Name Type Description
RedisResponseType RedisResponseType

The new value after increment.

Source code in archipy/adapters/redis/adapters.py
@override
async def incrby(self, name: RedisKeyType, amount: int = 1) -> RedisResponseType:
    """Increment the integer value of a key by the given amount asynchronously.

    Args:
        name (RedisKeyType): The key name.
        amount (int): Amount to increment by. Defaults to 1.

    Returns:
        RedisResponseType: The new value after increment.
    """
    return await self.client.incrby(name, amount)

archipy.adapters.redis.mocks.AsyncRedisMock.set async

set(
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType

Set the value of a key with optional expiration asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The key name.

required
value RedisSetType

The value to set.

required
ex RedisExpiryType | None

Expire time in seconds.

None
px RedisExpiryType | None

Expire time in milliseconds.

None
nx bool

Only set if key doesn't exist.

False
xx bool

Only set if key exists.

False
keepttl bool

Retain the TTL from the previous value.

False
get bool

Return the old value.

False
exat RedisAbsExpiryType | None

Absolute expiration time in seconds.

None
pxat RedisAbsExpiryType | None

Absolute expiration time in milliseconds.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Result of the operation.

Source code in archipy/adapters/redis/adapters.py
@override
async def set(
    self,
    name: RedisKeyType,
    value: RedisSetType,
    ex: RedisExpiryType | None = None,
    px: RedisExpiryType | None = None,
    nx: bool = False,
    xx: bool = False,
    keepttl: bool = False,
    get: bool = False,
    exat: RedisAbsExpiryType | None = None,
    pxat: RedisAbsExpiryType | None = None,
) -> RedisResponseType:
    """Set the value of a key with optional expiration asynchronously.

    Args:
        name (RedisKeyType): The key name.
        value (RedisSetType): The value to set.
        ex (RedisExpiryType | None): Expire time in seconds.
        px (RedisExpiryType | None): Expire time in milliseconds.
        nx (bool): Only set if key doesn't exist.
        xx (bool): Only set if key exists.
        keepttl (bool): Retain the TTL from the previous value.
        get (bool): Return the old value.
        exat (RedisAbsExpiryType | None): Absolute expiration time in seconds.
        pxat (RedisAbsExpiryType | None): Absolute expiration time in milliseconds.

    Returns:
        RedisResponseType: Result of the operation.
    """
    return await self.client.set(name, value, ex, px, nx, xx, keepttl, get, exat, pxat)

archipy.adapters.redis.mocks.AsyncRedisMock.get async

get(key: str) -> RedisResponseType

Get the value of a key asynchronously.

Parameters:

Name Type Description Default
key str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None if not exists.

Source code in archipy/adapters/redis/adapters.py
@override
async def get(self, key: str) -> RedisResponseType:
    """Get the value of a key asynchronously.

    Args:
        key (str): The key name.

    Returns:
        RedisResponseType: The value of the key or None if not exists.
    """
    return await self.read_only_client.get(key)

archipy.adapters.redis.mocks.AsyncRedisMock.mget async

mget(
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType

Get the values of multiple keys asynchronously.

Parameters:

Name Type Description Default
keys RedisKeyType | Iterable[RedisKeyType]

Single key or iterable of keys.

required
*args bytes | str

Additional keys.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
async def mget(
    self,
    keys: RedisKeyType | Iterable[RedisKeyType],
    *args: bytes | str,
) -> RedisResponseType:
    """Get the values of multiple keys asynchronously.

    Args:
        keys (RedisKeyType | Iterable[RedisKeyType]): Single key or iterable of keys.
        *args (bytes | str): Additional keys.

    Returns:
        RedisResponseType: List of values.
    """
    return await self.read_only_client.mget(keys, *args)

archipy.adapters.redis.mocks.AsyncRedisMock.mset async

mset(
    mapping: Mapping[RedisKeyType, bytes | str | float],
) -> RedisResponseType

Set multiple keys to their values asynchronously.

Parameters:

Name Type Description Default
mapping Mapping[RedisKeyType, bytes | str | float]

Dictionary of key-value pairs.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Always returns 'OK'.

Source code in archipy/adapters/redis/adapters.py
@override
async def mset(self, mapping: Mapping[RedisKeyType, bytes | str | float]) -> RedisResponseType:
    """Set multiple keys to their values asynchronously.

    Args:
        mapping (Mapping[RedisKeyType, bytes | str | float]): Dictionary of key-value pairs.

    Returns:
        RedisResponseType: Always returns 'OK'.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    return await self.client.mset(dict_mapping)

archipy.adapters.redis.mocks.AsyncRedisMock.keys async

keys(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

Find all keys matching the pattern asynchronously.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match keys against. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
async def keys(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """Find all keys matching the pattern asynchronously.

    Args:
        pattern (RedisPatternType): Pattern to match keys against. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of matching keys.
    """
    return await self.read_only_client.keys(pattern, **kwargs)

archipy.adapters.redis.mocks.AsyncRedisMock.getset async

getset(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Set a key's value and return its old value asynchronously.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The new value.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The previous value or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def getset(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Set a key's value and return its old value asynchronously.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The new value.

    Returns:
        RedisResponseType: The previous value or None.
    """
    return await self.client.getset(key, value)

archipy.adapters.redis.mocks.AsyncRedisMock.getdel async

getdel(key: bytes | str) -> RedisResponseType

Get a key's value and delete it asynchronously.

Parameters:

Name Type Description Default
key bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

The value of the key or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def getdel(self, key: bytes | str) -> RedisResponseType:
    """Get a key's value and delete it asynchronously.

    Args:
        key (bytes | str): The key name.

    Returns:
        RedisResponseType: The value of the key or None.
    """
    return await self.client.getdel(key)

archipy.adapters.redis.mocks.AsyncRedisMock.exists async

exists(*names: bytes | str) -> RedisResponseType

Check if keys exist asynchronously.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys that exist.

Source code in archipy/adapters/redis/adapters.py
@override
async def exists(self, *names: bytes | str) -> RedisResponseType:
    """Check if keys exist asynchronously.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys that exist.
    """
    return await self.read_only_client.exists(*names)

archipy.adapters.redis.mocks.AsyncRedisMock.delete async

delete(*names: bytes | str) -> RedisResponseType

Delete keys asynchronously.

Parameters:

Name Type Description Default
*names bytes | str

Variable number of key names.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of keys deleted.

Source code in archipy/adapters/redis/adapters.py
@override
async def delete(self, *names: bytes | str) -> RedisResponseType:
    """Delete keys asynchronously.

    Args:
        *names (bytes | str): Variable number of key names.

    Returns:
        RedisResponseType: Number of keys deleted.
    """
    return await self.client.delete(*names)

archipy.adapters.redis.mocks.AsyncRedisMock.append async

append(
    key: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Append a value to a key asynchronously.

Parameters:

Name Type Description Default
key RedisKeyType

The key name.

required
value bytes | str | float

The value to append.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Length of the string after append.

Source code in archipy/adapters/redis/adapters.py
@override
async def append(self, key: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Append a value to a key asynchronously.

    Args:
        key (RedisKeyType): The key name.
        value (bytes | str | float): The value to append.

    Returns:
        RedisResponseType: Length of the string after append.
    """
    return await self.client.append(key, value)

archipy.adapters.redis.mocks.AsyncRedisMock.ttl async

ttl(name: bytes | str) -> RedisResponseType

Get the time to live in seconds for a key asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Time to live in seconds.

Source code in archipy/adapters/redis/adapters.py
@override
async def ttl(self, name: bytes | str) -> RedisResponseType:
    """Get the time to live in seconds for a key asynchronously.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Time to live in seconds.
    """
    return await self.read_only_client.ttl(name)

archipy.adapters.redis.mocks.AsyncRedisMock.type async

type(name: bytes | str) -> RedisResponseType

Determine the type stored at key asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Type of the key's value.

Source code in archipy/adapters/redis/adapters.py
@override
async def type(self, name: bytes | str) -> RedisResponseType:
    """Determine the type stored at key asynchronously.

    Args:
        name (bytes | str): The key name.

    Returns:
        RedisResponseType: Type of the key's value.
    """
    return await self.read_only_client.type(name)

archipy.adapters.redis.mocks.AsyncRedisMock.llen async

llen(name: str) -> RedisIntegerResponseType

Get the length of a list asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list.

Source code in archipy/adapters/redis/adapters.py
@override
async def llen(self, name: str) -> RedisIntegerResponseType:
    """Get the length of a list asynchronously.

    Args:
        name (str): The key name of the list.

    Returns:
        RedisIntegerResponseType: Length of the list.
    """
    result = self.read_only_client.llen(name)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.lpop async

lpop(name: str, count: int | None = None) -> Any

Remove and return elements from list left asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
async def lpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from list left asynchronously.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    result = self.client.lpop(name, count)
    if isinstance(result, Awaitable):
        return await result
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.lpush async

lpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to list left asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
async def lpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to list left asynchronously.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.lpush(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.lrange async

lrange(
    name: str, start: int, end: int
) -> RedisListResponseType

Get a range of elements from a list asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
start int

Start index.

required
end int

End index.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of elements in range.

Source code in archipy/adapters/redis/adapters.py
@override
async def lrange(self, name: str, start: int, end: int) -> RedisListResponseType:
    """Get a range of elements from a list asynchronously.

    Args:
        name (str): The key name of the list.
        start (int): Start index.
        end (int): End index.

    Returns:
        RedisListResponseType: List of elements in range.
    """
    result = self.read_only_client.lrange(name, start, end)
    if isinstance(result, Awaitable):
        result = await result
    if result is None:
        return []
    if isinstance(result, list):
        return result
    from collections.abc import Iterable

    if isinstance(result, Iterable):
        return list(result)
    return []

archipy.adapters.redis.mocks.AsyncRedisMock.lrem async

lrem(
    name: str, count: int, value: str
) -> RedisIntegerResponseType

Remove elements from a list asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int

Number of occurrences to remove.

required
value str

Value to remove.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements removed.

Source code in archipy/adapters/redis/adapters.py
@override
async def lrem(self, name: str, count: int, value: str) -> RedisIntegerResponseType:
    """Remove elements from a list asynchronously.

    Args:
        name (str): The key name of the list.
        count (int): Number of occurrences to remove.
        value (str): Value to remove.

    Returns:
        RedisIntegerResponseType: Number of elements removed.
    """
    result = self.client.lrem(name, count, value)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.lset async

lset(name: str, index: int, value: str) -> bool

Set list element by index asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
index int

Index of the element.

required
value str

New value.

required

Returns:

Name Type Description
bool bool

True if successful.

Source code in archipy/adapters/redis/adapters.py
@override
async def lset(self, name: str, index: int, value: str) -> bool:
    """Set list element by index asynchronously.

    Args:
        name (str): The key name of the list.
        index (int): Index of the element.
        value (str): New value.

    Returns:
        bool: True if successful.
    """
    result = self.client.lset(name, index, value)
    if isinstance(result, Awaitable):
        result = await result
    return bool(result)

archipy.adapters.redis.mocks.AsyncRedisMock.rpop async

rpop(name: str, count: int | None = None) -> Any

Remove and return elements from list right asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
count int | None

Number of elements to pop. Defaults to None.

None

Returns:

Name Type Description
Any Any

Popped element(s) or None if list is empty.

Source code in archipy/adapters/redis/adapters.py
@override
async def rpop(self, name: str, count: int | None = None) -> Any:
    """Remove and return elements from list right asynchronously.

    Args:
        name (str): The key name of the list.
        count (int | None): Number of elements to pop. Defaults to None.

    Returns:
        Any: Popped element(s) or None if list is empty.
    """
    result = self.client.rpop(name, count)
    if isinstance(result, Awaitable):
        return await result
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.rpush async

rpush(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Push elements to list right asynchronously.

Parameters:

Name Type Description Default
name str

The key name of the list.

required
*values bytes | str | float

Values to push.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Length of the list after push.

Source code in archipy/adapters/redis/adapters.py
@override
async def rpush(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Push elements to list right asynchronously.

    Args:
        name (str): The key name of the list.
        *values (bytes | str | float): Values to push.

    Returns:
        RedisIntegerResponseType: Length of the list after push.
    """
    result = self.client.rpush(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.scan async

scan(
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType

Scan keys in database incrementally asynchronously.

Parameters:

Name Type Description Default
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of keys.

Source code in archipy/adapters/redis/adapters.py
@override
async def scan(
    self,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> RedisResponseType:
    """Scan keys in database incrementally asynchronously.

    Args:
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Tuple of cursor and list of keys.
    """
    return await self.read_only_client.scan(cursor, match, count, _type, **kwargs)

archipy.adapters.redis.mocks.AsyncRedisMock.scan_iter async

scan_iter(
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator[Any]

Iterate over keys in database asynchronously.

Parameters:

Name Type Description Default
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of keys. Defaults to None.

None
_type str | None

Filter by type. Defaults to None.

None
**kwargs Any

Additional arguments.

{}

Returns:

Type Description
Iterator[Any]

Iterator[Any]: Iterator over matching keys.

Source code in archipy/adapters/redis/adapters.py
@override
async def scan_iter(
    self,
    match: bytes | str | None = None,
    count: int | None = None,
    _type: str | None = None,
    **kwargs: Any,
) -> Iterator[Any]:
    """Iterate over keys in database asynchronously.

    Args:
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of keys. Defaults to None.
        _type (str | None): Filter by type. Defaults to None.
        **kwargs (Any): Additional arguments.

    Returns:
        Iterator[Any]: Iterator over matching keys.
    """
    result = self.read_only_client.scan_iter(match, count, _type, **kwargs)
    if isinstance(result, Awaitable):
        raise TypeError("Unexpected awaitable from sync Redis client")
    # Type narrowing: result is an Iterator
    if not isinstance(result, Iterator):
        raise TypeError(f"Expected Iterator, got {type(result)}")
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.sscan async

sscan(
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType

Scan set members incrementally asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
cursor int

Cursor position. Defaults to 0.

0
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

Tuple of cursor and list of members.

Source code in archipy/adapters/redis/adapters.py
@override
async def sscan(
    self,
    name: RedisKeyType,
    cursor: int = 0,
    match: bytes | str | None = None,
    count: int | None = None,
) -> RedisResponseType:
    """Scan set members incrementally asynchronously.

    Args:
        name (RedisKeyType): The set key name.
        cursor (int): Cursor position. Defaults to 0.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        RedisResponseType: Tuple of cursor and list of members.
    """
    result = self.read_only_client.sscan(name, cursor, match, count)
    if isinstance(result, Awaitable):
        awaited_result: RedisResponseType = await result
        return awaited_result
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.sscan_iter async

sscan_iter(
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator[Any]

Iterate over set members asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The set key name.

required
match bytes | str | None

Pattern to match. Defaults to None.

None
count int | None

Hint for number of elements. Defaults to None.

None

Returns:

Type Description
Iterator[Any]

Iterator[Any]: Iterator over set members.

Source code in archipy/adapters/redis/adapters.py
@override
async def sscan_iter(
    self,
    name: RedisKeyType,
    match: bytes | str | None = None,
    count: int | None = None,
) -> Iterator[Any]:
    """Iterate over set members asynchronously.

    Args:
        name (RedisKeyType): The set key name.
        match (bytes | str | None): Pattern to match. Defaults to None.
        count (int | None): Hint for number of elements. Defaults to None.

    Returns:
        Iterator[Any]: Iterator over set members.
    """
    result = self.read_only_client.sscan_iter(name, match, count)
    if isinstance(result, Awaitable):
        awaited_result = await result
        if not isinstance(awaited_result, Iterator):
            raise TypeError(f"Expected Iterator, got {type(awaited_result)}")
        return awaited_result
    # Type narrowing: result is an Iterator
    if not isinstance(result, Iterator):
        raise TypeError(f"Expected Iterator, got {type(result)}")
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.sadd async

sadd(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Add members to a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to add.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of elements added.

Source code in archipy/adapters/redis/adapters.py
@override
async def sadd(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Add members to a set asynchronously.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to add.

    Returns:
        RedisIntegerResponseType: Number of elements added.
    """
    result = self.client.sadd(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.scard async

scard(name: str) -> RedisIntegerResponseType

Get number of members in a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
async def scard(self, name: str) -> RedisIntegerResponseType:
    """Get number of members in a set asynchronously.

    Args:
        name (str): The set key name.

    Returns:
        RedisIntegerResponseType: Number of members.
    """
    result = self.client.scard(name)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.sismember async

sismember(name: str, value: str) -> bool

Check if value is in set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
value str

Value to check.

required

Returns:

Name Type Description
bool bool

True if value is member, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
async def sismember(self, name: str, value: str) -> bool:
    """Check if value is in set asynchronously.

    Args:
        name (str): The set key name.
        value (str): Value to check.

    Returns:
        bool: True if value is member, False otherwise.
    """
    result = self.read_only_client.sismember(name, value)
    if isinstance(result, Awaitable):
        result = await result
    return bool(result)

archipy.adapters.redis.mocks.AsyncRedisMock.smembers async

smembers(name: str) -> RedisSetResponseType

Get all members of a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set of all members.

Source code in archipy/adapters/redis/adapters.py
@override
async def smembers(self, name: str) -> RedisSetResponseType:
    """Get all members of a set asynchronously.

    Args:
        name (str): The set key name.

    Returns:
        RedisSetResponseType: Set of all members.
    """
    result = self.read_only_client.smembers(name)
    if isinstance(result, Awaitable):
        result = await result
    if result is None:
        return set()
    if isinstance(result, set):
        return result
    from collections.abc import Iterable

    if isinstance(result, Iterable):
        return set(result)
    return set()

archipy.adapters.redis.mocks.AsyncRedisMock.spop async

spop(
    name: str, count: int | None = None
) -> bytes | float | int | str | list | None

Remove and return random set members asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
count int | None

Number of members to pop. Defaults to None.

None

Returns:

Type Description
bytes | float | int | str | list | None

bytes | float | int | str | list | None: Popped member(s) or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def spop(self, name: str, count: int | None = None) -> bytes | float | int | str | list | None:
    """Remove and return random set members asynchronously.

    Args:
        name (str): The set key name.
        count (int | None): Number of members to pop. Defaults to None.

    Returns:
        bytes | float | int | str | list | None: Popped member(s) or None.
    """
    result = self.client.spop(name, count)
    if isinstance(result, Awaitable):
        awaited_result = await result
        # Type narrowing: result can be any of the return types
        if awaited_result is None or isinstance(awaited_result, (bytes, float, int, str, list)):
            return awaited_result
        raise TypeError(f"Unexpected type from spop: {type(awaited_result)}")
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.srem async

srem(
    name: str, *values: bytes | str | float
) -> RedisIntegerResponseType

Remove members from a set asynchronously.

Parameters:

Name Type Description Default
name str

The set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
async def srem(self, name: str, *values: bytes | str | float) -> RedisIntegerResponseType:
    """Remove members from a set asynchronously.

    Args:
        name (str): The set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisIntegerResponseType: Number of members removed.
    """
    result = self.client.srem(name, *values)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.sunion async

sunion(
    keys: RedisKeyType, *args: bytes | str
) -> RedisSetResponseType

Get union of multiple sets asynchronously.

Parameters:

Name Type Description Default
keys RedisKeyType

First set key.

required
*args bytes | str

Additional set keys.

()

Returns:

Name Type Description
RedisSetResponseType RedisSetResponseType

Set containing union of all sets.

Source code in archipy/adapters/redis/adapters.py
@override
async def sunion(self, keys: RedisKeyType, *args: bytes | str) -> RedisSetResponseType:
    """Get union of multiple sets asynchronously.

    Args:
        keys (RedisKeyType): First set key.
        *args (bytes | str): Additional set keys.

    Returns:
        RedisSetResponseType: Set containing union of all sets.
    """
    # Convert keys to str for type compatibility, combine into list
    keys_list: list[str] = [str(keys)] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
    result = self.client.sunion(keys_list)
    if isinstance(result, Awaitable):
        result = await result
    if result is None:
        return set()
    if isinstance(result, set):
        return result
    from collections.abc import Iterable

    if isinstance(result, Iterable):
        return set(result)
    return set()

archipy.adapters.redis.mocks.AsyncRedisMock.zadd async

zadd(
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType

Add members to sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
mapping Mapping[RedisKeyType, bytes | str | float]

Member-score pairs.

required
nx bool

Only add new elements. Defaults to False.

False
xx bool

Only update existing. Defaults to False.

False
ch bool

Return changed count. Defaults to False.

False
incr bool

Increment scores. Defaults to False.

False
gt bool

Only if greater. Defaults to False.

False
lt bool

Only if less. Defaults to False.

False

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of elements added or modified.

Source code in archipy/adapters/redis/adapters.py
@override
async def zadd(
    self,
    name: RedisKeyType,
    mapping: Mapping[RedisKeyType, bytes | str | float],
    nx: bool = False,
    xx: bool = False,
    ch: bool = False,
    incr: bool = False,
    gt: bool = False,
    lt: bool = False,
) -> RedisResponseType:
    """Add members to sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        mapping (Mapping[RedisKeyType, bytes | str | float]): Member-score pairs.
        nx (bool): Only add new elements. Defaults to False.
        xx (bool): Only update existing. Defaults to False.
        ch (bool): Return changed count. Defaults to False.
        incr (bool): Increment scores. Defaults to False.
        gt (bool): Only if greater. Defaults to False.
        lt (bool): Only if less. Defaults to False.

    Returns:
        RedisResponseType: Number of elements added or modified.
    """
    # Convert Mapping to dict for type compatibility with Redis client
    if isinstance(mapping, dict):
        dict_mapping: dict[str, bytes | str | float] = {str(k): v for k, v in mapping.items()}
    else:
        dict_mapping = {str(k): v for k, v in mapping.items()}
    str_name = str(name)
    result = self.client.zadd(str_name, dict_mapping, nx, xx, ch, incr, gt, lt)
    if isinstance(result, Awaitable):
        return await result
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.zcard async

zcard(name: bytes | str) -> RedisResponseType

Get number of members in sorted set asynchronously.

Parameters:

Name Type Description Default
name bytes | str

The sorted set key name.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members.

Source code in archipy/adapters/redis/adapters.py
@override
async def zcard(self, name: bytes | str) -> RedisResponseType:
    """Get number of members in sorted set asynchronously.

    Args:
        name (bytes | str): The sorted set key name.

    Returns:
        RedisResponseType: Number of members.
    """
    return await self.client.zcard(name)

archipy.adapters.redis.mocks.AsyncRedisMock.zcount async

zcount(
    name: RedisKeyType, min: float | str, max: float | str
) -> RedisResponseType

Count members in score range asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members in range.

Source code in archipy/adapters/redis/adapters.py
@override
async def zcount(self, name: RedisKeyType, min: float | str, max: float | str) -> RedisResponseType:
    """Count members in score range asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.

    Returns:
        RedisResponseType: Number of members in range.
    """
    return await self.client.zcount(name, min, max)

archipy.adapters.redis.mocks.AsyncRedisMock.zpopmax async

zpopmax(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Pop highest scored members asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zpopmax(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Pop highest scored members asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return await self.client.zpopmax(name, count)

archipy.adapters.redis.mocks.AsyncRedisMock.zpopmin async

zpopmin(
    name: RedisKeyType, count: int | None = None
) -> RedisResponseType

Pop lowest scored members asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
count int | None

Number to pop. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of popped member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zpopmin(self, name: RedisKeyType, count: int | None = None) -> RedisResponseType:
    """Pop lowest scored members asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        count (int | None): Number to pop. Defaults to None.

    Returns:
        RedisResponseType: List of popped member-score pairs.
    """
    return await self.client.zpopmin(name, count)

archipy.adapters.redis.mocks.AsyncRedisMock.zrange async

zrange(
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType

Get range from sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index or score.

required
end int

End index or score.

required
desc bool

Descending order. Defaults to False.

False
withscores bool

Include scores. Defaults to False.

False
score_cast_func RedisScoreCastType

Score cast function. Defaults to float.

float
byscore bool

Range by score. Defaults to False.

False
bylex bool

Range by lex. Defaults to False.

False
offset int | None

Offset for byscore/bylex. Defaults to None.

None
num int | None

Count for byscore/bylex. Defaults to None.

None

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    desc: bool = False,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
    byscore: bool = False,
    bylex: bool = False,
    offset: int | None = None,
    num: int | None = None,
) -> RedisResponseType:
    """Get range from sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index or score.
        end (int): End index or score.
        desc (bool): Descending order. Defaults to False.
        withscores (bool): Include scores. Defaults to False.
        score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.
        byscore (bool): Range by score. Defaults to False.
        bylex (bool): Range by lex. Defaults to False.
        offset (int | None): Offset for byscore/bylex. Defaults to None.
        num (int | None): Count for byscore/bylex. Defaults to None.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return await self.client.zrange(
        name,
        start,
        end,
        desc,
        withscores,
        score_cast_func,
        byscore,
        bylex,
        offset,
        num,
    )

archipy.adapters.redis.mocks.AsyncRedisMock.zrevrange async

zrevrange(
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get reverse range from sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
start int

Start index.

required
end int

End index.

required
withscores bool

Include scores. Defaults to False.

False
score_cast_func RedisScoreCastType

Score cast function. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrevrange(
    self,
    name: RedisKeyType,
    start: int,
    end: int,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get reverse range from sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        start (int): Start index.
        end (int): End index.
        withscores (bool): Include scores. Defaults to False.
        score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return await self.client.zrevrange(name, start, end, withscores, score_cast_func)

archipy.adapters.redis.mocks.AsyncRedisMock.zrangebyscore async

zrangebyscore(
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType

Get members by score range asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
min float | str

Minimum score.

required
max float | str

Maximum score.

required
start int | None

Offset. Defaults to None.

None
num int | None

Count. Defaults to None.

None
withscores bool

Include scores. Defaults to False.

False
score_cast_func RedisScoreCastType

Score cast function. Defaults to float.

float

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of members or member-score pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrangebyscore(
    self,
    name: RedisKeyType,
    min: float | str,
    max: float | str,
    start: int | None = None,
    num: int | None = None,
    withscores: bool = False,
    score_cast_func: RedisScoreCastType = float,
) -> RedisResponseType:
    """Get members by score range asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        min (float | str): Minimum score.
        max (float | str): Maximum score.
        start (int | None): Offset. Defaults to None.
        num (int | None): Count. Defaults to None.
        withscores (bool): Include scores. Defaults to False.
        score_cast_func (RedisScoreCastType): Score cast function. Defaults to float.

    Returns:
        RedisResponseType: List of members or member-score pairs.
    """
    return await self.client.zrangebyscore(name, min, max, start, num, withscores, score_cast_func)

archipy.adapters.redis.mocks.AsyncRedisMock.zrank async

zrank(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get rank of member in sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to find rank for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Rank or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrank(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get rank of member in sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to find rank for.

    Returns:
        RedisResponseType: Rank or None if not found.
    """
    return await self.client.zrank(name, value)

archipy.adapters.redis.mocks.AsyncRedisMock.zrem async

zrem(
    name: RedisKeyType, *values: bytes | str | float
) -> RedisResponseType

Remove members from sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
*values bytes | str | float

Members to remove.

()

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of members removed.

Source code in archipy/adapters/redis/adapters.py
@override
async def zrem(self, name: RedisKeyType, *values: bytes | str | float) -> RedisResponseType:
    """Remove members from sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        *values (bytes | str | float): Members to remove.

    Returns:
        RedisResponseType: Number of members removed.
    """
    return await self.client.zrem(name, *values)

archipy.adapters.redis.mocks.AsyncRedisMock.zscore async

zscore(
    name: RedisKeyType, value: bytes | str | float
) -> RedisResponseType

Get score of member in sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
value bytes | str | float

Member to get score for.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

Score or None if not found.

Source code in archipy/adapters/redis/adapters.py
@override
async def zscore(self, name: RedisKeyType, value: bytes | str | float) -> RedisResponseType:
    """Get score of member in sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        value (bytes | str | float): Member to get score for.

    Returns:
        RedisResponseType: Score or None if not found.
    """
    return await self.client.zscore(name, value)

archipy.adapters.redis.mocks.AsyncRedisMock.hdel async

hdel(
    name: str, *keys: str | bytes
) -> RedisIntegerResponseType

Delete fields from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
*keys str | bytes

Fields to delete.

()

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields deleted.

Source code in archipy/adapters/redis/adapters.py
@override
async def hdel(self, name: str, *keys: str | bytes) -> RedisIntegerResponseType:
    """Delete fields from hash asynchronously.

    Args:
        name (str): The hash key name.
        *keys (str | bytes): Fields to delete.

    Returns:
        RedisIntegerResponseType: Number of fields deleted.
    """
    # Convert keys to str for type compatibility
    str_keys: tuple[str, ...] = tuple(str(k) if isinstance(k, bytes) else k for k in keys)
    result = self.client.hdel(name, *str_keys)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.hexists async

hexists(name: str, key: str) -> bool

Check if field exists in hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to check.

required

Returns:

Name Type Description
bool bool

True if exists, False otherwise.

Source code in archipy/adapters/redis/adapters.py
@override
async def hexists(self, name: str, key: str) -> bool:
    """Check if field exists in hash asynchronously.

    Args:
        name (str): The hash key name.
        key (str): Field to check.

    Returns:
        bool: True if exists, False otherwise.
    """
    result = self.read_only_client.hexists(name, key)
    return await self._ensure_async_bool(result)

archipy.adapters.redis.mocks.AsyncRedisMock.hget async

hget(name: str, key: str) -> str | None

Get field value from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str

Field to get.

required

Returns:

Type Description
str | None

str | None: Value or None.

Source code in archipy/adapters/redis/adapters.py
@override
async def hget(self, name: str, key: str) -> str | None:
    """Get field value from hash asynchronously.

    Args:
        name (str): The hash key name.
        key (str): Field to get.

    Returns:
        str | None: Value or None.
    """
    result = self.read_only_client.hget(name, key)
    resolved = await self._ensure_async_str(result)
    return str(resolved) if resolved is not None else None

archipy.adapters.redis.mocks.AsyncRedisMock.hgetall async

hgetall(name: str) -> dict[str, Any]

Get all fields and values from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Dictionary of field-value pairs.

Source code in archipy/adapters/redis/adapters.py
@override
async def hgetall(self, name: str) -> dict[str, Any]:
    """Get all fields and values from hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        dict[str, Any]: Dictionary of field-value pairs.
    """
    result = self.read_only_client.hgetall(name)
    if isinstance(result, Awaitable):
        awaited_result = await result
        if awaited_result is None:
            return {}
        if isinstance(awaited_result, dict):
            return {str(k): v for k, v in awaited_result.items()}
        from collections.abc import Mapping

        if isinstance(awaited_result, Mapping):
            return {str(k): v for k, v in awaited_result.items()}
        return {}
    if result is None:
        return {}
    if isinstance(result, dict):
        return {str(k): v for k, v in result.items()}
    from collections.abc import Mapping

    if isinstance(result, Mapping):
        return {str(k): v for k, v in result.items()}
    return {}

archipy.adapters.redis.mocks.AsyncRedisMock.hkeys async

hkeys(name: str) -> RedisListResponseType

Get all fields from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field names.

Source code in archipy/adapters/redis/adapters.py
@override
async def hkeys(self, name: str) -> RedisListResponseType:
    """Get all fields from hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of field names.
    """
    result = self.read_only_client.hkeys(name)
    return await self._ensure_async_list(result)

archipy.adapters.redis.mocks.AsyncRedisMock.hlen async

hlen(name: str) -> RedisIntegerResponseType

Get number of fields in hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields.

Source code in archipy/adapters/redis/adapters.py
@override
async def hlen(self, name: str) -> RedisIntegerResponseType:
    """Get number of fields in hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        RedisIntegerResponseType: Number of fields.
    """
    result = self.read_only_client.hlen(name)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.hset async

hset(
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType

Set fields in hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
key str | bytes | None

Single field name. Defaults to None.

None
value str | bytes | None

Single field value. Defaults to None.

None
mapping dict | None

Field-value pairs dict. Defaults to None.

None
items list | None

Field-value pairs list. Defaults to None.

None

Returns:

Name Type Description
RedisIntegerResponseType RedisIntegerResponseType

Number of fields set.

Source code in archipy/adapters/redis/adapters.py
@override
async def hset(
    self,
    name: str,
    key: str | bytes | None = None,
    value: str | bytes | None = None,
    mapping: dict | None = None,
    items: list | None = None,
) -> RedisIntegerResponseType:
    """Set fields in hash asynchronously.

    Args:
        name (str): The hash key name.
        key (str | bytes | None): Single field name. Defaults to None.
        value (str | bytes | None): Single field value. Defaults to None.
        mapping (dict | None): Field-value pairs dict. Defaults to None.
        items (list | None): Field-value pairs list. Defaults to None.

    Returns:
        RedisIntegerResponseType: Number of fields set.
    """
    # Convert bytes to str for type compatibility with Redis client
    str_key: str | None = str(key) if key is not None and isinstance(key, bytes) else key
    str_value: str | None = str(value) if value is not None and isinstance(value, bytes) else value
    result = self.client.hset(name, str_key, str_value, mapping, items)
    return await self._ensure_async_int(result)

archipy.adapters.redis.mocks.AsyncRedisMock.hmget async

hmget(
    name: str, keys: list, *args: str | bytes
) -> RedisListResponseType

Get multiple field values from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required
keys list

List of field names.

required
*args str | bytes

Additional field names.

()

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of field values.

Source code in archipy/adapters/redis/adapters.py
@override
async def hmget(self, name: str, keys: list, *args: str | bytes) -> RedisListResponseType:
    """Get multiple field values from hash asynchronously.

    Args:
        name (str): The hash key name.
        keys (list): List of field names.
        *args (str | bytes): Additional field names.

    Returns:
        RedisListResponseType: List of field values.
    """
    # Convert keys list and args for type compatibility, combine into single list
    keys_list: list[str] = [str(k) for k in keys] + [str(arg) if isinstance(arg, bytes) else arg for arg in args]
    result = self.read_only_client.hmget(name, keys_list)
    return await self._ensure_async_list(result)

archipy.adapters.redis.mocks.AsyncRedisMock.hvals async

hvals(name: str) -> RedisListResponseType

Get all values from hash asynchronously.

Parameters:

Name Type Description Default
name str

The hash key name.

required

Returns:

Name Type Description
RedisListResponseType RedisListResponseType

List of values.

Source code in archipy/adapters/redis/adapters.py
@override
async def hvals(self, name: str) -> RedisListResponseType:
    """Get all values from hash asynchronously.

    Args:
        name (str): The hash key name.

    Returns:
        RedisListResponseType: List of values.
    """
    result = self.read_only_client.hvals(name)
    return await self._ensure_async_list(result)

archipy.adapters.redis.mocks.AsyncRedisMock.publish async

publish(
    channel: RedisKeyType,
    message: bytes | str,
    **kwargs: Any,
) -> RedisResponseType

Publish message to channel asynchronously.

Parameters:

Name Type Description Default
channel RedisKeyType

Channel name.

required
message bytes | str

Message to publish.

required
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

Number of subscribers received message.

Source code in archipy/adapters/redis/adapters.py
@override
async def publish(self, channel: RedisKeyType, message: bytes | str, **kwargs: Any) -> RedisResponseType:
    """Publish message to channel asynchronously.

    Args:
        channel (RedisKeyType): Channel name.
        message (bytes | str): Message to publish.
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: Number of subscribers received message.
    """
    # AsyncRedis client has publish method, type stubs may be incomplete
    publish_method = getattr(self.client, "publish", None)
    if publish_method and callable(publish_method):
        result = publish_method(channel, message, **kwargs)
        if isinstance(result, Awaitable):
            return await result
        return result
    raise AttributeError("publish method not available on Redis client")

archipy.adapters.redis.mocks.AsyncRedisMock.pubsub_channels async

pubsub_channels(
    pattern: RedisPatternType = "*", **kwargs: Any
) -> RedisResponseType

List active channels matching pattern asynchronously.

Parameters:

Name Type Description Default
pattern RedisPatternType

Pattern to match. Defaults to "*".

'*'
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
RedisResponseType RedisResponseType

List of channel names.

Source code in archipy/adapters/redis/adapters.py
@override
async def pubsub_channels(self, pattern: RedisPatternType = "*", **kwargs: Any) -> RedisResponseType:
    """List active channels matching pattern asynchronously.

    Args:
        pattern (RedisPatternType): Pattern to match. Defaults to "*".
        **kwargs (Any): Additional arguments.

    Returns:
        RedisResponseType: List of channel names.
    """
    # AsyncRedis client has pubsub_channels method, type stubs may be incomplete
    pubsub_channels_method = getattr(self.client, "pubsub_channels", None)
    if pubsub_channels_method and callable(pubsub_channels_method):
        result = pubsub_channels_method(pattern, **kwargs)
        if isinstance(result, Awaitable):
            return await result
        return result
    raise AttributeError("pubsub_channels method not available on Redis client")

archipy.adapters.redis.mocks.AsyncRedisMock.zincrby async

zincrby(
    name: RedisKeyType,
    amount: float,
    value: bytes | str | float,
) -> RedisResponseType

Increment member score in sorted set asynchronously.

Parameters:

Name Type Description Default
name RedisKeyType

The sorted set key name.

required
amount float

Amount to increment by.

required
value bytes | str | float

Member to increment.

required

Returns:

Name Type Description
RedisResponseType RedisResponseType

New score of the member.

Source code in archipy/adapters/redis/adapters.py
@override
async def zincrby(self, name: RedisKeyType, amount: float, value: bytes | str | float) -> RedisResponseType:
    """Increment member score in sorted set asynchronously.

    Args:
        name (RedisKeyType): The sorted set key name.
        amount (float): Amount to increment by.
        value (bytes | str | float): Member to increment.

    Returns:
        RedisResponseType: New score of the member.
    """
    return await self.client.zincrby(name, amount, value)

archipy.adapters.redis.mocks.AsyncRedisMock.pubsub async

pubsub(**kwargs: Any) -> AsyncPubSub

Get PubSub object for channel subscription asynchronously.

Parameters:

Name Type Description Default
**kwargs Any

Additional arguments.

{}

Returns:

Name Type Description
AsyncPubSub PubSub

PubSub object.

Source code in archipy/adapters/redis/adapters.py
@override
async def pubsub(self, **kwargs: Any) -> AsyncPubSub:
    """Get PubSub object for channel subscription asynchronously.

    Args:
        **kwargs (Any): Additional arguments.

    Returns:
        AsyncPubSub: PubSub object.
    """
    # Redis client has pubsub method, type stubs may be incomplete
    pubsub_method = getattr(self.client, "pubsub", None)
    if pubsub_method and callable(pubsub_method):
        return pubsub_method(**kwargs)
    raise AttributeError("pubsub method not available on Redis client")

archipy.adapters.redis.mocks.AsyncRedisMock.get_pipeline async

get_pipeline(
    transaction: Any = True, shard_hint: Any = None
) -> AsyncPipeline

Get pipeline for multiple commands asynchronously.

Parameters:

Name Type Description Default
transaction Any

Use transactions. Defaults to True.

True
shard_hint Any

Sharding hint. Defaults to None.

None

Returns:

Name Type Description
AsyncPipeline Pipeline

Pipeline object.

Source code in archipy/adapters/redis/adapters.py
@override
async def get_pipeline(self, transaction: Any = True, shard_hint: Any = None) -> AsyncPipeline:
    """Get pipeline for multiple commands asynchronously.

    Args:
        transaction (Any): Use transactions. Defaults to True.
        shard_hint (Any): Sharding hint. Defaults to None.

    Returns:
        AsyncPipeline: Pipeline object.
    """
    result = self.client.pipeline(transaction, shard_hint)
    # Type narrowing: result is an AsyncPipeline
    if not isinstance(result, AsyncPipeline):
        raise TypeError(f"Expected AsyncPipeline, got {type(result)}")
    return result

archipy.adapters.redis.mocks.AsyncRedisMock.cluster_info async

cluster_info() -> RedisResponseType

Get cluster information asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_info(self) -> RedisResponseType:
    """Get cluster information asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_info()
    return None

archipy.adapters.redis.mocks.AsyncRedisMock.cluster_nodes async

cluster_nodes() -> RedisResponseType

Get cluster nodes information asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_nodes(self) -> RedisResponseType:
    """Get cluster nodes information asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_nodes()
    return None

archipy.adapters.redis.mocks.AsyncRedisMock.cluster_slots async

cluster_slots() -> RedisResponseType

Get cluster slots mapping asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_slots(self) -> RedisResponseType:
    """Get cluster slots mapping asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_slots()
    return None

archipy.adapters.redis.mocks.AsyncRedisMock.cluster_key_slot async

cluster_key_slot(key: str) -> RedisResponseType

Get the hash slot for a key asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_key_slot(self, key: str) -> RedisResponseType:
    """Get the hash slot for a key asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_keyslot(key)
    return None

archipy.adapters.redis.mocks.AsyncRedisMock.cluster_count_keys_in_slot async

cluster_count_keys_in_slot(slot: int) -> RedisResponseType

Count keys in a specific slot asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_count_keys_in_slot(self, slot: int) -> RedisResponseType:
    """Count keys in a specific slot asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_countkeysinslot(slot)
    return None

archipy.adapters.redis.mocks.AsyncRedisMock.cluster_get_keys_in_slot async

cluster_get_keys_in_slot(
    slot: int, count: int
) -> RedisResponseType

Get keys in a specific slot asynchronously.

Source code in archipy/adapters/redis/adapters.py
@override
async def cluster_get_keys_in_slot(self, slot: int, count: int) -> RedisResponseType:
    """Get keys in a specific slot asynchronously."""
    if isinstance(self.client, AsyncRedisCluster):
        return await self.client.cluster_get_keys_in_slot(slot, count)
    return None

options: show_root_toc_entry: false heading_level: 3