Skip to content

Base Transaction

Home / python / base_transaction

glide.async_commands.transaction.BaseTransaction

Base class encompassing shared commands for both standalone and cluster mode implementations in transaction.

Command Response

The response for each command depends on the executed command. Specific response types are documented alongside each method.

Example

transaction = BaseTransaction() transaction.set("key", "value").get("key") await client.exec(transaction) [OK , "value"]

Source code in glide/async_commands/transaction.py
  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
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
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
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
class BaseTransaction:
    """
    Base class encompassing shared commands for both standalone and cluster mode implementations in transaction.

    Command Response:
        The response for each command depends on the executed command. Specific response types
        are documented alongside each method.

    Example:
        >>> transaction = BaseTransaction()
        >>> transaction.set("key", "value").get("key")
        >>> await client.exec(transaction)
        [OK , "value"]
    """

    def __init__(self) -> None:
        self.commands: List[Tuple[RequestType.ValueType, List[TEncodable]]] = []
        self.lock = threading.Lock()

    def append_command(
        self: TTransaction,
        request_type: RequestType.ValueType,
        args: List[TEncodable],
    ) -> TTransaction:
        self.lock.acquire()
        try:
            self.commands.append((request_type, args))
        finally:
            self.lock.release()
        return self

    def clear(self):
        with self.lock:
            self.commands.clear()

    def get(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Get the value associated with the given key, or null if no such value exists.

        See [valkey.io](https://valkey.io/commands/get/) for details.

        Args:
            key (TEncodable): The key to retrieve from the database.

        Command response:
            Optional[bytes]: If the key exists, returns the value of the key as a bytes string.

            Otherwise, return None.
        """
        return self.append_command(RequestType.Get, [key])

    def getdel(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Gets a value associated with the given string `key` and deletes the key.

        See [valkey.io](https://valkey.io/commands/getdel) for more details.

        Args:
            key (TEncodable): The `key` to retrieve from the database.

        Command response:
            Optional[bytes]: If `key` exists, returns the `value` of `key`.

            Otherwise, returns `None`.
        """
        return self.append_command(RequestType.GetDel, [key])

    def getrange(
        self: TTransaction, key: TEncodable, start: int, end: int
    ) -> TTransaction:
        """
        Returns the substring of the string value stored at `key`, determined by the offsets `start` and `end`
        (both are inclusive).
        Negative offsets can be used in order to provide an offset starting from the end of the string.
        So `-1` means the last character, `-2` the penultimate and so forth.

        If `key` does not exist, an empty string is returned. If `start` or `end`
        are out of range, returns the substring within the valid range of the string.

        See [valkey.io](https://valkey.io/commands/getrange/) for more details.

        Args:
            key (TEncodable): The key of the string.
            start (int): The starting offset.
            end (int): The ending offset.

        Commands response:
            bytes: A substring extracted from the value stored at `key`.
        """
        return self.append_command(RequestType.GetRange, [key, str(start), str(end)])

    def set(
        self: TTransaction,
        key: TEncodable,
        value: TEncodable,
        conditional_set: Union[ConditionalChange, None] = None,
        expiry: Union[ExpirySet, None] = None,
        return_old_value: bool = False,
    ) -> TTransaction:
        """
        Set the given key with the given value. Return value is dependent on the passed options.

        See [valkey.io](https://valkey.io/commands/set/) for details.

        Args:
            key (TEncodable): the key to store.
            value (TEncodable): the value to store with the given key.
            conditional_set (Optional[ConditionalChange], optional): set the key only if the given condition is met.
                Equivalent to [`XX` | `NX`] in the Valkey API. Defaults to None.
            expiry (Optional[ExpirySet], optional): set expiriation to the given key.
                Equivalent to [`EX` | `PX` | `EXAT` | `PXAT` | `KEEPTTL`] in the Valkey API. Defaults to None.
            return_old_value (bool, optional): Return the old value stored at key, or None if key did not exist.
                An error is returned and SET aborted if the value stored at key is not a string.
                Equivalent to `GET` in the Valkey API. Defaults to False.

        Command response:
            Optional[bytes]:
                If the value is successfully set, return OK.

                If value isn't set because of only_if_exists or only_if_does_not_exist conditions, return None.

                If return_old_value is set, return the old value as a bytes string.

        Example:
            Set "foo" to "bar" only if "foo" already exists, and set the key expiration to 5 seconds:

            >>> connection.set("foo", "bar", conditional_set=ConditionalChange.ONLY_IF_EXISTS,
            ... expiry=Expiry(ExpiryType.SEC, 5))
        """
        args = [key, value]
        if conditional_set:
            if conditional_set == ConditionalChange.ONLY_IF_EXISTS:
                args.append("XX")
            if conditional_set == ConditionalChange.ONLY_IF_DOES_NOT_EXIST:
                args.append("NX")
        if return_old_value:
            args.append("GET")
        if expiry is not None:
            args.extend(expiry.get_cmd_args())
        return self.append_command(RequestType.Set, args)

    def strlen(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Get the length of the string value stored at `key`.

        See [valkey.io](https://valkey.io/commands/strlen/) for more details.

        Args:
            key (TEncodable): The key to return its length.

        Commands response:
            int: The length of the string value stored at `key`.

            If `key` does not exist, it is treated as an empty string and 0 is returned.
        """
        return self.append_command(RequestType.Strlen, [key])

    def rename(
        self: TTransaction, key: TEncodable, new_key: TEncodable
    ) -> TTransaction:
        """
        Renames `key` to `new_key`.
        If `newkey` already exists it is overwritten.

        Note:
            In Cluster mode, both `key` and `newkey` must be in the same hash slot,
            meaning that in practice only keys that have the same hash tag can be reliably renamed in cluster.

        See [valkey.io](https://valkey.io/commands/rename/) for more details.

        Args:
            key (TEncodable) : The key to rename.
            new_key (TEncodable) : The new name of the key.

        Command response:
            OK: If the `key` was successfully renamed, return "OK".

            If `key` does not exist, the transaction fails with an error.
        """
        return self.append_command(RequestType.Rename, [key, new_key])

    def renamenx(
        self: TTransaction, key: TEncodable, new_key: TEncodable
    ) -> TTransaction:
        """
        Renames `key` to `new_key` if `new_key` does not yet exist.

        See [valkey.io](https://valkey.io/commands/renamenx) for more details.

        Args:
            key (TEncodable): The key to rename.
            new_key (TEncodable): The new key name.

        Command response:
            bool: True if `key` was renamed to `new_key`.

            False if `new_key` already exists.
        """
        return self.append_command(RequestType.RenameNX, [key, new_key])

    def custom_command(
        self: TTransaction, command_args: List[TEncodable]
    ) -> TTransaction:
        """
        Executes a single command, without checking inputs.

        See the Valkey GLIDE Wiki
        [custom command](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command)
        for details on the restrictions and limitations of the custom command API.

        Args:
            command_args (List[TEncodable]): List of command arguments.
                Every part of the command, including the command name and subcommands, should be added as a
                separate value in args.

        Command response:
            TResult: The returning value depends on the executed command.

        Example:
            Append a command to list of all pub/sub clients:

            >>> transaction.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"])
        """
        return self.append_command(RequestType.CustomCommand, command_args)

    def append(self: TTransaction, key: TEncodable, value: TEncodable) -> TTransaction:
        """
        Appends a value to a key.
        If `key` does not exist it is created and set as an empty string, so `APPEND` will be similar to
        SET in this special case.

        See [valkey.io](https://valkey.io/commands/append) for more details.

        Args:
            key (TEncodable): The key to which the value will be appended.
            value (TEncodable): The value to append.

        Commands response:
            int: The length of the string after appending the value.
        """
        return self.append_command(RequestType.Append, [key, value])

    def info(
        self: TTransaction,
        sections: Optional[List[InfoSection]] = None,
    ) -> TTransaction:
        """
        Get information and statistics about the server.

        See [valkey.io](https://valkey.io/commands/info/) for details.

        Args:
            sections (Optional[List[InfoSection]]): A list of InfoSection values specifying which sections of
                information to retrieve. When no parameter is provided, the default option is assumed.

        Command response:
            bytes: Returns a bytes string containing the information for the sections requested.
        """
        args: List[TEncodable] = (
            [section.value for section in sections] if sections else []
        )
        return self.append_command(RequestType.Info, args)

    def delete(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Delete one or more keys from the database. A key is ignored if it does not exist.

        See [valkey.io](https://valkey.io/commands/del/) for details.

        Args:
            keys (List[TEncodable]): A list of keys to be deleted from the database.

        Command response:
            int: The number of keys that were deleted.
        """
        return self.append_command(RequestType.Del, keys)

    def config_get(self: TTransaction, parameters: List[TEncodable]) -> TTransaction:
        """
        Get the values of configuration parameters.
        Starting from server version 7, command supports multiple parameters.

        See [valkey.io](https://valkey.io/commands/config-get/) for details.

        Args:
            parameters (List[TEncodable]): A list of configuration parameter names to retrieve values for.

        Command response:
            Dict[bytes, bytes]: A dictionary of values corresponding to the configuration parameters.
        """
        return self.append_command(RequestType.ConfigGet, parameters)

    def config_set(
        self: TTransaction,
        parameters_map: Mapping[TEncodable, TEncodable],
    ) -> TTransaction:
        """
        Set configuration parameters to the specified values.
        Starting from server version 7, command supports multiple parameters.

        See [valkey.io](https://valkey.io/commands/config-set/) for details.

        Args:
            parameters_map (Mapping[TEncodable, TEncodable]): A map consisting of configuration
            parameters and their respective values to set.

        Command response:
            OK: Returns OK if all configurations have been successfully set.

            Otherwise, the transaction fails with an error.
        """
        parameters: List[TEncodable] = []
        for pair in parameters_map.items():
            parameters.extend(pair)
        return self.append_command(RequestType.ConfigSet, parameters)

    def config_resetstat(self: TTransaction) -> TTransaction:
        """
        Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM commands.

        See [valkey.io](https://valkey.io/commands/config-resetstat/) for details.

        Command response:
            OK: a simple OK response.
        """
        return self.append_command(RequestType.ConfigResetStat, [])

    def mset(
        self: TTransaction, key_value_map: Mapping[TEncodable, TEncodable]
    ) -> TTransaction:
        """
        Set multiple keys to multiple values in a single atomic operation.

        See [valkey.io](https://valkey.io/commands/mset/) for more details.

        Args:
            parameters (Mapping[TEncodable, TEncodable]): A map of key value pairs.

        Command response:
            OK: a simple OK response.
        """
        parameters: List[TEncodable] = []
        for pair in key_value_map.items():
            parameters.extend(pair)
        return self.append_command(RequestType.MSet, parameters)

    def msetnx(
        self: TTransaction, key_value_map: Mapping[TEncodable, TEncodable]
    ) -> TTransaction:
        """
        Sets multiple keys to values if the key does not exist. The operation is atomic, and if one or
        more keys already exist, the entire operation fails.

        See [valkey.io](https://valkey.io/commands/msetnx/) for more details.

        Args:
            key_value_map (Mapping[TEncodable, TEncodable]): A key-value map consisting of keys and their respective
                values to set.

        Commands response:
            bool: True if all keys were set.

            False if no key was set.
        """
        parameters: List[TEncodable] = []
        for pair in key_value_map.items():
            parameters.extend(pair)
        return self.append_command(RequestType.MSetNX, parameters)

    def mget(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Retrieve the values of multiple keys.

        See [valkey.io](https://valkey.io/commands/mget/) for more details.

        Args:
            keys (List[TEncodable]): A list of keys to retrieve values for.

        Command response:
            List[Optional[bytes]]: A list of values corresponding to the provided keys. If a key is not found,
            its corresponding value in the list will be None.
        """
        return self.append_command(RequestType.MGet, keys)

    def touch(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Updates the last access time of specified keys.

        See [valkey.io](https://valkey.io/commands/touch/) for details.

        Args:
            keys (List[TEncodable]): The keys to update last access time.

        Commands response:
            int: The number of keys that were updated, a key is ignored if it doesn't exist.
        """
        return self.append_command(RequestType.Touch, keys)

    def config_rewrite(self: TTransaction) -> TTransaction:
        """
        Rewrite the configuration file with the current configuration.

        See [valkey.io](https://valkey.io/commands/config-rewrite/) for details.

        Command response:
            OK: OK is returned when the configuration was rewritten properly.

            Otherwise, the transaction fails with an error.
        """
        return self.append_command(RequestType.ConfigRewrite, [])

    def client_id(self: TTransaction) -> TTransaction:
        """
        Returns the current connection id.

        See [valkey.io](https://valkey.io/commands/client-id/) for more information.

        Command response:
            int: the id of the client.
        """
        return self.append_command(RequestType.ClientId, [])

    def incr(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Increments the number stored at `key` by one.
        If `key` does not exist, it is set to 0 before performing the
        operation.

        See [valkey.io](https://valkey.io/commands/incr/) for more details.

        Args:
            key (TEncodable): The key to increment its value.

        Command response:
            int: the value of `key` after the increment.
        """
        return self.append_command(RequestType.Incr, [key])

    def incrby(self: TTransaction, key: TEncodable, amount: int) -> TTransaction:
        """
        Increments the number stored at `key` by `amount`. If the key does not exist, it is set to 0 before performing
        the operation.

        See [valkey.io](https://valkey.io/commands/incrby/) for more details.

        Args:
          key (TEncodable): The key to increment its value.
          amount (int) : The amount to increment.

        Command response:
            int: The value of `key` after the increment.
        """
        return self.append_command(RequestType.IncrBy, [key, str(amount)])

    def incrbyfloat(self: TTransaction, key: TEncodable, amount: float) -> TTransaction:
        """
        Increment the string representing a floating point number stored at `key` by `amount`.
        By using a negative increment value, the value stored at the `key` is decremented.
        If the key does not exist, it is set to 0 before performing the operation.

        See [valkey.io](https://valkey.io/commands/incrbyfloat/) for more details.

        Args:
          key (TEncodable): The key to increment its value.
          amount (float) : The amount to increment.

        Command response:
            float: The value of key after the increment.
        """
        return self.append_command(RequestType.IncrByFloat, [key, str(amount)])

    def ping(self: TTransaction, message: Optional[TEncodable] = None) -> TTransaction:
        """
        Ping the server.

        See [valkey.io](https://valkey.io/commands/ping/) for more details.

        Args:
            message (Optional[TEncodable]): An optional message to include in the PING command. If not provided,
            the server will respond with "PONG". If provided, the server will respond with a copy of the message.

        Command response:
           bytes: b"PONG" if `message` is not provided, otherwise return a copy of `message`.
        """
        argument = [] if message is None else [message]
        return self.append_command(RequestType.Ping, argument)

    def decr(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Decrements the number stored at `key` by one. If the key does not exist, it is set to 0 before performing the
        operation.

        See [valkey.io](https://valkey.io/commands/decr/) for more details.

        Args:
            key (TEncodable): The key to decrement its value.

        Command response:
            int: the value of `key` after the decrement.
        """
        return self.append_command(RequestType.Decr, [key])

    def decrby(self: TTransaction, key: TEncodable, amount: int) -> TTransaction:
        """
        Decrements the number stored at `key` by `amount`. If the key does not exist, it is set to 0 before performing
        the operation.

        See [valkey.io](https://valkey.io/commands/decrby/) for more details.

        Args:
            key (TEncodable): The key to decrement its value.
            amount (int) : The amount to decrement.

        Command response:
            int: The value of `key` after the decrement.
        """
        return self.append_command(RequestType.DecrBy, [key, str(amount)])

    def setrange(
        self: TTransaction,
        key: TEncodable,
        offset: int,
        value: TEncodable,
    ) -> TTransaction:
        """
        Overwrites part of the string stored at `key`, starting at the specified
        `offset`, for the entire length of `value`.
        If the `offset` is larger than the current length of the string at `key`,
        the string is padded with zero bytes to make `offset` fit. Creates the `key`
        if it doesn't exist.

        See [valkey.io](https://valkey.io/commands/setrange) for more details.

        Args:
            key (TEncodable): The key of the string to update.
            offset (int): The position in the string where `value` should be written.
            value (TEncodable): The value written with `offset`.

        Command response:
            int: The length of the value stored at `key` after it was modified.
        """
        return self.append_command(RequestType.SetRange, [key, str(offset), value])

    def hset(
        self: TTransaction,
        key: TEncodable,
        field_value_map: Mapping[TEncodable, TEncodable],
    ) -> TTransaction:
        """
        Sets the specified fields to their respective values in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hset/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            field_value_map (Mapping[TEncodable, TEncodable]): A field-value map consisting of fields and their
                corresponding values to be set in the hash stored at the specified key.

        Command response:
            int: The number of fields that were added to the hash.
        """
        field_value_list: List[TEncodable] = [key]
        for pair in field_value_map.items():
            field_value_list.extend(pair)
        return self.append_command(RequestType.HSet, field_value_list)

    def hget(self: TTransaction, key: TEncodable, field: TEncodable) -> TTransaction:
        """
        Retrieves the value associated with `field` in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hget/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            field (TEncodable): The field whose value should be retrieved.

        Command response:
            Optional[bytes]: The value associated `field` in the hash.

            Returns None if `field` is not presented in the hash or `key` does not exist.
        """
        return self.append_command(RequestType.HGet, [key, field])

    def hsetnx(
        self: TTransaction,
        key: TEncodable,
        field: TEncodable,
        value: TEncodable,
    ) -> TTransaction:
        """
        Sets `field` in the hash stored at `key` to `value`, only if `field` does not yet exist.
        If `key` does not exist, a new key holding a hash is created.
        If `field` already exists, this operation has no effect.

        See [valkey.io](https://valkey.io/commands/hsetnx/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            field (TEncodable): The field to set the value for.
            value (TEncodable): The value to set.

        Commands response:
            bool: True if the field was set.

            False if the field already existed and was not set.
        """
        return self.append_command(RequestType.HSetNX, [key, field, value])

    def hincrby(
        self: TTransaction,
        key: TEncodable,
        field: TEncodable,
        amount: int,
    ) -> TTransaction:
        """
        Increment or decrement the value of a `field` in the hash stored at `key` by the specified amount.
        By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented.
        If `field` or `key` does not exist, it is set to 0 before performing the operation.

        See [valkey.io](https://valkey.io/commands/hincrby/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            field (TEncodable): The field in the hash stored at `key` to increment or decrement its value.
            amount (int): The amount by which to increment or decrement the field's value.
                Use a negative value to decrement.

        Command response:
            int: The value of the specified field in the hash stored at `key` after the increment or decrement.
        """
        return self.append_command(RequestType.HIncrBy, [key, field, str(amount)])

    def hincrbyfloat(
        self: TTransaction,
        key: TEncodable,
        field: TEncodable,
        amount: float,
    ) -> TTransaction:
        """
        Increment or decrement the floating-point value stored at `field` in the hash stored at `key` by the specified
        amount.
        By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented.
        If `field` or `key` does not exist, it is set to 0 before performing the operation.

        See [valkey.io](https://valkey.io/commands/hincrbyfloat/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            field (TEncodable): The field in the hash stored at `key` to increment or decrement its value.
            amount (float): The amount by which to increment or decrement the field's value.
                Use a negative value to decrement.

        Command response:
            float: The value of the specified field in the hash stored at `key` after the increment as a string.
        """
        return self.append_command(RequestType.HIncrByFloat, [key, field, str(amount)])

    def hexists(self: TTransaction, key: TEncodable, field: TEncodable) -> TTransaction:
        """
        Check if a field exists in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hexists/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            field (TEncodable): The field to check in the hash stored at `key`.

        Command response:
            bool: Returns `True` if the hash contains the specified field. If the hash does not contain the field,

            Returns `False` if the key does not exist.
        """
        return self.append_command(RequestType.HExists, [key, field])

    def hlen(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the number of fields contained in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hlen/) for more details.

        Args:
            key (TEncodable): The key of the hash.

        Command response:
            int: The number of fields in the hash, or 0 when the key does not exist.

            If `key` holds a value that is not a hash, the transaction fails with an error.
        """
        return self.append_command(RequestType.HLen, [key])

    def client_getname(self: TTransaction) -> TTransaction:
        """
        Get the name of the connection on which the transaction is being executed.

        See [valkey.io](https://valkey.io/commands/client-getname/) for more details.

        Command response:
            Optional[bytes]: Returns the name of the client connection as a bytes string if a name is set,

            Returns `None` if no name is assigned.
        """
        return self.append_command(RequestType.ClientGetName, [])

    def hgetall(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns all fields and values of the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hgetall/) for details.

        Args:
            key (TEncodable): The key of the hash.

        Command response:
            Dict[bytes, bytes]: A dictionary of fields and their values stored in the hash. Every field name in the
            list is followed by its value.

            If `key` does not exist, it returns an empty dictionary.
        """
        return self.append_command(RequestType.HGetAll, [key])

    def hmget(
        self: TTransaction, key: TEncodable, fields: List[TEncodable]
    ) -> TTransaction:
        """
        Retrieve the values associated with specified fields in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hmget/) for details.

        Args:
            key (TEncodable): The key of the hash.
            fields (List[TEncodable]): The list of fields in the hash stored at `key` to retrieve from the database.

        Returns:
            List[Optional[bytes]]: A list of values associated with the given fields, in the same order as they are requested.
            For every field that does not exist in the hash, a null value is returned.

            If `key` does not exist, it is treated as an empty hash, and the function returns a list of null values.
        """
        return self.append_command(RequestType.HMGet, [key] + fields)

    def hdel(
        self: TTransaction, key: TEncodable, fields: List[TEncodable]
    ) -> TTransaction:
        """
        Remove specified fields from the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hdel/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            fields (List[TEncodable]): The list of fields to remove from the hash stored at `key`.

        Returns:
            int: The number of fields that were removed from the hash, excluding specified but non-existing fields.

            If `key` does not exist, it is treated as an empty hash, and the function returns 0.
        """
        return self.append_command(RequestType.HDel, [key] + fields)

    def hvals(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns all values in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hvals/) for more details.

        Args:
            key (TEncodable): The key of the hash.

        Command response:
            List[bytes]: A list of values in the hash.

            An empty list when the key does not exist.
        """
        return self.append_command(RequestType.HVals, [key])

    def hkeys(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns all field names in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hkeys/) for more details.

        Args:
            key (TEncodable): The key of the hash.

        Command response:
            List[bytes]: A list of field names for the hash.

            An empty list when the key does not exist.
        """
        return self.append_command(RequestType.HKeys, [key])

    def hrandfield(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns a random field name from the hash value stored at `key`.

        See [valkey.io](https://valkey.io/commands/hrandfield) for more details.

        Args:
            key (TEncodable): The key of the hash.

        Command response:
            Optional[bytes]: A random field name from the hash stored at `key`.

            If the hash does not exist or is empty, None will be returned.
        """
        return self.append_command(RequestType.HRandField, [key])

    def hrandfield_count(
        self: TTransaction, key: TEncodable, count: int
    ) -> TTransaction:
        """
        Retrieves up to `count` random field names from the hash value stored at `key`.

        See [valkey.io](https://valkey.io/commands/hrandfield) for more details.

        Args:
            key (TEncodable): The key of the hash.
            count (int): The number of field names to return.

                - If `count` is positive, returns unique elements.
                - If `count` is negative, allows for duplicates elements.

        Command response:
            List[bytes]: A list of random field names from the hash.

            If the hash does not exist or is empty, the response will be an empty list.
        """
        return self.append_command(RequestType.HRandField, [key, str(count)])

    def hrandfield_withvalues(
        self: TTransaction, key: TEncodable, count: int
    ) -> TTransaction:
        """
        Retrieves up to `count` random field names along with their values from the hash value stored at `key`.

        See [valkey.io](https://valkey.io/commands/hrandfield) for more details.

        Args:
            key (TEncodable): The key of the hash.
            count (int): The number of field names to return.

                - If `count` is positive, returns unique elements.
                - If `count` is negative, allows for duplicates elements.

        Command response:
            List[List[bytes]]: A list of `[field_name, value]` lists, where `field_name` is a random field name from the
            hash and `value` is the associated value of the field name.

            If the hash does not exist or is empty, the response will be an empty list.
        """
        return self.append_command(
            RequestType.HRandField, [key, str(count), "WITHVALUES"]
        )

    def hstrlen(self: TTransaction, key: TEncodable, field: TEncodable) -> TTransaction:
        """
        Returns the string length of the value associated with `field` in the hash stored at `key`.

        See [valkey.io](https://valkey.io/commands/hstrlen/) for more details.

        Args:
            key (TEncodable): The key of the hash.
            field (TEncodable): The field in the hash.

        Commands response:
            int: The string length.

            Returns `0` if `field` or `key` does not exist.
        """
        return self.append_command(RequestType.HStrlen, [key, field])

    def lpush(
        self: TTransaction, key: TEncodable, elements: List[TEncodable]
    ) -> TTransaction:
        """
        Insert all the specified values at the head of the list stored at `key`.
        `elements` are inserted one after the other to the head of the list, from the leftmost element
        to the rightmost element. If `key` does not exist, it is created as empty list before performing the push operations.

        See [valkey.io](https://valkey.io/commands/lpush/) for more details.

        Args:
            key (TEncodable): The key of the list.
            elements (List[TEncodable]): The elements to insert at the head of the list stored at `key`.

        Command response:
            int: The length of the list after the push operations.
        """
        return self.append_command(RequestType.LPush, [key] + elements)

    def lpushx(
        self: TTransaction, key: TEncodable, elements: List[TEncodable]
    ) -> TTransaction:
        """
        Inserts all the specified values at the head of the list stored at `key`, only if `key` exists and holds a list.
        If `key` is not a list, this performs no operation.

        See [valkey.io](https://valkey.io/commands/lpushx/) for more details.

        Args:
            key (TEncodable): The key of the list.
            elements (List[TEncodable]): The elements to insert at the head of the list stored at `key`.

        Command response:
            int: The length of the list after the push operation.
        """
        return self.append_command(RequestType.LPushX, [key] + elements)

    def lpop(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Remove and return the first elements of the list stored at `key`.
        The command pops a single element from the beginning of the list.

        See [valkey.io](https://valkey.io/commands/lpop/) for details.

        Args:
            key (TEncodable): The key of the list.

        Command response:
            Optional[bytes]: The value of the first element.

            If `key` does not exist, None will be returned.
        """
        return self.append_command(RequestType.LPop, [key])

    def lpop_count(self: TTransaction, key: TEncodable, count: int) -> TTransaction:
        """
        Remove and return up to `count` elements from the list stored at `key`, depending on the list's length.

        See [valkey.io](https://valkey.io/commands/lpop/) for details.

        Args:
            key (TEncodable): The key of the list.
            count (int): The count of elements to pop from the list.

        Command response:
            Optional[List[bytes]]: A a list of popped elements will be returned depending on the list's length.

            If `key` does not exist, None will be returned.
        """
        return self.append_command(RequestType.LPop, [key, str(count)])

    def blpop(
        self: TTransaction, keys: List[TEncodable], timeout: float
    ) -> TTransaction:
        """
        Pops an element from the head of the first list that is non-empty, with the given keys being checked in the
        order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.

        See [valkey.io](https://valkey.io/commands/blpop) for details.

        Note:
            BLPOP is a client blocking command, see
            [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
            for more details and best practices.

        Args:
            keys (List[TEncodable]): The keys of the lists to pop from.
            timeout (float): The number of seconds to wait for a blocking operation to complete.
                A value of 0 will block indefinitely.

        Command response:
            Optional[List[bytes]]: A two-element list containing the key from which the element was popped and the value of the
            popped element, formatted as `[key, value]`.

            If no element could be popped and the `timeout` expired, returns None.
        """
        return self.append_command(RequestType.BLPop, keys + [str(timeout)])

    def lmpop(
        self: TTransaction,
        keys: List[TEncodable],
        direction: ListDirection,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Pops one or more elements from the first non-empty list from the provided `keys`.

        See [valkey.io](https://valkey.io/commands/lmpop/) for details.

        Args:
            keys (List[TEncodable]): An array of keys of lists.
            direction (ListDirection): The direction based on which elements are popped from
                (`ListDirection.LEFT` or `ListDirection.RIGHT`).
            count (Optional[int]): The maximum number of popped elements. If not provided,
                defaults to popping a single element.

        Command response:
            Optional[Mapping[bytes, List[bytes]]]: A map of `key` name mapped to an array of popped elements.

            None if no elements could be popped.

        Since: Valkey version 7.0.0.
        """
        args = [str(len(keys)), *keys, direction.value]
        if count is not None:
            args += ["COUNT", str(count)]

        return self.append_command(RequestType.LMPop, args)

    def blmpop(
        self: TTransaction,
        keys: List[TEncodable],
        direction: ListDirection,
        timeout: float,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Blocks the connection until it pops one or more elements from the first non-empty list from the provided `keys`.

        `BLMPOP` is the blocking variant of `LMPOP`.

        See [valkey.io](https://valkey.io/commands/blmpop/) for details.

        Args:
            keys (List[TEncodable]): An array of keys of lists.
            direction (ListDirection): The direction based on which elements are popped from
                (`ListDirection.LEFT` or `ListDirection.RIGHT`).
            timeout (float): The number of seconds to wait for a blocking operation to complete.
                A value of `0` will block indefinitely.
            count (Optional[int]): The maximum number of popped elements. If not provided,
                defaults to popping a single element.

        Command response:
            Optional[Mapping[bytes, List[bytes]]]: A map of `key` name mapped to an array of popped elements.

            None if no elements could be popped and the timeout expired.

        Since: Valkey version 7.0.0.
        """
        args = [str(timeout), str(len(keys)), *keys, direction.value]
        if count is not None:
            args += ["COUNT", str(count)]

        return self.append_command(RequestType.BLMPop, args)

    def lrange(
        self: TTransaction, key: TEncodable, start: int, end: int
    ) -> TTransaction:
        """
        Retrieve the specified elements of the list stored at `key` within the given range.
        The offsets `start` and `end` are zero-based indexes, with 0 being the first element of the list, 1 being the next
        element and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list,
        with -1 being the last element of the list, -2 being the penultimate, and so on.

        See [valkey.io](https://valkey.io/commands/lrange/) for details.

        Args:
            key (TEncodable): The key of the list.
            start (int): The starting point of the range.
            end (int): The end of the range.

        Command response:
            List[byte]: A list of elements within the specified range.

            If `start` exceeds the `end` of the list, or if `start` is greater than `end`, an empty list will be returned.

            If `end` exceeds the actual end of the list, the range will stop at the actual end of the list.

            If `key` does not exist an empty list will be returned.
        """
        return self.append_command(RequestType.LRange, [key, str(start), str(end)])

    def lindex(
        self: TTransaction,
        key: TEncodable,
        index: int,
    ) -> TTransaction:
        """
        Returns the element at `index` in the list stored at `key`.

        The index is zero-based, so 0 means the first element, 1 the second element and so on.
        Negative indices can be used to designate elements starting at the tail of the list.
        Here, -1 means the last element, -2 means the penultimate and so forth.

        See [valkey.io](https://valkey.io/commands/lindex/) for more details.

        Args:
            key (TEncodable): The key of the list.
            index (int): The index of the element in the list to retrieve.

        Command response:
            Optional[bytes]: The element at `index` in the list stored at `key`.

            If `index` is out of range or if `key` does not exist, None is returned.
        """
        return self.append_command(RequestType.LIndex, [key, str(index)])

    def lset(
        self: TTransaction,
        key: TEncodable,
        index: int,
        element: TEncodable,
    ) -> TTransaction:
        """
        Sets the list element at `index` to `element`.

        The index is zero-based, so `0` means the first element, `1` the second element and so on.
        Negative indices can be used to designate elements starting at the tail of the list.
        Here, `-1` means the last element, `-2` means the penultimate and so forth.

        See [valkey.io](https://valkey.io/commands/lset/) for details.

        Args:
            key (TEncodable): The key of the list.
            index (int): The index of the element in the list to be set.
            element (TEncodable): The new element to set at the specified index.

        Commands response:
            TOK: A simple `OK` response.
        """
        return self.append_command(RequestType.LSet, [key, str(index), element])

    def rpush(
        self: TTransaction, key: TEncodable, elements: List[TEncodable]
    ) -> TTransaction:
        """
        Inserts all the specified values at the tail of the list stored at `key`.
        `elements` are inserted one after the other to the tail of the list, from the leftmost element
        to the rightmost element. If `key` does not exist, it is created as empty list before performing the push operations.

        See [valkey.io](https://valkey.io/commands/rpush/) for more details.

        Args:
            key (TEncodable): The key of the list.
            elements (List[TEncodable]): The elements to insert at the tail of the list stored at `key`.

        Command response:
            int: The length of the list after the push operations.

            If `key` holds a value that is not a list, the transaction fails.
        """
        return self.append_command(RequestType.RPush, [key] + elements)

    def rpushx(
        self: TTransaction, key: TEncodable, elements: List[TEncodable]
    ) -> TTransaction:
        """
        Inserts all the specified values at the tail of the list stored at `key`, only if `key` exists and holds a list.
        If `key` is not a list, this performs no operation.

        See [valkey.io](https://valkey.io/commands/rpushx/) for more details.

        Args:
            key (TEncodable): The key of the list.
            elements (List[TEncodable]): The elements to insert at the tail of the list stored at `key`.

        Command response:
            int: The length of the list after the push operation.
        """
        return self.append_command(RequestType.RPushX, [key] + elements)

    def rpop(
        self: TTransaction, key: TEncodable, count: Optional[int] = None
    ) -> TTransaction:
        """
        Removes and returns the last elements of the list stored at `key`.
        The command pops a single element from the end of the list.

        See [valkey.io](https://valkey.io/commands/rpop/) for details.

        Args:
            key (TEncodable): The key of the list.

        Commands response:
            Optional[bytes]: The value of the last element.

            If `key` does not exist, None will be returned.
        """
        return self.append_command(RequestType.RPop, [key])

    def rpop_count(self: TTransaction, key: TEncodable, count: int) -> TTransaction:
        """
        Removes and returns up to `count` elements from the list stored at `key`, depending on the list's length.

        See [valkey.io](https://valkey.io/commands/rpop/) for details.

        Args:
            key (TEncodable): The key of the list.
            count (int): The count of elements to pop from the list.

        Commands response:
            Optional[List[bytes]: A list of popped elements will be returned depending on the list's length.

            If `key` does not exist, None will be returned.
        """
        return self.append_command(RequestType.RPop, [key, str(count)])

    def brpop(
        self: TTransaction, keys: List[TEncodable], timeout: float
    ) -> TTransaction:
        """
        Pops an element from the tail of the first list that is non-empty, with the given keys being checked in the
        order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.

        See [valkey.io](https://valkey.io/commands/brpop) for details.

        Note:
            BRPOP is a client blocking command, see
            [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
            for more details and best practices.

        Args:
            keys (List[TEncodable]): The keys of the lists to pop from.
            timeout (float): The number of seconds to wait for a blocking operation to complete.
                A value of 0 will block indefinitely.

        Command response:
            Optional[List[bytes]]: A two-element list containing the key from which the element was popped and the value of the
            popped element, formatted as `[key, value]`.

            If no element could be popped and the `timeout` expired, returns None.
        """
        return self.append_command(RequestType.BRPop, keys + [str(timeout)])

    def linsert(
        self: TTransaction,
        key: TEncodable,
        position: InsertPosition,
        pivot: TEncodable,
        element: TEncodable,
    ) -> TTransaction:
        """
        Inserts `element` in the list at `key` either before or after the `pivot`.

        See [valkey.io](https://valkey.io/commands/linsert/) for details.

        Args:
            key (TEncodable): The key of the list.
            position (InsertPosition): The relative position to insert into - either `InsertPosition.BEFORE` or
                `InsertPosition.AFTER` the `pivot`.
            pivot (TEncodable): An element of the list.
            element (TEncodable): The new element to insert.

        Command response:
            int: The list length after a successful insert operation.

            If the `key` doesn't exist returns `-1`.

            If the `pivot` wasn't found, returns `0`.
        """
        return self.append_command(
            RequestType.LInsert, [key, position.value, pivot, element]
        )

    def lmove(
        self: TTransaction,
        source: TEncodable,
        destination: TEncodable,
        where_from: ListDirection,
        where_to: ListDirection,
    ) -> TTransaction:
        """
        Atomically pops and removes the left/right-most element to the list stored at `source`
        depending on `where_from`, and pushes the element at the first/last element of the list
        stored at `destination` depending on `where_to`.

        See [valkey.io](https://valkey.io/commands/lmove/) for details.

        Args:
            source (TEncodable): The key to the source list.
            destination (TEncodable): The key to the destination list.
            where_from (ListDirection): The direction to remove the element from
                (`ListDirection.LEFT` or `ListDirection.RIGHT`).
            where_to (ListDirection): The direction to add the element to
                (`ListDirection.LEFT` or `ListDirection.RIGHT`).

        Command response:
            Optional[bytes]: The popped element.

            `None` if `source` does not exist.

        Since: Valkey version 6.2.0.
        """
        return self.append_command(
            RequestType.LMove, [source, destination, where_from.value, where_to.value]
        )

    def blmove(
        self: TTransaction,
        source: TEncodable,
        destination: TEncodable,
        where_from: ListDirection,
        where_to: ListDirection,
        timeout: float,
    ) -> TTransaction:
        """
        Blocks the connection until it pops atomically and removes the left/right-most element to the
        list stored at `source` depending on `where_from`, and pushes the element at the first/last element
        of the list stored at `destination` depending on `where_to`.
        `blmove` is the blocking variant of `lmove`.

        See [valkey.io](https://valkey.io/commands/blmove/) for details.

        Args:
            source (TEncodable): The key to the source list.
            destination (TEncodable): The key to the destination list.
            where_from (ListDirection): The direction to remove the element from
                (`ListDirection.LEFT` or `ListDirection.RIGHT`).
            where_to (ListDirection): The direction to add the element to
                (`ListDirection.LEFT` or `ListDirection.RIGHT`).
            timeout (float): The number of seconds to wait for a blocking operation to complete.
                A value of `0` will block indefinitely.

        Command response:
            Optional[bytes]: The popped element.

            `None` if `source` does not exist or if the operation timed-out.

        Since: Valkey version 6.2.0.
        """
        return self.append_command(
            RequestType.BLMove,
            [source, destination, where_from.value, where_to.value, str(timeout)],
        )

    def sadd(
        self: TTransaction, key: TEncodable, members: List[TEncodable]
    ) -> TTransaction:
        """
        Add specified members to the set stored at `key`.
        Specified members that are already a member of this set are ignored.
        If `key` does not exist, a new set is created before adding `members`.

        See [valkey.io](https://valkey.io/commands/sadd/) for more details.

        Args:
            key (TEncodable): The key where members will be added to its set.
            members (List[TEncodable]): A list of members to add to the set stored at key.

        Command response:
            int: The number of members that were added to the set, excluding members already present.
        """
        return self.append_command(RequestType.SAdd, [key] + members)

    def srem(
        self: TTransaction, key: TEncodable, members: List[TEncodable]
    ) -> TTransaction:
        """
        Remove specified members from the set stored at `key`.
        Specified members that are not a member of this set are ignored.

        See [valkey.io](https://valkey.io/commands/srem/) for details.

        Args:
            key (TEncodable): The key from which members will be removed.
            members (List[TEncodable]): A list of members to remove from the set stored at key.

        Commands response:
            int: The number of members that were removed from the set, excluding non-existing members.

            If `key` does not exist, it is treated as an empty set and this command returns 0.
        """
        return self.append_command(RequestType.SRem, [key] + members)

    def smembers(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Retrieve all the members of the set value stored at `key`.

        See [valkey.io](https://valkey.io/commands/smembers/) for details.

        Args:
            key (TEncodable): The key from which to retrieve the set members.

        Commands response:
            Set[bytes]: A set of all members of the set.

            If `key` does not exist an empty list will be returned.
        """
        return self.append_command(RequestType.SMembers, [key])

    def scard(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Retrieve the set cardinality (number of elements) of the set stored at `key`.

        See [valkey.io](https://valkey.io/commands/scard/) for details.

        Args:
            key (TEncodable): The key from which to retrieve the number of set members.

        Commands response:
            int: The cardinality (number of elements) of the set.

            Returns `0` if the key does not exist.
        """
        return self.append_command(RequestType.SCard, [key])

    def spop(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Removes and returns one random member from the set stored at `key`.

        See [valkey.io](https://valkey-io.github.io/commands/spop/) for more details.
        To pop multiple members, see `spop_count`.

        Args:
            key (TEncodable): The key of the set.

        Commands response:
            Optional[bytes]: The value of the popped member.

            If `key` does not exist, None will be returned.
        """
        return self.append_command(RequestType.SPop, [key])

    def spop_count(self: TTransaction, key: TEncodable, count: int) -> TTransaction:
        """
        Removes and returns up to `count` random members from the set stored at `key`, depending on the set's length.

        See [valkey.io](https://valkey-io.github.io/commands/spop/) for more details.

        To pop a single member, see `spop`.

        Args:
            key (TEncodable): The key of the set.
            count (int): The count of the elements to pop from the set.

        Commands response:
            Set[bytes]: A set of popped elements will be returned depending on the set's length.

            If `key` does not exist, an empty set will be returned.
        """
        return self.append_command(RequestType.SPop, [key, str(count)])

    def sismember(
        self: TTransaction,
        key: TEncodable,
        member: TEncodable,
    ) -> TTransaction:
        """
        Returns if `member` is a member of the set stored at `key`.

        See [valkey.io](https://valkey.io/commands/sismember/) for more details.

        Args:
            key (TEncodable): The key of the set.
            member (TEncodable): The member to check for existence in the set.

        Commands response:
            bool: True if the member exists in the set, False otherwise.

            If `key` doesn't exist, it is treated as an empty set and the command returns False.
        """
        return self.append_command(RequestType.SIsMember, [key, member])

    def smove(
        self: TTransaction,
        source: TEncodable,
        destination: TEncodable,
        member: TEncodable,
    ) -> TTransaction:
        """
        Moves `member` from the set at `source` to the set at `destination`, removing it from the source set. Creates a
        new destination set if needed. The operation is atomic.

        See [valkey.io](https://valkey.io/commands/smove) for more details.

        Args:
            source (TEncodable): The key of the set to remove the element from.
            destination (TEncodable): The key of the set to add the element to.
            member (TEncodable): The set element to move.

        Command response:
            bool: True on success.

            False if the `source` set does not exist or the element is not a member of the source set.
        """
        return self.append_command(RequestType.SMove, [source, destination, member])

    def sunion(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Gets the union of all the given sets.

        See [valkey.io](https://valkey.io/commands/sunion) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sets.

        Commands response:
            Set[bytes]: A set of members which are present in at least one of the given sets.

            If none of the sets exist, an empty set will be returned.
        """
        return self.append_command(RequestType.SUnion, keys)

    def sunionstore(
        self: TTransaction,
        destination: TEncodable,
        keys: List[TEncodable],
    ) -> TTransaction:
        """
        Stores the members of the union of all given sets specified by `keys` into a new set at `destination`.

        See [valkey.io](https://valkey.io/commands/sunionstore) for more details.

        Args:
            destination (TEncodable): The key of the destination set.
            keys (List[TEncodable]): The keys from which to retrieve the set members.

        Command response:
            int: The number of elements in the resulting set.
        """
        return self.append_command(RequestType.SUnionStore, [destination] + keys)

    def sinter(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Gets the intersection of all the given sets.

        See [valkey.io](https://valkey.io/commands/sinter) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sets.

        Command response:
            Set[bytes]: A set of members which are present in all given sets.

            If one or more sets do not exist, an empty set will be returned.
        """
        return self.append_command(RequestType.SInter, keys)

    def sinterstore(
        self: TTransaction,
        destination: TEncodable,
        keys: List[TEncodable],
    ) -> TTransaction:
        """
        Stores the members of the intersection of all given sets specified by `keys` into a new set at `destination`.

        See [valkey.io](https://valkey.io/commands/sinterstore) for more details.

        Args:
            destination (TEncodable): The key of the destination set.
            keys (List[TEncodable]): The keys from which to retrieve the set members.

        Command response:
            int: The number of elements in the resulting set.
        """
        return self.append_command(RequestType.SInterStore, [destination] + keys)

    def sintercard(
        self: TTransaction, keys: List[TEncodable], limit: Optional[int] = None
    ) -> TTransaction:
        """
        Gets the cardinality of the intersection of all the given sets.
        Optionally, a `limit` can be specified to stop the computation early if the intersection
        cardinality reaches the specified limit.

        See [valkey.io](https://valkey.io/commands/sintercard) for more details.

        Args:
            keys (List[TEncodable]): A list of keys representing the sets to intersect.
            limit (Optional[int]): An optional limit to the maximum number of intersecting elements to count.
                If specified, the computation stops as soon as the cardinality reaches this limit.

        Command response:
            int: The number of elements in the resulting set of the intersection.
        """
        args: List[TEncodable] = [str(len(keys))]
        args.extend(keys)
        if limit is not None:
            args.extend(["LIMIT", str(limit)])
        return self.append_command(RequestType.SInterCard, args)

    def sdiff(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Computes the difference between the first set and all the successive sets in `keys`.

        See [valkey.io](https://valkey.io/commands/sdiff) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sets to diff.

        Command response:
            Set[bytes]: A set of elements representing the difference between the sets.

            If any of the keys in `keys` do not exist, they are treated as empty sets.
        """
        return self.append_command(RequestType.SDiff, keys)

    def sdiffstore(
        self: TTransaction,
        destination: TEncodable,
        keys: List[TEncodable],
    ) -> TTransaction:
        """
        Stores the difference between the first set and all the successive sets in `keys` into a new set at
        `destination`.

        See [valkey.io](https://valkey.io/commands/sdiffstore) for more details.

        Args:
            destination (TEncodable): The key of the destination set.
            keys (List[TEncodable]): The keys of the sets to diff.

        Command response:
            int: The number of elements in the resulting set.
        """
        return self.append_command(RequestType.SDiffStore, [destination] + keys)

    def smismember(
        self: TTransaction, key: TEncodable, members: List[TEncodable]
    ) -> TTransaction:
        """
        Checks whether each member is contained in the members of the set stored at `key`.

        See [valkey.io](https://valkey.io/commands/smismember) for more details.

        Args:
            key (TEncodable): The key of the set to check.
            members (List[TEncodable]): A list of members to check for existence in the set.

        Command response:
            List[bool]: A list of bool values, each indicating if the respective member exists in the set.
        """
        return self.append_command(RequestType.SMIsMember, [key] + members)

    def ltrim(
        self: TTransaction, key: TEncodable, start: int, end: int
    ) -> TTransaction:
        """
        Trim an existing list so that it will contain only the specified range of elements specified.
        The offsets `start` and `end` are zero-based indexes, with 0 being the first element of the list, 1 being the next
        element and so on.
        These offsets can also be negative numbers indicating offsets starting at the end of the list, with -1 being the last
        element of the list, -2 being the penultimate, and so on.

        See [valkey.io](https://valkey.io/commands/ltrim/) for more details.

        Args:
            key (TEncodable): The key of the list.
            start (int): The starting point of the range.
            end (int): The end of the range.

        Commands response:
            TOK: A simple "OK" response.

            If `start` exceeds the end of the list, or if `start` is greater than `end`, the result will be an empty list
            (which causes `key` to be removed).

            If `end` exceeds the actual end of the list, it will be treated like the last element of the list.

            If `key` does not exist, the response will be "OK" without changes to the database.
        """
        return self.append_command(RequestType.LTrim, [key, str(start), str(end)])

    def lrem(
        self: TTransaction,
        key: TEncodable,
        count: int,
        element: TEncodable,
    ) -> TTransaction:
        """
        Removes the first `count` occurrences of elements equal to `element` from the list stored at `key`.
        If `count` is positive, it removes elements equal to `element` moving from head to tail.
        If `count` is negative, it removes elements equal to `element` moving from tail to head.
        If `count` is 0 or greater than the occurrences of elements equal to `element`, it removes all elements
        equal to `element`.

        See [valkey.io](https://valkey.io/commands/lrem/) for more details.

        Args:
            key (TEncodable): The key of the list.
            count (int): The count of occurrences of elements equal to `element` to remove.
            element (TEncodable): The element to remove from the list.

        Commands response:
            int: The number of removed elements.

            If `key` does not exist, 0 is returned.
        """
        return self.append_command(RequestType.LRem, [key, str(count), element])

    def llen(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Get the length of the list stored at `key`.

        See [valkey.io](https://valkey.io/commands/llen/) for details.

        Args:
            key (TEncodable): The key of the list.

        Commands response:
            int: The length of the list at the specified key.

            If `key` does not exist, it is interpreted as an empty list and 0 is returned.
        """
        return self.append_command(RequestType.LLen, [key])

    def exists(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Returns the number of keys in `keys` that exist in the database.

        See [valkey.io](https://valkey.io/commands/exists/) for more details.

        Args:
            keys (List[TEncodable]): The list of keys to check.

        Commands response:
            int: The number of keys that exist. If the same existing key is mentioned in `keys` multiple times,
            it will be counted multiple times.
        """
        return self.append_command(RequestType.Exists, keys)

    def unlink(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Unlink (delete) multiple keys from the database.
        A key is ignored if it does not exist.
        This command, similar to DEL, removes specified keys and ignores non-existent ones.
        However, this command does not block the server, while `DEL <[valkey.io](https://valkey.io/commands/del>`_) does.

        See [valkey.io](https://valkey.io/commands/unlink/) for more details.

        Args:
            keys (List[TEncodable]): The list of keys to unlink.

        Commands response:
            int: The number of keys that were unlinked.
        """
        return self.append_command(RequestType.Unlink, keys)

    def expire(
        self: TTransaction,
        key: TEncodable,
        seconds: int,
        option: Optional[ExpireOptions] = None,
    ) -> TTransaction:
        """
        Sets a timeout on `key` in seconds. After the timeout has expired, the key will automatically be deleted.
        If `key` already has an existing expire set, the time to live is updated to the new value.
        If `seconds` is a non-positive number, the key will be deleted rather than expired.
        The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

        See [valkey.io](https://valkey.io/commands/expire/) for more details.

        Args:
            key (TEncodable): The key to set a timeout on.
            seconds (int): The timeout in seconds.
            option (Optional[ExpireOptions]): The expire option.

        Commands response:
            bool: `True` if the timeout was set.

            `False` if the timeout was not set (e.g., the key doesn't exist or the
            operation is skipped due to the provided arguments).
        """
        args: List[TEncodable] = (
            [key, str(seconds)] if option is None else [key, str(seconds), option.value]
        )
        return self.append_command(RequestType.Expire, args)

    def expireat(
        self: TTransaction,
        key: TEncodable,
        unix_seconds: int,
        option: Optional[ExpireOptions] = None,
    ) -> TTransaction:
        """
        Sets a timeout on `key` using an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the
        number of seconds.
        A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be
        deleted.
        If `key` already has an existing expire set, the time to live is updated to the new value.
        The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

        See [valkey.io](https://valkey.io/commands/expireat/) for more details.

        Args:
            key (TEncodable): The key to set a timeout on.
            unix_seconds (int): The timeout in an absolute Unix timestamp.
            option (Optional[ExpireOptions]): The expire option.

        Commands response:
            bool: `True` if the timeout was set.

            `False` if the timeout was not set (e.g., the key doesn't exist or the operation
            is skipped due to the provided arguments).
        """
        args = (
            [key, str(unix_seconds)]
            if option is None
            else [key, str(unix_seconds), option.value]
        )
        return self.append_command(RequestType.ExpireAt, args)

    def pexpire(
        self: TTransaction,
        key: TEncodable,
        milliseconds: int,
        option: Optional[ExpireOptions] = None,
    ) -> TTransaction:
        """
        Sets a timeout on `key` in milliseconds. After the timeout has expired, the key will automatically be deleted.
        If `key` already has an existing expire set, the time to live is updated to the new value.
        If `milliseconds` is a non-positive number, the key will be deleted rather than expired.
        The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

        See [valkey.io](https://valkey.io/commands/pexpire/) for more details.

        Args:
            key (TEncodable): The key to set a timeout on.
            milliseconds (int): The timeout in milliseconds.
            option (Optional[ExpireOptions]): The expire option.

        Commands response:
            bool: `True` if the timeout was set.

            `False` if the timeout was not set (e.g., the key doesn't exist or the operation
            is skipped due to the provided arguments).
        """
        args = (
            [key, str(milliseconds)]
            if option is None
            else [key, str(milliseconds), option.value]
        )
        return self.append_command(RequestType.PExpire, args)

    def pexpireat(
        self: TTransaction,
        key: TEncodable,
        unix_milliseconds: int,
        option: Optional[ExpireOptions] = None,
    ) -> TTransaction:
        """
        Sets a timeout on `key` using an absolute Unix timestamp in milliseconds (milliseconds since January 1, 1970) instead
        of specifying the number of milliseconds.
        A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be
        deleted.
        If `key` already has an existing expire set, the time to live is updated to the new value.
        The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

        See [valkey.io](https://valkey.io/commands/pexpireat/) for more details.

        Args:
            key (TEncodable): The key to set a timeout on.
            unix_milliseconds (int): The timeout in an absolute Unix timestamp in milliseconds.
            option (Optional[ExpireOptions]): The expire option.

        Commands response:
            bool: `True` if the timeout was set.

            `False` if the timeout was not set (e.g., the key doesn't exist or the operation
            is skipped due to the provided arguments).
        """
        args = (
            [key, str(unix_milliseconds)]
            if option is None
            else [key, str(unix_milliseconds), option.value]
        )
        return self.append_command(RequestType.PExpireAt, args)

    def expiretime(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the absolute Unix timestamp (since January 1, 1970) at which
        the given `key` will expire, in seconds.
        To get the expiration with millisecond precision, use `pexpiretime`.

        See [valkey.io](https://valkey.io/commands/expiretime/) for details.

        Args:
            key (TEncodable): The `key` to determine the expiration value of.

        Commands response:
            int: The expiration Unix timestamp in seconds.

            -2 if `key` does not exist.

            -1 if `key` exists but has no associated expire.

        Since: Valkey version 7.0.0.
        """
        return self.append_command(RequestType.ExpireTime, [key])

    def pexpiretime(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the absolute Unix timestamp (since January 1, 1970) at which
        the given `key` will expire, in milliseconds.

        See [valkey.io](https://valkey.io/commands/pexpiretime/) for details.

        Args:
            key (TEncodable): The `key` to determine the expiration value of.

        Commands response:
            int: The expiration Unix timestamp in milliseconds.

            -2 if `key` does not exist.

            -1 if `key` exists but has no associated expiration.

        Since: Valkey version 7.0.0.
        """
        return self.append_command(RequestType.PExpireTime, [key])

    def ttl(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the remaining time to live of `key` that has a timeout.

        See [valkey.io](https://valkey.io/commands/ttl/) for more details.

        Args:
            key (TEncodable): The key to return its timeout.

        Commands response:
            int: TTL in seconds.

            -2 if `key` does not exist.

            -1 if `key` exists but has no associated expire.
        """
        return self.append_command(RequestType.TTL, [key])

    def pttl(
        self: TTransaction,
        key: TEncodable,
    ) -> TTransaction:
        """
        Returns the remaining time to live of `key` that has a timeout, in milliseconds.

        See [valkey.io](https://valkey.io/commands/pttl) for more details.

        Args:
            key (TEncodable): The key to return its timeout.

        Commands Response:
            int: TTL in milliseconds.

            -2 if `key` does not exist.

            -1 if `key` exists but has no associated expire.
        """
        return self.append_command(RequestType.PTTL, [key])

    def persist(
        self: TTransaction,
        key: TEncodable,
    ) -> TTransaction:
        """
        Remove the existing timeout on `key`, turning the key from volatile (a key with an expire set) to
        persistent (a key that will never expire as no timeout is associated).

        See [valkey.io](https://valkey.io/commands/persist/) for more details.

        Args:
            key (TEncodable): The key to remove the existing timeout on.

        Commands response:
            bool: False if `key` does not exist or does not have an associated timeout.

            True if the timeout has been removed.
        """
        return self.append_command(RequestType.Persist, [key])

    def echo(self: TTransaction, message: TEncodable) -> TTransaction:
        """
        Echoes the provided `message` back.

        See [valkey.io](https://valkey.io/commands/echo) for more details.

        Args:
            message (TEncodable): The message to be echoed back.

        Commands response:
            bytes: The provided `message`.
        """
        return self.append_command(RequestType.Echo, [message])

    def lastsave(self: TTransaction) -> TTransaction:
        """
        Returns the Unix time of the last DB save timestamp or startup timestamp if no save was made since then.

        See [valkey.io](https://valkey.io/commands/lastsave) for more details.

        Command response:
            int: The Unix time of the last successful DB save.
        """
        return self.append_command(RequestType.LastSave, [])

    def type(self: TTransaction, key: TEncodable) -> TTransaction:
        """
         Returns the string representation of the type of the value stored at `key`.

         See [valkey.io](https://valkey.io/commands/type/) for more details.

        Args:
            key (TEncodable): The key to check its data type.

        Commands response:
            bytes: If the key exists, the type of the stored value is returned.

            Otherwise, a "none" string is returned.
        """
        return self.append_command(RequestType.Type, [key])

    def function_load(
        self: TTransaction, library_code: TEncodable, replace: bool = False
    ) -> TTransaction:
        """
        Loads a library to Valkey.

        See [valkey.io](https://valkey.io/commands/function-load/) for more details.

        Args:
            library_code (TEncodable): The source code that implements the library.
            replace (bool): Whether the given library should overwrite a library with the same name if
                it already exists.

        Commands response:
            bytes: The library name that was loaded.

        Since: Valkey 7.0.0.
        """
        return self.append_command(
            RequestType.FunctionLoad,
            ["REPLACE", library_code] if replace else [library_code],
        )

    def function_list(
        self: TTransaction,
        library_name_pattern: Optional[TEncodable] = None,
        with_code: bool = False,
    ) -> TTransaction:
        """
        Returns information about the functions and libraries.

        See [valkey.io](https://valkey.io/commands/function-list/) for more details.

        Args:
            library_name_pattern (Optional[TEncodable]):  A wildcard pattern for matching library names.
            with_code (bool): Specifies whether to request the library code from the server or not.

        Commands response:
            TFunctionListResponse: Info about all or selected libraries and their functions.

        Since: Valkey 7.0.0.
        """
        args = []
        if library_name_pattern is not None:
            args.extend(["LIBRARYNAME", library_name_pattern])
        if with_code:
            args.append("WITHCODE")
        return self.append_command(
            RequestType.FunctionList,
            args,
        )

    def function_flush(
        self: TTransaction, mode: Optional[FlushMode] = None
    ) -> TTransaction:
        """
        Deletes all function libraries.

        See [valkey.io](https://valkey.io/commands/function-flush/) for more details.

        Args:
            mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.

        Commands response:
            TOK: A simple `OK`.

        Since: Valkey 7.0.0.
        """
        return self.append_command(
            RequestType.FunctionFlush,
            [mode.value] if mode else [],
        )

    def function_delete(self: TTransaction, library_name: TEncodable) -> TTransaction:
        """
        Deletes a library and all its functions.

        See [valkey.io](https://valkey.io/commands/function-delete/) for more details.

        Args:
            library_name (TEncodable): The library name to delete

        Commands response:
            TOK: A simple `OK`.

        Since: Valkey 7.0.0.
        """
        return self.append_command(
            RequestType.FunctionDelete,
            [library_name],
        )

    def fcall(
        self: TTransaction,
        function: TEncodable,
        keys: Optional[List[TEncodable]] = None,
        arguments: Optional[List[TEncodable]] = None,
    ) -> TTransaction:
        """
        Invokes a previously loaded function.

        See [valkey.io](https://valkey.io/commands/fcall/) for more details.

        Args:
            function (TEncodable): The function name.
            keys (Optional[List[TEncodable]]): A list of keys accessed by the function. To ensure the correct
                execution of functions, both in standalone and clustered deployments, all names of keys
                that a function accesses must be explicitly provided as `keys`.
            arguments (Optional[List[TEncodable]]): A list of `function` arguments. `Arguments`
                should not represent names of keys.

        Command Response:
            TResult: The invoked function's return value.

        Since: Valkey version 7.0.0.
        """
        args = []
        if keys is not None:
            args.extend([function, str(len(keys))] + keys)
        else:
            args.extend([function, str(0)])
        if arguments is not None:
            args.extend(arguments)
        return self.append_command(RequestType.FCall, args)

    def fcall_ro(
        self: TTransaction,
        function: TEncodable,
        keys: Optional[List[TEncodable]] = None,
        arguments: Optional[List[TEncodable]] = None,
    ) -> TTransaction:
        """
        Invokes a previously loaded read-only function.

        See [valkey.io](https://valkey.io/commands/fcall_ro) for more details.

        Args:
            function (TEncodable): The function name.
            keys (List[TEncodable]): An `array` of keys accessed by the function. To ensure the correct
                execution of functions, all names of keys that a function accesses must be
                explicitly provided as `keys`.
            arguments (List[TEncodable]): An `array` of `function` arguments. `arguments` should not
                represent names of keys.

        Command Response:
            TResult: The return value depends on the function that was executed.

        Since: Valkey version 7.0.0.
        """
        args = []
        if keys is not None:
            args.extend([function, str(len(keys))] + keys)
        else:
            args.extend([function, str(0)])
        if arguments is not None:
            args.extend(arguments)
        return self.append_command(RequestType.FCallReadOnly, args)

    def function_stats(self: TTransaction) -> TTransaction:
        """
        Returns information about the function that's currently running and information about the
        available execution engines.

        See [valkey.io](https://valkey.io/commands/function-stats/) for more details

        Command Response:
            TFunctionStatsSingleNodeResponse: A `Mapping` with two keys:

                - `running_script` with information about the running script.
                - `engines` with information about available engines and their stats.

        Since: Valkey version 7.0.0.
        """
        return self.append_command(RequestType.FunctionStats, [])

    def function_dump(self: TTransaction) -> TTransaction:
        """
        Returns the serialized payload of all loaded libraries.

        See [valkey.io](https://valkey.io/commands/function-dump/) for more details.

        Command response:
            bytes: The serialized payload of all loaded libraries.

        Since: Valkey version 7.0.0.
        """
        return self.append_command(RequestType.FunctionDump, [])

    def function_restore(
        self: TTransaction,
        payload: TEncodable,
        policy: Optional[FunctionRestorePolicy] = None,
    ) -> TTransaction:
        """
        Restores libraries from the serialized payload returned by the `function_dump` command.

        See [valkey.io](https://valkey.io/commands/function-restore/) for more details.

        Args:
            payload (TEncodable): The serialized data from the `function_dump` command.
            policy (Optional[FunctionRestorePolicy]): A policy for handling existing libraries.

        Command response:
            TOK: A simple "OK" response.

        Since: Valkey version 7.0.0.
        """
        args: List[TEncodable] = [payload]
        if policy is not None:
            args.append(policy.value)
        return self.append_command(RequestType.FunctionRestore, args)

    def dump(
        self: TTransaction,
        key: TEncodable,
    ) -> TTransaction:
        """
        Serialize the value stored at `key` in a Valkey-specific format and return it to the user.

        See [valkey.io](https://valkey.io/commands/dump/) for more details.

        Args:
            key (TEncodable): The `key` to serialize.

        Command response:
            Optional[bytes]: The serialized value of the data stored at `key`.

            If `key` does not exist, `None` will be returned.
        """
        return self.append_command(RequestType.Dump, [key])

    def restore(
        self: TTransaction,
        key: TEncodable,
        ttl: int,
        value: TEncodable,
        replace: bool = False,
        absttl: bool = False,
        idletime: Optional[int] = None,
        frequency: Optional[int] = None,
    ) -> TTransaction:
        """
        Create a `key` associated with a `value` that is obtained by deserializing the provided
        serialized `value` obtained via `dump`.

        See [valkey.io](https://valkey.io/commands/restore) for more details.

        Note:
            `IDLETIME` and `FREQ` modifiers cannot be set at the same time.

        Args:
            key (TEncodable): The `key` to create.
            ttl (int): The expiry time (in milliseconds). If `0`, the `key` will persist.
            value (TEncodable) The serialized value to deserialize and assign to `key`.
            replace (bool): Set to `True` to replace the key if it exists.
            absttl (bool): Set to `True` to specify that `ttl` represents an absolute Unix
                timestamp (in milliseconds).
            idletime (Optional[int]): Set the `IDLETIME` option with object idletime to the given key.
            frequency (Optional[int]): Set the `FREQ` option with object frequency to the given key.

        Command response:
            TOK: A simple "OK" response.
        """
        args = [key, str(ttl), value]
        if replace is True:
            args.append("REPLACE")
        if absttl is True:
            args.append("ABSTTL")
        if idletime is not None:
            args.extend(["IDLETIME", str(idletime)])
        if frequency is not None:
            args.extend(["FREQ", str(frequency)])
        return self.append_command(RequestType.Restore, args)

    def xadd(
        self: TTransaction,
        key: TEncodable,
        values: List[Tuple[TEncodable, TEncodable]],
        options: StreamAddOptions = StreamAddOptions(),
    ) -> TTransaction:
        """
        Adds an entry to the specified stream stored at `key`. If the `key` doesn't exist, the stream is created.

        See [valkey.io](https://valkey.io/commands/xadd) for more details.

        Args:
            key (TEncodable): The key of the stream.
            values: List[Tuple[TEncodable, TEncodable]]: Field-value pairs to be added to the entry.
            options (Optional[StreamAddOptions]): Additional options for adding entries to the stream.
                Default to None. See `StreamAddOptions`.

        Commands response:
            bytes: The id of the added entry.

            None if `options.make_stream` is set to False and no stream with the matching `key` exists.
        """
        args = [key]
        if options:
            args.extend(options.to_args())
        args.extend([field for pair in values for field in pair])

        return self.append_command(RequestType.XAdd, args)

    def xdel(
        self: TTransaction, key: TEncodable, ids: List[TEncodable]
    ) -> TTransaction:
        """
        Removes the specified entries by id from a stream, and returns the number of entries deleted.

        See [valkey.io](https://valkey.io/commands/xdel) for more details.

        Args:
            key (TEncodable): The key of the stream.
            ids (List[TEncodable]): An array of entry ids.

        Command response:
            int: The number of entries removed from the stream. This number may be less than the number of entries in
            `ids`, if the specified `ids` don't exist in the stream.
        """
        return self.append_command(RequestType.XDel, [key] + ids)

    def xtrim(
        self: TTransaction,
        key: TEncodable,
        options: StreamTrimOptions,
    ) -> TTransaction:
        """
        Trims the stream stored at `key` by evicting older entries.

        See [valkey.io](https://valkey.io/commands/xtrim) for more details.

        Args:
            key (TEncodable): The key of the stream.
            options (StreamTrimOptions): Options detailing how to trim the stream. See `StreamTrimOptions`.

        Commands response:
            int: TThe number of entries deleted from the stream.

            If `key` doesn't exist, 0 is returned.
        """
        args = [key]
        if options:
            args.extend(options.to_args())

        return self.append_command(RequestType.XTrim, args)

    def xlen(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the number of entries in the stream stored at `key`.

        See [valkey.io](https://valkey.io/commands/xlen) for more details.

        Args:
            key (TEncodable): The key of the stream.

        Command response:
            int: The number of entries in the stream.

            If `key` does not exist, returns 0.
        """
        return self.append_command(RequestType.XLen, [key])

    def xrange(
        self: TTransaction,
        key: TEncodable,
        start: StreamRangeBound,
        end: StreamRangeBound,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Returns stream entries matching a given range of IDs.

        See [valkey.io](https://valkey.io/commands/xrange) for more details.

        Args:
            key (TEncodable): The key of the stream.
            start (StreamRangeBound): The starting stream ID bound for the range.

                - Use `IdBound` to specify a stream ID.
                - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
                - Use `MinId` to start with the minimum available ID.

            end (StreamRangeBound): The ending stream ID bound for the range.

                - Use `IdBound` to specify a stream ID.
                - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
                - Use `MaxId` to end with the maximum available ID.

            count (Optional[int]): An optional argument specifying the maximum count of stream entries to return.
                If `count` is not provided, all stream entries in the range will be returned.

        Command response:
            Optional[Mapping[bytes, List[List[bytes]]]]: A mapping of stream IDs to stream entry data, where entry data is a
            list of pairings with format `[[field, entry], [field, entry], ...]`.

            Returns None if the range arguments are not applicable.
        """
        args = [key, start.to_arg(), end.to_arg()]
        if count is not None:
            args.extend(["COUNT", str(count)])

        return self.append_command(RequestType.XRange, args)

    def xrevrange(
        self: TTransaction,
        key: TEncodable,
        end: StreamRangeBound,
        start: StreamRangeBound,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Returns stream entries matching a given range of IDs in reverse order. Equivalent to `XRANGE` but returns the
        entries in reverse order.

        See [valkey.io](https://valkey.io/commands/xrevrange) for more details.

        Args:
            key (TEncodable): The key of the stream.
            end (StreamRangeBound): The ending stream ID bound for the range.

                - Use `IdBound` to specify a stream ID.
                - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
                - Use `MaxId` to end with the maximum available ID.

            start (StreamRangeBound): The starting stream ID bound for the range.

                - Use `IdBound` to specify a stream ID.
                - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
                - Use `MinId` to start with the minimum available ID.

            count (Optional[int]): An optional argument specifying the maximum count of stream entries to return.
                If `count` is not provided, all stream entries in the range will be returned.

        Command response:
            Optional[Mapping[bytes, List[List[bytes]]]]: A mapping of stream IDs to stream entry data, where entry data is a
            list of pairings with format `[[field, entry], [field, entry], ...]`.

            Returns None if the range arguments are not applicable.
        """
        args = [key, end.to_arg(), start.to_arg()]
        if count is not None:
            args.extend(["COUNT", str(count)])

        return self.append_command(RequestType.XRevRange, args)

    def xread(
        self: TTransaction,
        keys_and_ids: Mapping[TEncodable, TEncodable],
        options: Optional[StreamReadOptions] = None,
    ) -> TTransaction:
        """
        Reads entries from the given streams.

        See [valkey.io](https://valkey.io/commands/xread) for more details.

        Args:
            keys_and_ids (Mapping[TEncodable, TEncodable]): A mapping of stream keys to stream entry IDs to read from.
            options (Optional[StreamReadOptions]): Options detailing how to read the stream.

        Command response:
            Optional[Mapping[bytes, Mapping[bytes, List[List[bytes]]]]]: A mapping of stream keys, to a mapping of stream IDs,
            to a list of pairings with format `[[field, entry], [field, entry], ...]`.

            None will be returned under the following conditions:

                - All key-ID pairs in `keys_and_ids` have either a non-existing key or a non-existing ID,
                  or there are no entries after the given ID.
                - The `BLOCK` option is specified and the timeout is hit.
        """
        args: List[TEncodable] = [] if options is None else options.to_args()
        args.append("STREAMS")
        args.extend([key for key in keys_and_ids.keys()])
        args.extend([value for value in keys_and_ids.values()])

        return self.append_command(RequestType.XRead, args)

    def xgroup_create(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        group_id: TEncodable,
        options: Optional[StreamGroupOptions] = None,
    ) -> TTransaction:
        """
        Creates a new consumer group uniquely identified by `group_name` for the stream stored at `key`.

        See [valkey.io](https://valkey.io/commands/xgroup-create) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The newly created consumer group name.
            group_id (TEncodable): The stream entry ID that specifies the last delivered entry in the stream from the new
                group’s perspective. The special ID "$" can be used to specify the last entry in the stream.
            options (Optional[StreamGroupOptions]): Options for creating the stream group.

        Command response:
            TOK: A simple "OK" response.
        """
        args = [key, group_name, group_id]
        if options is not None:
            args.extend(options.to_args())

        return self.append_command(RequestType.XGroupCreate, args)

    def xgroup_destroy(
        self: TTransaction, key: TEncodable, group_name: TEncodable
    ) -> TTransaction:
        """
        Destroys the consumer group `group_name` for the stream stored at `key`.

        See [valkey.io](https://valkey.io/commands/xgroup-destroy) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name to delete.

        Command response:
            bool: True if the consumer group was destroyed.

            Otherwise, returns False.
        """
        return self.append_command(RequestType.XGroupDestroy, [key, group_name])

    def xgroup_create_consumer(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        consumer_name: TEncodable,
    ) -> TTransaction:
        """
        Creates a consumer named `consumer_name` in the consumer group `group_name` for the stream stored at `key`.

        See [valkey.io](https://valkey.io/commands/xgroup-createconsumer) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.
            consumer_name (TEncodable): The newly created consumer.

        Command response:
            bool: True if the consumer is created.

            Otherwise, returns False.
        """
        return self.append_command(
            RequestType.XGroupCreateConsumer, [key, group_name, consumer_name]
        )

    def xgroup_del_consumer(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        consumer_name: TEncodable,
    ) -> TTransaction:
        """
        Deletes a consumer named `consumer_name` in the consumer group `group_name` for the stream stored at `key`.

        See [valkey.io](https://valkey.io/commands/xgroup-delconsumer) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.
            consumer_name (TEncodable): The consumer to delete.

        Command response:
            int: The number of pending messages the `consumer` had before it was deleted.
        """
        return self.append_command(
            RequestType.XGroupDelConsumer, [key, group_name, consumer_name]
        )

    def xgroup_set_id(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        stream_id: TEncodable,
        entries_read_id: Optional[str] = None,
    ) -> TTransaction:
        """
        Set the last delivered ID for a consumer group.

        See [valkey.io](https://valkey.io/commands/xgroup-setid) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.
            stream_id (TEncodable): The stream entry ID that should be set as the last delivered ID for the consumer group.
            entries_read_id (Optional[str]): An arbitrary ID (that isn't the first ID, last ID, or the zero ID ("0-0"))
                used to find out how many entries are between the arbitrary ID (excluding it) and the stream's last
                entry. This argument can only be specified if you are using Valkey version 7.0.0 or above.

        Command response:
            TOK: A simple "OK" response.
        """
        args = [key, group_name, stream_id]
        if entries_read_id is not None:
            args.extend(["ENTRIESREAD", entries_read_id])

        return self.append_command(RequestType.XGroupSetId, args)

    def xreadgroup(
        self: TTransaction,
        keys_and_ids: Mapping[TEncodable, TEncodable],
        group_name: TEncodable,
        consumer_name: TEncodable,
        options: Optional[StreamReadGroupOptions] = None,
    ) -> TTransaction:
        """
        Reads entries from the given streams owned by a consumer group.

        See [valkey.io](https://valkey.io/commands/xreadgroup) for more details.

        Args:
            keys_and_ids (Mapping[TEncodable, TEncodable]): A mapping of stream keys to stream entry IDs to read from.
                Use the special entry ID of `">"` to receive only new messages.
            group_name (TEncodable): The consumer group name.
            consumer_name (TEncodable): The consumer name. The consumer will be auto-created if it does not already exist.
            options (Optional[StreamReadGroupOptions]): Options detailing how to read the stream.

        Command response:
            Optional[Mapping[bytes, Mapping[bytes, Optional[List[List[bytes]]]]]]: A mapping of stream keys, to a mapping of
            stream IDs, to a list of pairings with format `[[field, entry], [field, entry], ...]`.

            Returns None if the BLOCK option is given and a timeout occurs, or if there is no stream that can be served.
        """
        args = ["GROUP", group_name, consumer_name]
        if options is not None:
            args.extend(options.to_args())

        args.append("STREAMS")
        args.extend([key for key in keys_and_ids.keys()])
        args.extend([value for value in keys_and_ids.values()])

        return self.append_command(RequestType.XReadGroup, args)

    def xack(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        ids: List[TEncodable],
    ) -> TTransaction:
        """
        Removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group.
        This command should be called on pending messages so that such messages do not get processed again by the
        consumer group.

        See [valkey.io](https://valkey.io/commands/xack) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.
            ids (List[TEncodable]): The stream entry IDs to acknowledge and consume for the given consumer group.

        Command response:
            int: The number of messages that were successfully acknowledged.
        """
        return self.append_command(RequestType.XAck, [key, group_name] + ids)

    def xpending(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
    ) -> TTransaction:
        """
        Returns stream message summary information for pending messages for the given consumer group.

        See [valkey.io](https://valkey.io/commands/xpending) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.

        Command response:
            List[Union[int, bytes, List[List[bytes]], None]]: A list that includes the summary of pending messages, with the
            format `[num_group_messages, start_id, end_id, [[consumer_name, num_consumer_messages]]]`, where:

                - `num_group_messages`: The total number of pending messages for this consumer group.
                - `start_id`: The smallest ID among the pending messages.
                - `end_id`: The greatest ID among the pending messages.
                - `[[consumer_name, num_consumer_messages]]`: A 2D list of every consumer in the consumer group with at
                  least one pending message, and the number of pending messages it has.

            If there are no pending messages for the given consumer group, `[0, None, None, None]` will be returned.
        """
        return self.append_command(RequestType.XPending, [key, group_name])

    def xpending_range(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        start: StreamRangeBound,
        end: StreamRangeBound,
        count: int,
        options: Optional[StreamPendingOptions] = None,
    ) -> TTransaction:
        """
        Returns an extended form of stream message information for pending messages matching a given range of IDs.

        See [valkey.io](https://valkey.io/commands/xpending) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.
            start (StreamRangeBound): The starting stream ID bound for the range.

                - Use `IdBound` to specify a stream ID.
                - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
                - Use `MinId` to start with the minimum available ID.

            end (StreamRangeBound): The ending stream ID bound for the range.

                - Use `IdBound` to specify a stream ID.
                - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
                - Use `MaxId` to end with the maximum available ID.

            count (int): Limits the number of messages returned.
            options (Optional[StreamPendingOptions]): The stream pending options.

        Command response:
            List[List[Union[bytes, int]]]: A list of lists, where each inner list is a length 4 list containing extended
            message information with the format `[[id, consumer_name, time_elapsed, num_delivered]]`, where:

                - `id`: The ID of the message.
                - `consumer_name`: The name of the consumer that fetched the message and has still to acknowledge it. We
                  call it the current owner of the message.
                - `time_elapsed`: The number of milliseconds that elapsed since the last time this message was delivered
                  to this consumer.
                - `num_delivered`: The number of times this message was delivered.
        """
        args = _create_xpending_range_args(key, group_name, start, end, count, options)
        return self.append_command(RequestType.XPending, args)

    def xautoclaim(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        consumer_name: TEncodable,
        min_idle_time_ms: int,
        start: TEncodable,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Transfers ownership of pending stream entries that match the specified criteria.

        See [valkey.io](https://valkey.io/commands/xautoclaim) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.
            consumer_name (TEncodable): The consumer name.
            min_idle_time_ms (int): Filters the claimed entries to those that have been idle for more than the specified
                value.
            start (TEncodable): Filters the claimed entries to those that have an ID equal or greater than the specified value.
            count (Optional[int]): Limits the number of claimed entries to the specified value.

        Command response:
            List[Union[str, Mapping[bytes, List[List[bytes]]], List[bytes]]]: A list containing the following elements:

                - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent
                  to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was
                  scanned.
                - A mapping of the claimed entries, with the keys being the claimed entry IDs and the values being a
                  2D list of the field-value pairs in the format `[[field1, value1], [field2, value2], ...]`.
                - If you are using Valkey 7.0.0 or above, the response list will also include a list containing the
                  message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are
                  deleted from the Pending Entries List.

        Since: Valkey version 6.2.0.
        """
        args = [key, group_name, consumer_name, str(min_idle_time_ms), start]
        if count is not None:
            args.extend(["COUNT", str(count)])

        return self.append_command(RequestType.XAutoClaim, args)

    def xautoclaim_just_id(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
        consumer_name: TEncodable,
        min_idle_time_ms: int,
        start: TEncodable,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Transfers ownership of pending stream entries that match the specified criteria. This command uses the JUSTID
        argument to further specify that the return value should contain a list of claimed IDs without their
        field-value info.

        See [valkey.io](https://valkey.io/commands/xautoclaim) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.
            consumer_name (TEncodable): The consumer name.
            min_idle_time_ms (int): Filters the claimed entries to those that have been idle for more than the specified
                value.
            start (TEncodable): Filters the claimed entries to those that have an ID equal or greater than the specified value.
            count (Optional[int]): Limits the number of claimed entries to the specified value.

        Command response:
            List[Union[bytes, List[bytes]]]: A list containing the following elements:

                - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent
                  to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was
                  scanned.
                - A list of the IDs for the claimed entries.
                - If you are using Valkey 7.0.0 or above, the response list will also include a list containing the
                  message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are
                  deleted from the Pending Entries List.

        Since: Valkey version 6.2.0.
        """
        args = [key, group_name, consumer_name, str(min_idle_time_ms), start]
        if count is not None:
            args.extend(["COUNT", str(count)])

        args.append("JUSTID")

        return self.append_command(RequestType.XAutoClaim, args)

    def xinfo_groups(
        self: TTransaction,
        key: TEncodable,
    ) -> TTransaction:
        """
        Returns the list of all consumer groups and their attributes for the stream stored at `key`.

        See [valkey.io](https://valkey.io/commands/xinfo-groups) for more details.

        Args:
            key (TEncodable): The key of the stream.

        Command response:
            List[Mapping[bytes, Union[bytes, int, None]]]: A list of mappings, where each mapping represents the
            attributes of a consumer group for the stream at `key`.
        """
        return self.append_command(RequestType.XInfoGroups, [key])

    def xinfo_consumers(
        self: TTransaction,
        key: TEncodable,
        group_name: TEncodable,
    ) -> TTransaction:
        """
        Returns the list of all consumers and their attributes for the given consumer group of the stream stored at
        `key`.

        See [valkey.io](https://valkey.io/commands/xinfo-consumers) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group_name (TEncodable): The consumer group name.

        Command response:
            List[Mapping[bytes, Union[bytes, int]]]: A list of mappings, where each mapping contains the attributes of a
            consumer for the given consumer group of the stream at `key`.
        """
        return self.append_command(RequestType.XInfoConsumers, [key, group_name])

    def xinfo_stream(
        self: TTransaction,
        key: TEncodable,
    ) -> TTransaction:
        """
        Returns information about the stream stored at `key`. To get more detailed information, use `xinfo_stream_full`.

        See [valkey.io](https://valkey.io/commands/xinfo-stream) for more details.

        Args:
            key (TEncodable): The key of the stream.

        Command response:
            TXInfoStreamResponse: A mapping of stream information for the given `key`.
        """
        return self.append_command(RequestType.XInfoStream, [key])

    def xinfo_stream_full(
        self: TTransaction,
        key: TEncodable,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Returns verbose information about the stream stored at `key`.

        See [valkey.io](https://valkey.io/commands/xinfo-stream) for more details.

        Args:
            key (TEncodable): The key of the stream.
            count (Optional[int]): The number of stream and PEL entries that are returned. A value of `0` means that all
                entries will be returned. If not provided, defaults to `10`.

        Command response:
            TXInfoStreamFullResponse: A mapping of detailed stream information for the given `key`.
        """
        args = [key, "FULL"]
        if count is not None:
            args.extend(["COUNT", str(count)])

        return self.append_command(RequestType.XInfoStream, args)

    def geoadd(
        self: TTransaction,
        key: TEncodable,
        members_geospatialdata: Mapping[TEncodable, GeospatialData],
        existing_options: Optional[ConditionalChange] = None,
        changed: bool = False,
    ) -> TTransaction:
        """
        Adds geospatial members with their positions to the specified sorted set stored at `key`.
        If a member is already a part of the sorted set, its position is updated.

        See [valkey.io](https://valkey.io/commands/geoadd) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            members_geospatialdata (Mapping[TEncodable, GeospatialData]): A mapping of member names to their
                corresponding positions. See `GeospatialData`.
            The command will report an error when the user attempts to index coordinates outside the specified ranges.
            existing_options (Optional[ConditionalChange]): Options for handling existing members.

                - NX: Only add new elements.
                - XX: Only update existing elements.

            changed (bool): Modify the return value to return the number of changed elements, instead of the
                number of new elements added.

        Commands response:
            int: The number of elements added to the sorted set.

            If `changed` is set, returns the number of elements updated in the sorted set.
        """
        args = [key]
        if existing_options:
            args.append(existing_options.value)

        if changed:
            args.append("CH")

        members_geospatialdata_list = [
            coord
            for member, position in members_geospatialdata.items()
            for coord in [str(position.longitude), str(position.latitude), member]
        ]
        args += members_geospatialdata_list

        return self.append_command(RequestType.GeoAdd, args)

    def geodist(
        self: TTransaction,
        key: TEncodable,
        member1: TEncodable,
        member2: TEncodable,
        unit: Optional[GeoUnit] = None,
    ) -> TTransaction:
        """
        Returns the distance between two members in the geospatial index stored at `key`.

        See [valkey.io](https://valkey.io/commands/geodist) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            member1 (TEncodable): The name of the first member.
            member2 (TEncodable): The name of the second member.
            unit (Optional[GeoUnit]): The unit of distance measurement. See `GeoUnit`.
                If not specified, the default unit is meters.

        Commands response:
            Optional[float]: The distance between `member1` and `member2`.

            If one or both members do not exist, or if the key does not exist, returns None.
        """
        args = [key, member1, member2]
        if unit:
            args.append(unit.value)

        return self.append_command(RequestType.GeoDist, args)

    def geohash(
        self: TTransaction, key: TEncodable, members: List[TEncodable]
    ) -> TTransaction:
        """
        Returns the GeoHash bytes strings representing the positions of all the specified members in the sorted set stored at
        `key`.

        See [valkey.io](https://valkey.io/commands/geohash) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            members (List[TEncodable]): The list of members whose GeoHash bytes strings are to be retrieved.

        Commands response:
            List[Optional[bytes]]: A list of GeoHash bytes strings representing the positions of the specified members
            stored at `key`.

            If a member does not exist in the sorted set, a None value is returned for that member.
        """
        return self.append_command(RequestType.GeoHash, [key] + members)

    def geopos(
        self: TTransaction,
        key: TEncodable,
        members: List[TEncodable],
    ) -> TTransaction:
        """
        Returns the positions (longitude and latitude) of all the given members of a geospatial index in the sorted set stored
        at `key`.

        See [valkey.io](https://valkey.io/commands/geopos) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            members (List[TEncodable]): The members for which to get the positions.

        Commands response:
            List[Optional[List[float]]]: A list of positions (longitude and latitude) corresponding to the given members.

            If a member does not exist, its position will be None.
        """
        return self.append_command(RequestType.GeoPos, [key] + members)

    def geosearch(
        self: TTransaction,
        key: TEncodable,
        search_from: Union[TEncodable, GeospatialData],
        search_by: Union[GeoSearchByRadius, GeoSearchByBox],
        order_by: Optional[OrderBy] = None,
        count: Optional[GeoSearchCount] = None,
        with_coord: bool = False,
        with_dist: bool = False,
        with_hash: bool = False,
    ) -> TTransaction:
        """
        Searches for members in a sorted set stored at `key` representing geospatial data within a circular or
        rectangular area.

        See [valkey.io](https://valkey.io/commands/geosearch/) for more details.

        Args:
            key (TEncodable): The key of the sorted set representing geospatial data.
            search_from (Union[TEncodable, GeospatialData]): The location to search from. Can be specified either as a member
                from the sorted set or as a geospatial data (see `GeospatialData`).
            search_by (Union[GeoSearchByRadius, GeoSearchByBox]): The search criteria.
                For circular area search, see `GeoSearchByRadius`.
                For rectangle area search, see `GeoSearchByBox`.
            order_by (Optional[OrderBy]): Specifies the order in which the results should be returned.

                - `ASC`: Sorts items from the nearest to the farthest, relative to the center point.
                - `DESC`: Sorts items from the farthest to the nearest, relative to the center point.

                If not specified, the results would be unsorted.
            count (Optional[GeoSearchCount]): Specifies the maximum number of results to return. See `GeoSearchCount`.
                If not specified, return all results.
            with_coord (bool): Whether to include coordinates of the returned items. Defaults to False.
            with_dist (bool): Whether to include distance from the center in the returned items.
                The distance is returned in the same unit as specified for the `search_by` arguments. Defaults to False.
            with_hash (bool): Whether to include geohash of the returned items. Defaults to False.

        Command Response:
            List[Union[bytes, List[Union[bytes, float, int, List[float]]]]]: By default, returns a list of members (locations)
            names.

            If any of `with_coord`, `with_dist` or `with_hash` are True, returns an array of arrays, where each sub array
            represents a single item in the following order:

                - (bytes): The member (location) name.
                - (float): The distance from the center as a floating point number, in the same unit specified in the radius,
                  if `with_dist` is set to True.
                - (int): The Geohash integer, if `with_hash` is set to True.
                - List[float]: The coordinates as a two item [longitude,latitude] array, if `with_coord` is set to True.

        Since: Valkey version 6.2.0.
        """
        args = _create_geosearch_args(
            [key],
            search_from,
            search_by,
            order_by,
            count,
            with_coord,
            with_dist,
            with_hash,
        )

        return self.append_command(RequestType.GeoSearch, args)

    def geosearchstore(
        self: TTransaction,
        destination: TEncodable,
        source: TEncodable,
        search_from: Union[TEncodable, GeospatialData],
        search_by: Union[GeoSearchByRadius, GeoSearchByBox],
        count: Optional[GeoSearchCount] = None,
        store_dist: bool = False,
    ) -> TTransaction:
        """
        Searches for members in a sorted set stored at `key` representing geospatial data within a circular or rectangular
        area and stores the result in `destination`.
        If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.

        To get the result directly, see `geosearch`.

        See [valkey.io](https://valkey.io/commands/geosearch/) for more details.

        Args:
            destination (TEncodable): The key to store the search results.
            source (TEncodable): The key of the sorted set representing geospatial data to search from.
            search_from (Union[TEncodable, GeospatialData]): The location to search from. Can be specified either as a member
                from the sorted set or as a geospatial data (see `GeospatialData`).
            search_by (Union[GeoSearchByRadius, GeoSearchByBox]): The search criteria.
                For circular area search, see `GeoSearchByRadius`.
                For rectangular area search, see `GeoSearchByBox`.
            count (Optional[GeoSearchCount]): Specifies the maximum number of results to store. See `GeoSearchCount`.
                If not specified, stores all results.
            store_dist (bool): Determines what is stored as the sorted set score. Defaults to False.

                - If set to False, the geohash of the location will be stored as the sorted set score.
                - If set to True, the distance from the center of the shape (circle or box) will be stored as the sorted set
                  score. The distance is represented as a floating-point number in the same unit specified for that shape.

        Commands response:
            int: The number of elements in the resulting sorted set stored at `destination`.

        Since: Valkey version 6.2.0.
        """
        args = _create_geosearch_args(
            [destination, source],
            search_from,
            search_by,
            None,
            count,
            False,
            False,
            False,
            store_dist,
        )

        return self.append_command(RequestType.GeoSearchStore, args)

    def zadd(
        self: TTransaction,
        key: TEncodable,
        members_scores: Mapping[TEncodable, float],
        existing_options: Optional[ConditionalChange] = None,
        update_condition: Optional[UpdateOptions] = None,
        changed: bool = False,
    ) -> TTransaction:
        """
        Adds members with their scores to the sorted set stored at `key`.
        If a member is already a part of the sorted set, its score is updated.

        See [valkey.io](https://valkey.io/commands/zadd/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            members_scores (Mapping[TEncodable, float]): A mapping of members to their corresponding scores.
            existing_options (Optional[ConditionalChange]): Options for handling existing members.

                - NX: Only add new elements.
                - XX: Only update existing elements.

            update_condition (Optional[UpdateOptions]): Options for updating scores.

                - GT: Only update scores greater than the current values.
                - LT: Only update scores less than the current values.

            changed (bool): Modify the return value to return the number of changed elements, instead of the number
                of new elements added.

        Commands response:
            int: The number of elements added to the sorted set.

            If `changed` is set, returns the number of elements updated in the sorted set.
        """
        args = [key]
        if existing_options:
            args.append(existing_options.value)

        if update_condition:
            args.append(update_condition.value)

        if changed:
            args.append("CH")

        if existing_options and update_condition:
            if existing_options == ConditionalChange.ONLY_IF_DOES_NOT_EXIST:
                raise ValueError(
                    "The GT, LT and NX options are mutually exclusive. "
                    f"Cannot choose both {update_condition.value} and NX."
                )

        members_scores_list = [
            str(item) for pair in members_scores.items() for item in pair[::-1]
        ]
        args += members_scores_list

        return self.append_command(RequestType.ZAdd, args)

    def zadd_incr(
        self: TTransaction,
        key: TEncodable,
        member: TEncodable,
        increment: float,
        existing_options: Optional[ConditionalChange] = None,
        update_condition: Optional[UpdateOptions] = None,
    ) -> TTransaction:
        """
        Increments the score of member in the sorted set stored at `key` by `increment`.
        If `member` does not exist in the sorted set, it is added with `increment` as its score (as if its
        previous score was 0.0).
        If `key` does not exist, a new sorted set with the specified member as its sole member is created.

        See [valkey.io](https://valkey.io/commands/zadd/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            member (TEncodable): A member in the sorted set to increment.
            increment (float): The score to increment the member.
            existing_options (Optional[ConditionalChange]): Options for handling the member's existence.

                - NX: Only increment a member that doesn't exist.
                - XX: Only increment an existing member.

            update_condition (Optional[UpdateOptions]): Options for updating the score.

                - GT: Only increment the score of the member if the new score will be greater than the current score.
                - LT: Only increment (decrement) the score of the member if the new score will be less than the current score.

        Commands response:
            Optional[float]: The score of the member.

            If there was a conflict with choosing the XX/NX/LT/GT options, the operation aborts and None is returned.
        """
        args = [key]
        if existing_options:
            args.append(existing_options.value)

        if update_condition:
            args.append(update_condition.value)

        args.append("INCR")

        if existing_options and update_condition:
            if existing_options == ConditionalChange.ONLY_IF_DOES_NOT_EXIST:
                raise ValueError(
                    "The GT, LT and NX options are mutually exclusive. "
                    f"Cannot choose both {update_condition.value} and NX."
                )

        args += [str(increment), member]
        return self.append_command(RequestType.ZAdd, args)

    def zcard(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the cardinality (number of elements) of the sorted set stored at `key`.

        See [valkey.io](https://valkey.io/commands/zcard/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.

        Commands response:
            int: The number of elements in the sorted set.

            If `key` does not exist, it is treated as an empty sorted set, and the command returns 0.
        """
        return self.append_command(RequestType.ZCard, [key])

    def zcount(
        self: TTransaction,
        key: TEncodable,
        min_score: Union[InfBound, ScoreBoundary],
        max_score: Union[InfBound, ScoreBoundary],
    ) -> TTransaction:
        """
        Returns the number of members in the sorted set stored at `key` with scores between `min_score` and `max_score`.

        See [valkey.io](https://valkey.io/commands/zcount/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            min_score (Union[InfBound, ScoreBoundary]): The minimum score to count from.
                Can be an instance of InfBound representing positive/negative infinity,
                or ScoreBoundary representing a specific score and inclusivity.
            max_score (Union[InfBound, ScoreBoundary]): The maximum score to count up to.
                Can be an instance of InfBound representing positive/negative infinity,
                or ScoreBoundary representing a specific score and inclusivity.

        Commands response:
            int: The number of members in the specified score range.

            If key does not exist, 0 is returned.

            If `max_score` < `min_score`, 0 is returned.
        """
        score_min = (
            min_score.value["score_arg"]
            if isinstance(min_score, InfBound)
            else min_score.value
        )
        score_max = (
            max_score.value["score_arg"]
            if isinstance(max_score, InfBound)
            else max_score.value
        )
        return self.append_command(RequestType.ZCount, [key, score_min, score_max])

    def zincrby(
        self: TTransaction,
        key: TEncodable,
        increment: float,
        member: TEncodable,
    ) -> TTransaction:
        """
        Increments the score of `member` in the sorted set stored at `key` by `increment`.
        If `member` does not exist in the sorted set, it is added with `increment` as its score.
        If `key` does not exist, a new sorted set is created with the specified member as its sole member.

        See [valkey.io](https://valkey.io/commands/zincrby/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            increment (float): The score increment.
            member (TEncodable): A member of the sorted set.

        Commands response:
            float: The new score of `member`.
        """
        return self.append_command(RequestType.ZIncrBy, [key, str(increment), member])

    def zpopmax(
        self: TTransaction, key: TEncodable, count: Optional[int] = None
    ) -> TTransaction:
        """
        Removes and returns the members with the highest scores from the sorted set stored at `key`.
        If `count` is provided, up to `count` members with the highest scores are removed and returned.
        Otherwise, only one member with the highest score is removed and returned.

        See [valkey.io](https://valkey.io/commands/zpopmax) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            count (Optional[int]): Specifies the quantity of members to pop. If not specified, pops one member.
                If `count` is higher than the sorted set's cardinality, returns all members and their scores,
                ordered from highest to lowest.

        Commands response:
            Mapping[bytes, float]: A map of the removed members and their scores, ordered from the one with the highest score
            to the one with the lowest.

            If `key` doesn't exist, it will be treated as an emtpy sorted set and the command returns an empty map.
        """
        return self.append_command(
            RequestType.ZPopMax, [key, str(count)] if count else [key]
        )

    def bzpopmax(
        self: TTransaction, keys: List[TEncodable], timeout: float
    ) -> TTransaction:
        """
        Pops the member with the highest score from the first non-empty sorted set, with the given keys being checked in
        the order that they are given. Blocks the connection when there are no members to remove from any of the given
        sorted sets.

        `BZPOPMAX` is the blocking variant of `ZPOPMAX`.

        Note:
            `BZPOPMAX` is a client blocking command, see
            [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
            for more details and best practices.

        See [valkey.io](https://valkey.io/commands/bzpopmax) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.
            timeout (float): The number of seconds to wait for a blocking operation to complete.
                A value of 0 will block indefinitely.

        Command response:
            Optional[List[Union[bytes, float]]]: An array containing the key where the member was popped out, the
            member itself, and the member score.

            If no member could be popped and the `timeout` expired, returns None.
        """
        return self.append_command(RequestType.BZPopMax, keys + [str(timeout)])

    def zpopmin(
        self: TTransaction, key: TEncodable, count: Optional[int] = None
    ) -> TTransaction:
        """
        Removes and returns the members with the lowest scores from the sorted set stored at `key`.
        If `count` is provided, up to `count` members with the lowest scores are removed and returned.
        Otherwise, only one member with the lowest score is removed and returned.

        See [valkey.io](https://valkey.io/commands/zpopmin) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            count (Optional[int]): Specifies the quantity of members to pop. If not specified, pops one member.
                If `count` is higher than the sorted set's cardinality, returns all members and their scores.

        Commands response:
            Mapping[bytes, float]: A map of the removed members and their scores, ordered from the one with the lowest score
            to the one with the highest.

            If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
        """
        return self.append_command(
            RequestType.ZPopMin, [key, str(count)] if count else [key]
        )

    def bzpopmin(
        self: TTransaction, keys: List[TEncodable], timeout: float
    ) -> TTransaction:
        """
        Pops the member with the lowest score from the first non-empty sorted set, with the given keys being checked in
        the order that they are given. Blocks the connection when there are no members to remove from any of the given
        sorted sets.

        `BZPOPMIN` is the blocking variant of `ZPOPMIN`.

        Note:
            `BZPOPMIN` is a client blocking command, see
            [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
            for more details and best practices.

        See [valkey.io](https://valkey.io/commands/bzpopmin) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.
            timeout (float): The number of seconds to wait for a blocking operation to complete.
                A value of 0 will block indefinitely.

        Command response:
            Optional[List[Union[bytes, float]]]: An array containing the key where the member was popped out, the
            member itself, and the member score.

            If no member could be popped and the `timeout` expired, returns None.
        """
        return self.append_command(RequestType.BZPopMin, keys + [str(timeout)])

    def zrange(
        self: TTransaction,
        key: TEncodable,
        range_query: Union[RangeByIndex, RangeByLex, RangeByScore],
        reverse: bool = False,
    ) -> TTransaction:
        """
        Returns the specified range of elements in the sorted set stored at `key`.

        ZRANGE can perform different types of range queries: by index (rank), by the score, or by lexicographical order.

        See [valkey.io](https://valkey.io/commands/zrange/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            range_query (Union[RangeByIndex, RangeByLex, RangeByScore]): The range query object representing the type of range
            query to perform.

                - For range queries by index (rank), use RangeByIndex.
                - For range queries by lexicographical order, use RangeByLex.
                - For range queries by score, use RangeByScore.

            reverse (bool): If True, reverses the sorted set, with index 0 as the element with the highest score.

        Commands response:
            List[bytes]: A list of elements within the specified range.

            If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
        """
        args = _create_zrange_args(key, range_query, reverse, with_scores=False)

        return self.append_command(RequestType.ZRange, args)

    def zrange_withscores(
        self: TTransaction,
        key: TEncodable,
        range_query: Union[RangeByIndex, RangeByScore],
        reverse: bool = False,
    ) -> TTransaction:
        """
        Returns the specified range of elements with their scores in the sorted set stored at `key`.
        Similar to ZRANGE but with a WITHSCORE flag.

        See [valkey.io](https://valkey.io/commands/zrange/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            range_query (Union[RangeByIndex, RangeByScore]): The range query object representing the type of range query
            to perform.

                - For range queries by index (rank), use RangeByIndex.
                - For range queries by score, use RangeByScore.

            reverse (bool): If True, reverses the sorted set, with index 0 as the element with the highest score.

        Commands response:
            Mapping[bytes , float]: A map of elements and their scores within the specified range.

            If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty map.
        """
        args = _create_zrange_args(key, range_query, reverse, with_scores=True)

        return self.append_command(RequestType.ZRange, args)

    def zrangestore(
        self: TTransaction,
        destination: TEncodable,
        source: TEncodable,
        range_query: Union[RangeByIndex, RangeByLex, RangeByScore],
        reverse: bool = False,
    ) -> TTransaction:
        """
        Stores a specified range of elements from the sorted set at `source`, into a new sorted set at `destination`. If
        `destination` doesn't exist, a new sorted set is created; if it exists, it's overwritten.

        ZRANGESTORE can perform different types of range queries: by index (rank), by the score, or by lexicographical
        order.

        See [valkey.io](https://valkey.io/commands/zrangestore) for more details.

        Args:
            destination (TEncodable): The key for the destination sorted set.
            source (TEncodable): The key of the source sorted set.
            range_query (Union[RangeByIndex, RangeByLex, RangeByScore]): The range query object representing the type of
            range query to perform.

                - For range queries by index (rank), use RangeByIndex.
                - For range queries by lexicographical order, use RangeByLex.
                - For range queries by score, use RangeByScore.

            reverse (bool): If True, reverses the sorted set, with index 0 as the element with the highest score.

        Command response:
            int: The number of elements in the resulting sorted set.
        """
        args = _create_zrange_args(source, range_query, reverse, False, destination)

        return self.append_command(RequestType.ZRangeStore, args)

    def zrank(
        self: TTransaction,
        key: TEncodable,
        member: TEncodable,
    ) -> TTransaction:
        """
        Returns the rank of `member` in the sorted set stored at `key`, with scores ordered from low to high.

        See [valkey.io](https://valkey.io/commands/zrank) for more details.

        To get the rank of `member` with its score, see `zrank_withscore`.

        Args:
            key (TEncodable): The key of the sorted set.
            member (TEncodable): The member whose rank is to be retrieved.

        Commands response:
            Optional[int]: The rank of `member` in the sorted set.

            If `key` doesn't exist, or if `member` is not present in the set, None will be returned.
        """
        return self.append_command(RequestType.ZRank, [key, member])

    def zrank_withscore(
        self: TTransaction,
        key: TEncodable,
        member: TEncodable,
    ) -> TTransaction:
        """
        Returns the rank of `member` in the sorted set stored at `key` with its score, where scores are ordered from the
        lowest to highest.

        See [valkey.io](https://valkey.io/commands/zrank) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            member (TEncodable): The member whose rank is to be retrieved.

        Commands response:
            Optional[List[Union[int, float]]]: A list containing the rank and score of `member` in the sorted set.

            If `key` doesn't exist, or if `member` is not present in the set, None will be returned.

        Since: Valkey version 7.2.0.
        """
        return self.append_command(RequestType.ZRank, [key, member, "WITHSCORE"])

    def zrevrank(
        self: TTransaction, key: TEncodable, member: TEncodable
    ) -> TTransaction:
        """
        Returns the rank of `member` in the sorted set stored at `key`, where scores are ordered from the highest to
        lowest, starting from `0`.

        To get the rank of `member` with its score, see `zrevrank_withscore`.

        See [valkey.io](https://valkey.io/commands/zrevrank) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            member (TEncodable): The member whose rank is to be retrieved.

        Command response:
            Optional[int]: The rank of `member` in the sorted set, where ranks are ordered from high to low based on scores.

            If `key` doesn't exist, or if `member` is not present in the set, `None` will be returned.
        """
        return self.append_command(RequestType.ZRevRank, [key, member])

    def zrevrank_withscore(
        self: TTransaction, key: TEncodable, member: TEncodable
    ) -> TTransaction:
        """
        Returns the rank of `member` in the sorted set stored at `key` with its score, where scores are ordered from the
        highest to lowest, starting from `0`.

        See [valkey.io](https://valkey.io/commands/zrevrank) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            member (TEncodable): The member whose rank is to be retrieved.

        Command response:
            Optional[List[Union[int, float]]]: A list containing the rank (as `int`) and score (as `float`) of `member`
            in the sorted set, where ranks are ordered from high to low based on scores.

            If `key` doesn't exist, or if `member` is not present in the set, `None` will be returned.

        Since: Valkey version 7.2.0.
        """
        return self.append_command(RequestType.ZRevRank, [key, member, "WITHSCORE"])

    def zrem(
        self: TTransaction,
        key: TEncodable,
        members: List[TEncodable],
    ) -> TTransaction:
        """
        Removes the specified members from the sorted set stored at `key`.
        Specified members that are not a member of this set are ignored.

        See [valkey.io](https://valkey.io/commands/zrem/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            members (List[TEncodable]): A list of members to remove from the sorted set.

        Commands response:
            int: The number of members that were removed from the sorted set, not including non-existing members.

            If `key` does not exist, it is treated as an empty sorted set, and the command returns 0.
        """
        return self.append_command(RequestType.ZRem, [key] + members)

    def zremrangebyscore(
        self: TTransaction,
        key: TEncodable,
        min_score: Union[InfBound, ScoreBoundary],
        max_score: Union[InfBound, ScoreBoundary],
    ) -> TTransaction:
        """
        Removes all elements in the sorted set stored at `key` with a score between `min_score` and `max_score`.

        See [valkey.io](https://valkey.io/commands/zremrangebyscore/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            min_score (Union[InfBound, ScoreBoundary]): The minimum score to remove from.
                Can be an instance of InfBound representing positive/negative infinity,
                or ScoreBoundary representing a specific score and inclusivity.
            max_score (Union[InfBound, ScoreBoundary]): The maximum score to remove up to.
                Can be an instance of InfBound representing positive/negative infinity,
                or ScoreBoundary representing a specific score and inclusivity.

        Commands response:
            int: The number of members that were removed from the sorted set.

            If `key` does not exist, it is treated as an empty sorted set, and the command returns 0.

            If `min_score` is greater than `max_score`, 0 is returned.
        """
        score_min = (
            min_score.value["score_arg"]
            if isinstance(min_score, InfBound)
            else min_score.value
        )
        score_max = (
            max_score.value["score_arg"]
            if isinstance(max_score, InfBound)
            else max_score.value
        )
        return self.append_command(
            RequestType.ZRemRangeByScore, [key, score_min, score_max]
        )

    def zremrangebylex(
        self: TTransaction,
        key: TEncodable,
        min_lex: Union[InfBound, LexBoundary],
        max_lex: Union[InfBound, LexBoundary],
    ) -> TTransaction:
        """
        Removes all elements in the sorted set stored at `key` with a lexicographical order between `min_lex` and
        `max_lex`.

        See [valkey.io](https://valkey.io/commands/zremrangebylex/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            min_lex (Union[InfBound, LexBoundary]): The minimum bound of the lexicographical range.
                Can be an instance of `InfBound` representing positive/negative infinity, or `LexBoundary`
                representing a specific lex and inclusivity.
            max_lex (Union[InfBound, LexBoundary]): The maximum bound of the lexicographical range.
                Can be an instance of `InfBound` representing positive/negative infinity, or `LexBoundary`
                representing a specific lex and inclusivity.

        Command response:
            int: The number of members that were removed from the sorted set.

            If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`.

            If `min_lex` is greater than `max_lex`, `0` is returned.
        """
        min_lex_arg = (
            min_lex.value["lex_arg"] if isinstance(min_lex, InfBound) else min_lex.value
        )
        max_lex_arg = (
            max_lex.value["lex_arg"] if isinstance(max_lex, InfBound) else max_lex.value
        )

        return self.append_command(
            RequestType.ZRemRangeByLex, [key, min_lex_arg, max_lex_arg]
        )

    def zremrangebyrank(
        self: TTransaction,
        key: TEncodable,
        start: int,
        end: int,
    ) -> TTransaction:
        """
        Removes all elements in the sorted set stored at `key` with rank between `start` and `end`.
        Both `start` and `end` are zero-based indexes with 0 being the element with the lowest score.
        These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score.

        See [valkey.io](https://valkey.io/commands/zremrangebyrank/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            start (int): The starting point of the range.
            end (int): The end of the range.

        Command response:
            int: The number of elements that were removed.

            If `start` exceeds the end of the sorted set, or if `start` is greater than `end`, `0` is returned.

            If `end` exceeds the actual end of the sorted set, the range will stop at the actual end of the sorted set.

            If `key` does not exist, `0` is returned.
        """
        return self.append_command(
            RequestType.ZRemRangeByRank, [key, str(start), str(end)]
        )

    def zlexcount(
        self: TTransaction,
        key: TEncodable,
        min_lex: Union[InfBound, LexBoundary],
        max_lex: Union[InfBound, LexBoundary],
    ) -> TTransaction:
        """
        Returns the number of members in the sorted set stored at `key` with lexographical values between
        `min_lex` and `max_lex`.

        See [valkey.io](https://valkey.io/commands/zlexcount/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            min_lex (Union[InfBound, LexBoundary]): The minimum lexicographical value to count from.
                Can be an instance of InfBound representing positive/negative infinity,
                or LexBoundary representing a specific lexicographical value and inclusivity.
            max_lex (Union[InfBound, LexBoundary]): The maximum lexicographical value to count up to.
                Can be an instance of InfBound representing positive/negative infinity,
                or LexBoundary representing a specific lexicographical value and inclusivity.

        Command response:
            int: The number of members in the specified lexicographical range.

            If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`.

            If `max_lex < min_lex`, `0` is returned.
        """
        min_lex_arg = (
            min_lex.value["lex_arg"] if isinstance(min_lex, InfBound) else min_lex.value
        )
        max_lex_arg = (
            max_lex.value["lex_arg"] if isinstance(max_lex, InfBound) else max_lex.value
        )

        return self.append_command(
            RequestType.ZLexCount, [key, min_lex_arg, max_lex_arg]
        )

    def zscore(self: TTransaction, key: TEncodable, member: TEncodable) -> TTransaction:
        """
        Returns the score of `member` in the sorted set stored at `key`.

        See [valkey.io](https://valkey.io/commands/zscore/) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            member (TEncodable): The member whose score is to be retrieved.

        Commands response:
            Optional[float]: The score of the member.

            If `member` does not exist in the sorted set, None is returned.

            If `key` does not exist,  None is returned.
        """
        return self.append_command(RequestType.ZScore, [key, member])

    def zmscore(
        self: TTransaction, key: TEncodable, members: List[TEncodable]
    ) -> TTransaction:
        """
        Returns the scores associated with the specified `members` in the sorted set stored at `key`.

        See [valkey.io](https://valkey.io/commands/zmscore) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            members (List[TEncodable]): A list of members in the sorted set.

        Command response:
            List[Optional[float]]: A list of scores corresponding to `members`.

            If a member does not exist in the sorted set, the corresponding value in the list will be None.
        """
        return self.append_command(RequestType.ZMScore, [key] + members)

    def zdiff(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Returns the difference between the first sorted set and all the successive sorted sets.
        To get the elements with their scores, see `zdiff_withscores`.

        See [valkey.io](https://valkey.io/commands/zdiff) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.

        Command response:
            List[bytes]: A list of elements representing the difference between the sorted sets.

            If the first key does not exist, it is treated as an empty sorted set, and the command returns an
            empty list.
        """
        args: List[TEncodable] = [str(len(keys))]
        args.extend(keys)
        return self.append_command(RequestType.ZDiff, args)

    def zdiff_withscores(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Returns the difference between the first sorted set and all the successive sorted sets, with the associated scores.

        See [valkey.io](https://valkey.io/commands/zdiff) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.

        Command response:
            Mapping[bytes, float]: A mapping of elements and their scores representing the difference between the sorted sets.

            If the first `key` does not exist, it is treated as an empty sorted set, and the command returns an
            empty list.
        """
        return self.append_command(
            RequestType.ZDiff, [str(len(keys))] + keys + ["WITHSCORES"]
        )

    def zdiffstore(
        self: TTransaction,
        destination: TEncodable,
        keys: List[TEncodable],
    ) -> TTransaction:
        """
        Calculates the difference between the first sorted set and all the successive sorted sets at `keys` and stores
        the difference as a sorted set to `destination`, overwriting it if it already exists. Non-existent keys are
        treated as empty sets.

        See [valkey.io](https://valkey.io/commands/zdiffstore) for more details.

        Args:
            destination (TEncodable): The key for the resulting sorted set.
            keys (List[TEncodable]): The keys of the sorted sets to compare.

        Command response:
            int: The number of members in the resulting sorted set stored at `destination`.
        """
        return self.append_command(
            RequestType.ZDiffStore, [destination, str(len(keys))] + keys
        )

    def zinter(
        self: TTransaction,
        keys: List[TEncodable],
    ) -> TTransaction:
        """
        Computes the intersection of sorted sets given by the specified `keys` and returns a list of intersecting elements.

        See [valkey.io](https://valkey.io/commands/zinter/) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.

        Command response:
            List[bytes]: The resulting array of intersecting elements.
        """
        args: List[TEncodable] = [str(len(keys))]
        args.extend(keys)
        return self.append_command(RequestType.ZInter, args)

    def zinter_withscores(
        self: TTransaction,
        keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
        aggregation_type: Optional[AggregationType] = None,
    ) -> TTransaction:
        """
        Computes the intersection of sorted sets given by the specified `keys` and returns a sorted set of
        intersecting elements with scores.

        See [valkey.io](https://valkey.io/commands/zinter/) for more details.

        Args:
            keys (Union[List[TEncodable], List[Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

                - List[TEncodable] - for keys only.
                - List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.

            aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
                when combining the scores of elements. See `AggregationType`.

        Command response:
            Mapping[bytes, float]: The resulting sorted set with scores.
        """
        args = _create_zinter_zunion_cmd_args(keys, aggregation_type)
        args.append("WITHSCORES")
        return self.append_command(RequestType.ZInter, args)

    def zinterstore(
        self: TTransaction,
        destination: TEncodable,
        keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
        aggregation_type: Optional[AggregationType] = None,
    ) -> TTransaction:
        """
        Computes the intersection of sorted sets given by the specified `keys` and stores the result in `destination`.
        If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.

        Note:
            When in cluster mode, `destination` and all keys in `keys` must map to the same hash slot.

        See [valkey.io](https://valkey.io/commands/zinterstore/) for more details.

        Args:
            destination (TEncodable): The key of the destination sorted set.
            keys (Union[List[TEncodable], Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

                - List[TEncodable] - for keys only.
                - List[Tuple[TEncodable, float]]] - for weighted keys with score multipliers.

            aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
                when combining the scores of elements. See `AggregationType`.

        Command response:
            int: The number of elements in the resulting sorted set stored at `destination`.
        """
        args = _create_zinter_zunion_cmd_args(keys, aggregation_type, destination)
        return self.append_command(RequestType.ZInterStore, args)

    def zunion(
        self: TTransaction,
        keys: List[TEncodable],
    ) -> TTransaction:
        """
        Computes the union of sorted sets given by the specified `keys` and returns a list of union elements.

        See [valkey.io](https://valkey.io/commands/zunion/) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.

        Command response:
            List[bytes]: The resulting array of union elements.
        """
        args: List[TEncodable] = [str(len(keys))]
        args.extend(keys)
        return self.append_command(RequestType.ZUnion, args)

    def zunion_withscores(
        self: TTransaction,
        keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
        aggregation_type: Optional[AggregationType] = None,
    ) -> TTransaction:
        """
        Computes the union of sorted sets given by the specified `keys` and returns a sorted set of union elements with scores.

        See [valkey.io](https://valkey.io/commands/zunion/) for more details.

        Args:
            keys (Union[List[TEncodable], List[Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

                - List[TEncodable] - for keys only.
                - List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.

            aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
                when combining the scores of elements. See `AggregationType`.

        Command response:
            Mapping[bytes, float]: The resulting sorted set with scores.
        """
        args = _create_zinter_zunion_cmd_args(keys, aggregation_type)
        args.append("WITHSCORES")
        return self.append_command(RequestType.ZUnion, args)

    def zunionstore(
        self: TTransaction,
        destination: TEncodable,
        keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
        aggregation_type: Optional[Optional[AggregationType]] = None,
    ) -> TTransaction:
        """
        Computes the union of sorted sets given by the specified `keys` and stores the result in `destination`.
        If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.

        Note:
            When in cluster mode, `destination` and all keys in `keys` must map to the same hash slot.

        see [valkey.io](https://valkey.io/commands/zunionstore/) for more details.

        Args:
            destination (TEncodable): The key of the destination sorted set.
            keys (Union[List[TEncodable], List[Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

                - List[TEncodable] - for keys only.
                - List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.

            aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
                when combining the scores of elements. See `AggregationType`.

        Command response:
            int: The number of elements in the resulting sorted set stored at `destination`.
        """
        args = _create_zinter_zunion_cmd_args(keys, aggregation_type, destination)
        return self.append_command(RequestType.ZUnionStore, args)

    def zrandmember(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns a random member from the sorted set stored at 'key'.

        See [valkey.io](https://valkey.io/commands/zrandmember) for more details.

        Args:
            key (TEncodable): The key of the sorted set.

        Command response:
            Optional[bytes]: A random member from the sorted set.

            If the sorted set does not exist or is empty, the response will be None.
        """
        return self.append_command(RequestType.ZRandMember, [key])

    def zrandmember_count(
        self: TTransaction, key: TEncodable, count: int
    ) -> TTransaction:
        """
        Retrieves up to the absolute value of `count` random members from the sorted set stored at 'key'.

        See [valkey.io](https://valkey.io/commands/zrandmember) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            count (int): The number of members to return.

                - If `count` is positive, returns unique members.
                - If `count` is negative, allows for duplicates members.

        Command response:
            List[bytes]: A list of members from the sorted set.

            If the sorted set does not exist or is empty, the response will be an empty list.
        """
        return self.append_command(RequestType.ZRandMember, [key, str(count)])

    def zrandmember_withscores(
        self: TTransaction, key: TEncodable, count: int
    ) -> TTransaction:
        """
        Retrieves up to the absolute value of `count` random members along with their scores from the sorted set
        stored at 'key'.

        See [valkey.io](https://valkey.io/commands/zrandmember) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            count (int): The number of members to return.

                - If `count` is positive, returns unique members.
                - If `count` is negative, allows for duplicates members.

        Command response:
            List[List[Union[bytes, float]]]: A list of `[member, score]` lists, where `member` is a random member from
            the sorted set and `score` is the associated score.

            If the sorted set does not exist or is empty, the response will be an empty list.
        """
        return self.append_command(
            RequestType.ZRandMember, [key, str(count), "WITHSCORES"]
        )

    def zmpop(
        self: TTransaction,
        keys: List[TEncodable],
        filter: ScoreFilter,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Pops a member-score pair from the first non-empty sorted set, with the given keys being checked in the order
        that they are given. The optional `count` argument can be used to specify the number of elements to pop, and is
        set to 1 by default. The number of popped elements is the minimum from the sorted set's cardinality and `count`.

        See [valkey.io](https://valkey.io/commands/zmpop) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.
            modifier (ScoreFilter): The element pop criteria - either ScoreFilter.MIN or ScoreFilter.MAX to pop
                members with the lowest/highest scores accordingly.
            count (Optional[int]): The number of elements to pop.

        Command response:
            Optional[List[Union[bytes, Mapping[bytes, float]]]]: A two-element list containing the key name of the set from
            which elements were popped, and a member-score mapping of the popped elements.

            If no members could be popped, returns None.

        Since: Valkey version 7.0.0.
        """
        args = [str(len(keys))] + keys + [filter.value]
        if count is not None:
            args = args + ["COUNT", str(count)]

        return self.append_command(RequestType.ZMPop, args)

    def bzmpop(
        self: TTransaction,
        keys: List[TEncodable],
        modifier: ScoreFilter,
        timeout: float,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Pops a member-score pair from the first non-empty sorted set, with the given keys being checked in the order
        that they are given. Blocks the connection when there are no members to pop from any of the given sorted sets.

        The optional `count` argument can be used to specify the number of elements to pop, and is set to 1 by default.

        The number of popped elements is the minimum from the sorted set's cardinality and `count`.

        `BZMPOP` is the blocking variant of `ZMPOP`.

        See [valkey.io](https://valkey.io/commands/bzmpop) for more details.

        Note:
            `BZMPOP` is a client blocking command, see
            [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
            for more details and best practices.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets.
            modifier (ScoreFilter): The element pop criteria - either ScoreFilter.MIN or ScoreFilter.MAX to pop
                members with the lowest/highest scores accordingly.
            timeout (float): The number of seconds to wait for a blocking operation to complete. A value of 0 will
                block indefinitely.
            count (Optional[int]): The number of elements to pop.

        Command response:
            Optional[List[Union[bytes, Mapping[bytes, float]]]]: A two-element list containing the key name of the set from
            which elements were popped, and a member-score mapping.

            If no members could be popped and the timeout expired, returns None.

        Since: Valkey version 7.0.0.
        """
        args = [str(timeout), str(len(keys))] + keys + [modifier.value]
        if count is not None:
            args = args + ["COUNT", str(count)]

        return self.append_command(RequestType.BZMPop, args)

    def zintercard(
        self: TTransaction, keys: List[TEncodable], limit: Optional[int] = None
    ) -> TTransaction:
        """
        Returns the cardinality of the intersection of the sorted sets specified by `keys`. When provided with the
        optional `limit` argument, if the intersection cardinality reaches `limit` partway through the computation, the
        algorithm will exit early and yield `limit` as the cardinality.

        See [valkey.io](https://valkey.io/commands/zintercard) for more details.

        Args:
            keys (List[TEncodable]): The keys of the sorted sets to intersect.
            limit (Optional[int]): An optional argument that can be used to specify a maximum number for the
                intersection cardinality. If limit is not supplied, or if it is set to 0, there will be no limit.

        Command response:
            int: The cardinality of the intersection of the given sorted sets, or the `limit` if reached.

        Since: Valkey version 7.0.0.
        """
        args = [str(len(keys))] + keys
        if limit is not None:
            args.extend(["LIMIT", str(limit)])

        return self.append_command(RequestType.ZInterCard, args)

    def dbsize(self: TTransaction) -> TTransaction:
        """
        Returns the number of keys in the currently selected database.

        See [valkey.io](https://valkey.io/commands/dbsize) for more details.

        Commands response:
            int: The number of keys in the database.
        """
        return self.append_command(RequestType.DBSize, [])

    def pfadd(
        self: TTransaction, key: TEncodable, elements: List[TEncodable]
    ) -> TTransaction:
        """
        Adds all elements to the HyperLogLog data structure stored at the specified `key`.
        Creates a new structure if the `key` does not exist.
        When no elements are provided, and `key` exists and is a HyperLogLog, then no operation is performed.

        See [valkey.io](https://valkey.io/commands/pfadd/) for more details.

        Args:
            key (TEncodable): The key of the HyperLogLog data structure to add elements into.
            elements (List[TEncodable]): A list of members to add to the HyperLogLog stored at `key`.

        Commands response:
            int: If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is
            altered, then returns 1.

            Otherwise, returns 0.
        """
        return self.append_command(RequestType.PfAdd, [key] + elements)

    def pfcount(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
        """
        Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or
        calculates the combined cardinality of multiple keys by merging their HyperLogLogs temporarily.

        See [valkey.io](https://valkey.io/commands/pfcount) for more details.

        Args:
            keys (List[TEncodable]): The keys of the HyperLogLog data structures to be analyzed.

        Command response:
            int: The approximated cardinality of given HyperLogLog data structures.
            The cardinality of a key that does not exist is 0.
        """
        return self.append_command(RequestType.PfCount, keys)

    def pfmerge(
        self: TTransaction,
        destination: TEncodable,
        source_keys: List[TEncodable],
    ) -> TTransaction:
        """
        Merges multiple HyperLogLog values into a unique value. If the destination variable exists, it is treated as one
        of the source HyperLogLog data sets, otherwise a new HyperLogLog is created.

        See [valkey.io](https://valkey.io/commands/pfmerge) for more details.

        Args:
            destination (TEncodable): The key of the destination HyperLogLog where the merged data sets will be stored.
            source_keys (List[TEncodable]): The keys of the HyperLogLog structures to be merged.

        Command response:
            OK: A simple OK response.
        """
        return self.append_command(RequestType.PfMerge, [destination] + source_keys)

    def bitcount(
        self: TTransaction,
        key: TEncodable,
        options: Optional[OffsetOptions] = None,
    ) -> TTransaction:
        """
        Counts the number of set bits (population counting) in a string stored at `key`. The `options` argument can
        optionally be provided to count the number of bits in a specific string interval.

        See [valkey.io](https://valkey.io/commands/bitcount) for more details.

        Args:
            key (TEncodable): The key for the string to count the set bits of.
            options (Optional[OffsetOptions]): The offset options.

        Command response:
            int: If `options` is provided, returns the number of set bits in the string interval specified by `options`.

            If `options` is not provided, returns the number of set bits in the string stored at `key`.

            Otherwise, if `key` is missing, returns `0` as it is treated as an empty string.
        """
        args: List[TEncodable] = [key]
        if options is not None:
            args.extend(options.to_args())

        return self.append_command(RequestType.BitCount, args)

    def setbit(
        self: TTransaction, key: TEncodable, offset: int, value: int
    ) -> TTransaction:
        """
        Sets or clears the bit at `offset` in the string value stored at `key`. The `offset` is a zero-based index,
        with `0` being the first element of the list, `1` being the next element, and so on. The `offset` must be less
        than `2^32` and greater than or equal to `0`. If a key is non-existent then the bit at `offset` is set to
        `value` and the preceding bits are set to `0`.

        See [valkey.io](https://valkey.io/commands/setbit) for more details.

        Args:
            key (TEncodable): The key of the string.
            offset (int): The index of the bit to be set.
            value (int): The bit value to set at `offset`. The value must be `0` or `1`.

        Command response:
            int: The bit value that was previously stored at `offset`.
        """
        return self.append_command(RequestType.SetBit, [key, str(offset), str(value)])

    def getbit(self: TTransaction, key: TEncodable, offset: int) -> TTransaction:
        """
        Returns the bit value at `offset` in the string value stored at `key`.
        `offset` should be greater than or equal to zero.

        See [valkey.io](https://valkey.io/commands/getbit) for more details.

        Args:
            key (TEncodable): The key of the string.
            offset (int): The index of the bit to return.

        Command response:
            int: The bit at the given `offset` of the string.

            Returns `0` if the key is empty or if the `offset` exceeds the length of the string.
        """
        return self.append_command(RequestType.GetBit, [key, str(offset)])

    def bitpos(
        self: TTransaction,
        key: TEncodable,
        bit: int,
        options: Optional[OffsetOptions] = None,
    ) -> TTransaction:
        """
        Returns the position of the first bit matching the given `bit` value. The optional starting offset
        `start` is a zero-based index, with `0` being the first byte of the list, `1` being the next byte and so on.
        The offset can also be a negative number indicating an offset starting at the end of the list, with `-1` being
        the last byte of the list, `-2` being the penultimate, and so on.

        See [valkey.io](https://valkey.io/commands/bitpos) for more details.

        Args:
            key (TEncodable): The key of the string.
            bit (int): The bit value to match. Must be `0` or `1`.
            options (Optional[OffsetOptions]): The offset options.

        Command response:
            int: The position of the first occurrence of `bit` in the binary value of the string held at `key`.

            If `start` was provided, the search begins at the offset indicated by `start`.
        """
        args: List[TEncodable] = [key, str(bit)]
        if options is not None:
            args.extend(options.to_args())

        return self.append_command(RequestType.BitPos, args)

    def bitop(
        self: TTransaction,
        operation: BitwiseOperation,
        destination: TEncodable,
        keys: List[TEncodable],
    ) -> TTransaction:
        """
        Perform a bitwise operation between multiple keys (containing string values) and store the result in the
        `destination`.

        See [valkey.io](https://valkey.io/commands/bitop) for more details.

        Args:
            operation (BitwiseOperation): The bitwise operation to perform.
            destination (TEncodable): The key that will store the resulting string.
            keys (List[TEncodable]): The list of keys to perform the bitwise operation on.

        Command response:
            int: The size of the string stored in `destination`.
        """
        return self.append_command(
            RequestType.BitOp, [operation.value, destination] + keys
        )

    def bitfield(
        self: TTransaction,
        key: TEncodable,
        subcommands: List[BitFieldSubCommands],
    ) -> TTransaction:
        """
        Reads or modifies the array of bits representing the string that is held at `key` based on the specified
        `subcommands`.

        See [valkey.io](https://valkey.io/commands/bitfield) for more details.

        Args:
            key (TEncodable): The key of the string.
            subcommands (List[BitFieldSubCommands]): The subcommands to be performed on the binary value of the string
                at `key`, which could be any of the following:

                    - `BitFieldGet`
                    - `BitFieldSet`
                    - `BitFieldIncrBy`
                    - `BitFieldOverflow`

        Command response:
            List[Optional[int]]: An array of results from the executed subcommands:

                - `BitFieldGet` returns the value in `BitOffset` or `BitOffsetMultiplier`.
                - `BitFieldSet` returns the old value in `BitOffset` or `BitOffsetMultiplier`.
                - `BitFieldIncrBy` returns the new value in `BitOffset` or `BitOffsetMultiplier`.
                - `BitFieldOverflow` determines the behavior of the "SET" and "INCRBY" subcommands when an overflow or
                  underflow occurs. "OVERFLOW" does not return a value and does not contribute a value to the list
                  response.
        """
        args = [key] + _create_bitfield_args(subcommands)
        return self.append_command(RequestType.BitField, args)

    def bitfield_read_only(
        self: TTransaction, key: TEncodable, subcommands: List[BitFieldGet]
    ) -> TTransaction:
        """
        Reads the array of bits representing the string that is held at `key` based on the specified `subcommands`.

        See [valkey.io](https://valkey.io/commands/bitfield_ro) for more details.

        Args:
            key (TEncodable): The key of the string.
            subcommands (List[BitFieldGet]): The "GET" subcommands to be performed.

        Command response:
            List[int]: An array of results from the "GET" subcommands.

        Since: Valkey version 6.0.0.
        """
        args = [key] + _create_bitfield_read_only_args(subcommands)
        return self.append_command(RequestType.BitFieldReadOnly, args)

    def object_encoding(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the internal encoding for the Valkey object stored at `key`.

        See [valkey.io](https://valkey.io/commands/object-encoding) for more details.

        Args:
            key (TEncodable): The `key` of the object to get the internal encoding of.

        Command response:
            Optional[bytes]: If `key` exists, returns the internal encoding of the object stored at
            `key` as a bytes string.

            Otherwise, returns None.
        """
        return self.append_command(RequestType.ObjectEncoding, [key])

    def object_freq(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the logarithmic access frequency counter of a Valkey object stored at `key`.

        See [valkey.io](https://valkey.io/commands/object-freq) for more details.

        Args:
            key (TEncodable): The key of the object to get the logarithmic access frequency counter of.

        Command response:
            Optional[int]: If `key` exists, returns the logarithmic access frequency counter of the object stored at `key` as
            an integer.

            Otherwise, returns None.
        """
        return self.append_command(RequestType.ObjectFreq, [key])

    def object_idletime(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the time in seconds since the last access to the value stored at `key`.

        See [valkey.io](https://valkey.io/commands/object-idletime) for more details.

        Args:
            key (TEncodable): The key of the object to get the idle time of.

        Command response:
            Optional[int]: If `key` exists, returns the idle time in seconds.

            Otherwise, returns None.
        """
        return self.append_command(RequestType.ObjectIdleTime, [key])

    def object_refcount(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns the reference count of the object stored at `key`.

        See [valkey.io](https://valkey.io/commands/object-refcount) for more details.

        Args:
            key (TEncodable): The key of the object to get the reference count of.

        Command response:
            Optional[int]: If `key` exists, returns the reference count of the object stored at `key` as an integer.

            Otherwise, returns None.
        """
        return self.append_command(RequestType.ObjectRefCount, [key])

    def srandmember(self: TTransaction, key: TEncodable) -> TTransaction:
        """
        Returns a random element from the set value stored at 'key'.

        See [valkey.io](https://valkey.io/commands/srandmember) for more details.

        Args:
            key (TEncodable): The key from which to retrieve the set member.

        Command Response:
            bytes: A random element from the set.

            `None` if 'key' does not exist.
        """
        return self.append_command(RequestType.SRandMember, [key])

    def srandmember_count(
        self: TTransaction, key: TEncodable, count: int
    ) -> TTransaction:
        """
        Returns one or more random elements from the set value stored at 'key'.

        See [valkey.io](https://valkey.io/commands/srandmember) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            count (int): The number of members to return.

                - If `count` is positive, returns unique members.
                - If `count` is negative, allows for duplicates members.

        Command Response:
            List[TEncodable]: A list of members from the set.

            If the set does not exist or is empty, the response will be an empty list.
        """
        return self.append_command(RequestType.SRandMember, [key, str(count)])

    def flushall(
        self: TTransaction, flush_mode: Optional[FlushMode] = None
    ) -> TTransaction:
        """
        Deletes all the keys of all the existing databases. This command never fails.

        See [valkey.io](https://valkey.io/commands/flushall) for more details.

        Args:
            flush_mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.

        Command Response:
            TOK: OK.
        """
        args: List[TEncodable] = []
        if flush_mode is not None:
            args.append(flush_mode.value)
        return self.append_command(RequestType.FlushAll, args)

    def flushdb(
        self: TTransaction, flush_mode: Optional[FlushMode] = None
    ) -> TTransaction:
        """
        Deletes all the keys of the currently selected database. This command never fails.

        See [valkey.io](https://valkey.io/commands/flushdb) for more details.

        Args:
            flush_mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.

        Command Response:
            TOK: OK.
        """
        args: List[TEncodable] = []
        if flush_mode is not None:
            args.append(flush_mode.value)
        return self.append_command(RequestType.FlushDB, args)

    def getex(
        self: TTransaction, key: TEncodable, expiry: Optional[ExpiryGetEx] = None
    ) -> TTransaction:
        """
        Get the value of `key` and optionally set its expiration. GETEX is similar to GET.

        See [valkey.io](https://valkey.io/commands/getex) for more details.

        Args:
            key (TEncodable): The key to get.
            expiry (Optional[ExpirySet], optional): set expiriation to the given key.
                Equivalent to [`EX` | `PX` | `EXAT` | `PXAT` | `PERSIST`] in the Valkey API.

        Command Response:
            Optional[bytes]: If `key` exists, return the value stored at `key`

            If 'key` does not exist, return 'None'

        Since: Valkey version 6.2.0.
        """
        args: List[TEncodable] = [key]
        if expiry is not None:
            args.extend(expiry.get_cmd_args())
        return self.append_command(RequestType.GetEx, args)

    def lolwut(
        self: TTransaction,
        version: Optional[int] = None,
        parameters: Optional[List[int]] = None,
    ) -> TTransaction:
        """
        Displays a piece of generative computer art and the Valkey version.

        See [valkey.io](https://valkey.io/commands/lolwut) for more details.

        Args:
            version (Optional[int]): Version of computer art to generate.
            parameters (Optional[List[int]]): Additional set of arguments in order to change the output:

                - For version `5`, those are length of the line, number of squares per row, and number of squares per column.
                - For version `6`, those are number of columns and number of lines.

        Command Response:
            bytes: A piece of generative computer art along with the current Valkey version.
        """
        args: List[TEncodable] = []
        if version is not None:
            args.extend(["VERSION", str(version)])
        if parameters:
            for var in parameters:
                args.extend(str(var))
        return self.append_command(RequestType.Lolwut, args)

    def random_key(self: TTransaction) -> TTransaction:
        """
        Returns a random existing key name.

        See [valkey.io](https://valkey.io/commands/randomkey) for more details.

        Command response:
            Optional[bytes]: A random existing key name.
        """
        return self.append_command(RequestType.RandomKey, [])

    def sscan(
        self: TTransaction,
        key: TEncodable,
        cursor: TEncodable,
        match: Optional[TEncodable] = None,
        count: Optional[int] = None,
    ) -> TTransaction:
        """
        Iterates incrementally over a set.

        See [valkey.io](https://valkey.io/commands/sscan) for more details.

        Args:
            key (TEncodable): The key of the set.
            cursor (TEncodable): The cursor that points to the next iteration of results. A value of "0" indicates the start of
                the search.
            match (Optional[TEncodable]): The match filter is applied to the result of the command and will only include
                strings or bytes strings that match the pattern specified. If the set is large enough for scan commands to
                return only a subset of the set then there could be a case where the result is empty although there are items
                that match the pattern specified. This is due to the default `COUNT` being `10` which indicates that it will
                only fetch and match `10` items from the list.
            count (Optional[int]): `COUNT` is a just a hint for the command for how many elements to fetch from the set.
                `COUNT` could be ignored until the set is large enough for the `SCAN` commands to represent the results
                as compact single-allocation packed encoding.

        Command Response:
            List[Union[bytes, List[bytes]]]: An `Array` of the `cursor` and the subset of the set held by `key`.
            The first element is always the `cursor` for the next iteration of results. `0` will be the `cursor`
            returned on the last iteration of the set. The second element is always an `Array` of the subset of the
            set held in `key`.
        """
        args = [key, cursor]
        if match is not None:
            args += ["MATCH", match]
        if count is not None:
            args += ["COUNT", str(count)]

        return self.append_command(RequestType.SScan, args)

    def zscan(
        self: TTransaction,
        key: TEncodable,
        cursor: TEncodable,
        match: Optional[TEncodable] = None,
        count: Optional[int] = None,
        no_scores: bool = False,
    ) -> TTransaction:
        """
        Iterates incrementally over a sorted set.

        See [valkey.io](https://valkey.io/commands/zscan) for more details.

        Args:
            key (TEncodable): The key of the sorted set.
            cursor (TEncodable): The cursor that points to the next iteration of results. A value of "0" indicates the start of
                the search.
            match (Optional[TEncodable]): The match filter is applied to the result of the command and will only include
                strings or byte strings that match the pattern specified. If the sorted set is large enough for scan commands
                to return only a subset of the sorted set then there could be a case where the result is empty although there
                are items that match the pattern specified. This is due to the default `COUNT` being `10` which indicates
                that it will only fetch and match `10` items from the list.
            count (Optional[int]): `COUNT` is a just a hint for the command for how many elements to fetch from the
                sorted set. `COUNT` could be ignored until the sorted set is large enough for the `SCAN` commands to
                represent the results as compact single-allocation packed encoding.
            no_scores (bool): If `True`, the command will not return scores associated with the members. Since Valkey "8.0.0".

        Returns:
            List[Union[bytes, List[bytes]]]: An `Array` of the `cursor` and the subset of the sorted set held by `key`.
            The first element is always the `cursor` for the next iteration of results. `0` will be the `cursor`
            returned on the last iteration of the sorted set. The second element is always an `Array` of the subset
            of the sorted set held in `key`. The `Array` in the second element is a flattened series of
            `String` pairs, where the value is at even indices and the score is at odd indices.

            If `no_scores` is set to`True`, the second element will only contain the members without scores.
        """
        args = [key, cursor]
        if match is not None:
            args += ["MATCH", match]
        if count is not None:
            args += ["COUNT", str(count)]
        if no_scores:
            args.append("NOSCORES")

        return self.append_command(RequestType.ZScan, args)

    def hscan(
        self: TTransaction,
        key: TEncodable,
        cursor: TEncodable,
        match: Optional[TEncodable] = None,
        count: Optional[int] = None,
        no_values: bool = False,
    ) -> TTransaction:
        """
        Iterates incrementally over a hash.

        See [valkey.io](https://valkey.io/commands/hscan) for more details.

        Args:
            key (TEncodable): The key of the set.
            cursor (TEncodable): The cursor that points to the next iteration of results. A value of "0" indicates the start of
                the search.
            match (Optional[TEncodable]): The match filter is applied to the result of the command and will only include
                strings or byte strings that match the pattern specified. If the hash is large enough for scan commands to
                return only a subset of the hash then there could be a case where the result is empty although there are
                items that match the pattern specified. This is due to the default `COUNT` being `10` which indicates that
                it will only fetch and match `10` items from the list.
            count (Optional[int]): `COUNT` is a just a hint for the command for how many elements to fetch from the hash.
                `COUNT` could be ignored until the hash is large enough for the `SCAN` commands to represent the results
                as compact single-allocation packed encoding.
            no_values (bool): If `True`, the command will not return values the fields in the hash. Since Valkey "8.0.0".

        Returns:
            List[Union[bytes, List[bytes]]]: An `Array` of the `cursor` and the subset of the hash held by `key`.
            The first element is always the `cursor` for the next iteration of results. `0` will be the `cursor`
            returned on the last iteration of the hash. The second element is always an `Array` of the subset of the
            hash held in `key`. The `Array` in the second element is a flattened series of `String` pairs,
            where the value is at even indices and the score is at odd indices.

            If `no_values` is set to `True`, the second element will only contain the fields without the values.
        """
        args = [key, cursor]
        if match is not None:
            args += ["MATCH", match]
        if count is not None:
            args += ["COUNT", str(count)]
        if no_values:
            args.append("NOVALUES")

        return self.append_command(RequestType.HScan, args)

    def lcs(
        self: TTransaction,
        key1: TEncodable,
        key2: TEncodable,
    ) -> TTransaction:
        """
        Returns the longest common subsequence between strings stored at key1 and key2.

        Note:
            This is different than the longest common string algorithm, since
            matching characters in the two strings do not need to be contiguous.

            For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings
            from left to right, the longest common set of characters is composed of the first "f" and then the "o".

        See [valkey.io](https://valkey.io/commands/lcs) for more details.

        Args:
            key1 (TEncodable): The key that stores the first value.
            key2 (TEncodable): The key that stores the second value.

        Command Response:
            A Bytes String containing the longest common subsequence between the 2 strings.

            An empty Bytes String is returned if the keys do not exist or have no common subsequences.

        Since: Valkey version 7.0.0.
        """
        args = [key1, key2]

        return self.append_command(RequestType.LCS, args)

    def lcs_len(
        self: TTransaction,
        key1: TEncodable,
        key2: TEncodable,
    ) -> TTransaction:
        """
        Returns the length of the longest common subsequence between strings stored at key1 and key2.

        Note:
            This is different than the longest common string algorithm, since
            matching characters in the two strings do not need to be contiguous.

            For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings
            from left to right, the longest common set of characters is composed of the first "f" and then the "o".

        See [valkey.io](https://valkey.io/commands/lcs) for more details.

        Args:
            key1 (TEncodable): The key that stores the first value.
            key2 (TEncodable): The key that stores the second value.

        Command Response:
            The length of the longest common subsequence between the 2 strings.

        Since: Valkey version 7.0.0.
        """
        args = [key1, key2, "LEN"]

        return self.append_command(RequestType.LCS, args)

    def lcs_idx(
        self: TTransaction,
        key1: TEncodable,
        key2: TEncodable,
        min_match_len: Optional[int] = None,
        with_match_len: Optional[bool] = False,
    ) -> TTransaction:
        """
        Returns the indices and length of the longest common subsequence between strings stored at key1 and key2.

        Note:
            This is different than the longest common string algorithm, since
            matching characters in the two strings do not need to be contiguous.

            For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings
            from left to right, the longest common set of characters is composed of the first "f" and then the "o".

        See [valkey.io](https://valkey.io/commands/lcs) for more details.

        Args:
            key1 (TEncodable): The key that stores the first value.
            key2 (TEncodable): The key that stores the second value.
            min_match_len (Optional[int]): The minimum length of matches to include in the result.
            with_match_len (Optional[bool]): If True, include the length of the substring matched for each substring.

        Command Response:
            A Map containing the indices of the longest common subsequence between the
            2 strings and the length of the longest common subsequence. The resulting map contains two
            keys, "matches" and "len":

                - "len" is mapped to the length of the longest common subsequence between the 2 strings.
                - "matches" is mapped to a three dimensional int array that stores pairs of indices that
                  represent the location of the common subsequences in the strings held by key1 and key2,
                  with the length of the match after each matches, if with_match_len is enabled.

        Since: Valkey version 7.0.0.
        """
        args = [key1, key2, "IDX"]

        if min_match_len is not None:
            args.extend(["MINMATCHLEN", str(min_match_len)])

        if with_match_len:
            args.append("WITHMATCHLEN")

        return self.append_command(RequestType.LCS, args)

    def wait(
        self: TTransaction,
        numreplicas: int,
        timeout: int,
    ) -> TTransaction:
        """
        Returns the number of replicas that acknowledged the write commands sent by the current client
        before this command, both in the case where the specified number of replicas are reached, or
        when the timeout is reached.

        See [valkey.io](https://valkey.io/commands/wait) for more details.

        Args:
            numreplicas (int): The number of replicas to reach.
            timeout (int): The timeout value specified in milliseconds.

        Command Response:
            bytes: The number of replicas reached by all the writes performed in the context of the current connection.
        """
        args: List[TEncodable] = [str(numreplicas), str(timeout)]
        return self.append_command(RequestType.Wait, args)

    def lpos(
        self: TTransaction,
        key: TEncodable,
        element: TEncodable,
        rank: Optional[int] = None,
        count: Optional[int] = None,
        max_len: Optional[int] = None,
    ) -> TTransaction:
        """
        Returns the index or indexes of element(s) matching `element` in the `key` list. If no match is found,
        None is returned.

        See [valkey.io](https://valkey.io/commands/lpos) for more details.

        Args:
            key (TEncodable): The name of the list.
            element (TEncodable): The value to search for within the list.
            rank (Optional[int]): The rank of the match to return.
            count (Optional[int]): The number of matches wanted. A `count` of 0 returns all the matches.
            max_len (Optional[int]): The maximum number of comparisons to make between the element and the items
                in the list. A `max_len` of 0 means unlimited amount of comparisons.

        Command Response:
            Union[int, List[int], None]: The index of the first occurrence of `element`.

            None if `element` is not in the list.

            With the `count` option, a list of indices of matching elements will be returned.

        Since: Valkey version 6.0.6.
        """
        args = [key, element]

        if rank is not None:
            args.extend(["RANK", str(rank)])

        if count is not None:
            args.extend(["COUNT", str(count)])

        if max_len is not None:
            args.extend(["MAXLEN", str(max_len)])

        return self.append_command(RequestType.LPos, args)

    def xclaim(
        self: TTransaction,
        key: TEncodable,
        group: TEncodable,
        consumer: TEncodable,
        min_idle_time_ms: int,
        ids: List[TEncodable],
        options: Optional[StreamClaimOptions] = None,
    ) -> TTransaction:
        """
        Changes the ownership of a pending message.

        See [valkey.io](https://valkey.io/commands/xclaim) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group (TEncodable): The consumer group name.
            consumer (TEncodable): The group consumer.
            min_idle_time_ms (int): The minimum idle time for the message to be claimed.
            ids (List[TEncodable]): A array of entry ids.
            options (Optional[StreamClaimOptions]): Stream claim options.

        Returns:
            A Mapping of message entries with the format::

                {"entryId": [["entry", "data"], ...], ...}

            that are claimed by the consumer.
        """

        args = [key, group, consumer, str(min_idle_time_ms), *ids]

        if options:
            args.extend(options.to_args())

        return self.append_command(RequestType.XClaim, args)

    def xclaim_just_id(
        self: TTransaction,
        key: TEncodable,
        group: TEncodable,
        consumer: TEncodable,
        min_idle_time_ms: int,
        ids: List[TEncodable],
        options: Optional[StreamClaimOptions] = None,
    ) -> TTransaction:
        """
        Changes the ownership of a pending message. This function returns a List with
        only the message/entry IDs, and is equivalent to using JUSTID in the Valkey API.

        See [valkey.io](https://valkey.io/commands/xclaim) for more details.

        Args:
            key (TEncodable): The key of the stream.
            group (TEncodable): The consumer group name.
            consumer (TEncodable): The group consumer.
            min_idle_time_ms (int): The minimum idle time for the message to be claimed.
            ids (List[TEncodable]): A array of entry ids.
            options (Optional[StreamClaimOptions]): Stream claim options.

        Returns:
            A List of message ids claimed by the consumer.
        """

        args = [
            key,
            group,
            consumer,
            str(min_idle_time_ms),
            *ids,
            StreamClaimOptions.JUST_ID_VALKEY_API,
        ]

        if options:
            args.extend(options.to_args())

        return self.append_command(RequestType.XClaim, args)

    def pubsub_channels(
        self: TTransaction, pattern: Optional[TEncodable] = None
    ) -> TTransaction:
        """
        Lists the currently active channels.

        See [valkey.io](https://valkey.io/commands/pubsub-channels) for details.

        Args:
            pattern (Optional[TEncodable]): A glob-style pattern to match active channels.
                If not provided, all active channels are returned.

        Command response:
            List[bytes]: A list of currently active channels matching the given pattern.

            If no pattern is specified, all active channels are returned.
        """

        return self.append_command(
            RequestType.PubSubChannels, [pattern] if pattern else []
        )

    def pubsub_numpat(self: TTransaction) -> TTransaction:
        """
        Returns the number of unique patterns that are subscribed to by clients.

        Note:
            This is the total number of unique patterns all the clients are subscribed to,
            not the count of clients subscribed to patterns.

        See [valkey.io](https://valkey.io/commands/pubsub-numpat) for details.

        Command response:
            int: The number of unique patterns.
        """
        return self.append_command(RequestType.PubSubNumPat, [])

    def pubsub_numsub(
        self: TTransaction, channels: Optional[List[TEncodable]] = None
    ) -> TTransaction:
        """
        Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.

        Note:
            It is valid to call this command without channels. In this case, it will just return an empty map.

        See [valkey.io](https://valkey.io/commands/pubsub-numsub) for details.

        Args:
            channels (Optional[List[str]]): The list of channels to query for the number of subscribers.
                If not provided, returns an empty map.

        Command response:
            Mapping[bytes, int]: A map where keys are the channel names and values are the number of subscribers.
        """
        return self.append_command(
            RequestType.PubSubNumSub, channels if channels else []
        )

    def sort(
        self: TTransaction,
        key: TEncodable,
        by_pattern: Optional[TEncodable] = None,
        limit: Optional[Limit] = None,
        get_patterns: Optional[List[TEncodable]] = None,
        order: Optional[OrderBy] = None,
        alpha: Optional[bool] = None,
    ) -> TTransaction:
        """
        Sorts the elements in the list, set, or sorted set at `key` and returns the result.
        The `sort` command can be used to sort elements based on different criteria and apply transformations on sorted
        elements.
        To store the result into a new key, see `sort_store`.

        See [valkey.io](https://valkey.io/commands/sort) for more details.

        Note:
            When in cluster mode, `key`, and any patterns specified in `by_pattern` or `get_patterns`
            must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
            only since Valkey version 8.0.

        Args:
            key (TEncodable): The key of the list, set, or sorted set to be sorted.
            by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key
                themselves.
                The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
                from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects,
                `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or
                timestamps.
                E.g., if `by_pattern` is `weight_*`, the command will sort the elements by the values of the
                keys `weight_<element>`.
                If not provided, elements are sorted by their value.
                Supported in cluster mode since Valkey version 8.0.
            limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for
                more information.
            get_patterns (Optional[List[TEncodable]]): A pattern used to retrieve external keys' values, instead of the
                elements at `key`.
                The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
                from `key` replaces the asterisk to create the key name. This allows the sorted elements to be
                transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern`
                can be used to retrieve specific attributes of these users, such as their names or email addresses.
                E.g., if `get_pattern` is `name_*`, the command will return the values of the keys `name_<element>`
                for each sorted element. Multiple `get_pattern` arguments can be provided to retrieve multiple attributes.
                The special value `#` can be used to include the actual element from `key` being sorted.
                If not provided, only the sorted elements themselves are returned.
                Supported in cluster mode since Valkey version 8.0.
            order (Optional[OrderBy]): Specifies the order to sort the elements.
                Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending).
            alpha (Optional[bool]): When `True`, sorts elements lexicographically. When `False` (default),
                sorts elements numerically.
                Use this when the list, set, or sorted set contains string values that cannot be converted into
                double precision floating point numbers.

        Command response:
            List[Optional[bytes]]: Returns a list of sorted elements.
        """
        args = _build_sort_args(key, by_pattern, limit, get_patterns, order, alpha)
        return self.append_command(RequestType.Sort, args)

    def sort_ro(
        self: TTransaction,
        key: TEncodable,
        by_pattern: Optional[TEncodable] = None,
        limit: Optional[Limit] = None,
        get_patterns: Optional[List[TEncodable]] = None,
        order: Optional[OrderBy] = None,
        alpha: Optional[bool] = None,
    ) -> TTransaction:
        """
        Sorts the elements in the list, set, or sorted set at `key` and returns the result.
        The `sort_ro` command can be used to sort elements based on different criteria and apply transformations
        on sorted elements.
        This command is routed depending on the client's `ReadFrom` strategy.

        See [valkey.io](https://valkey.io/commands/sort) for more details.

        Note:
            When in cluster mode, `key`, and any patterns specified in `by_pattern` or `get_patterns`
            must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
            only since Valkey version 8.0.

        Args:
            key (TEncodable): The key of the list, set, or sorted set to be sorted.
            by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key
                themselves.
                The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
                from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects,
                `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or
                timestamps.
                E.g., if `by_pattern` is `weight_*`, the command will sort the elements by the values of the
                keys `weight_<element>`.
                If not provided, elements are sorted by their value.
                Supported in cluster mode since Valkey version 8.0.
            limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for
                more information.
            get_patterns (Optional[List[TEncodable]]): A pattern used to retrieve external keys' values, instead of the
                elements at `key`.
                The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
                from `key` replaces the asterisk to create the key name. This allows the sorted elements to be
                transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern`
                can be used to retrieve specific attributes of these users, such as their names or email addresses.
                E.g., if `get_pattern` is `name_*`, the command will return the values of the keys `name_<element>`
                for each sorted element. Multiple `get_pattern` arguments can be provided to retrieve multiple attributes.
                The special value `#` can be used to include the actual element from `key` being sorted.
                If not provided, only the sorted elements themselves are returned.
                Supported in cluster mode since Valkey version 8.0.
            order (Optional[OrderBy]): Specifies the order to sort the elements.
                Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending).
            alpha (Optional[bool]): When `True`, sorts elements lexicographically. When `False` (default), sorts elements
                numerically.
                Use this when the list, set, or sorted set contains string values that cannot be converted into double
                precision floating point numbers.

        Command response:
            List[Optional[bytes]]: Returns a list of sorted elements.

        Since: Valkey version 7.0.0.
        """
        args = _build_sort_args(key, by_pattern, limit, get_patterns, order, alpha)
        return self.append_command(RequestType.SortReadOnly, args)

    def sort_store(
        self: TTransaction,
        key: TEncodable,
        destination: TEncodable,
        by_pattern: Optional[TEncodable] = None,
        limit: Optional[Limit] = None,
        get_patterns: Optional[List[TEncodable]] = None,
        order: Optional[OrderBy] = None,
        alpha: Optional[bool] = None,
    ) -> TTransaction:
        """
        Sorts the elements in the list, set, or sorted set at `key` and stores the result in `store`.
        The `sort` command can be used to sort elements based on different criteria, apply transformations on sorted elements,
        and store the result in a new key.
        To get the sort result without storing it into a key, see `sort`.

        See [valkey.io](https://valkey.io/commands/sort) for more details.

        Note:
            When in cluster mode, `key`, `destination`, and any patterns specified in `by_pattern` or `get_patterns`
            must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
            only since Valkey version 8.0.

        Args:
            key (TEncodable): The key of the list, set, or sorted set to be sorted.
            destination (TEncodable): The key where the sorted result will be stored.
            by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key
                themselves.
                The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
                from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects,
                `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or
                timestamps.
                E.g., if `by_pattern` is `weight_*`, the command will sort the elements by the values of the
                keys `weight_<element>`.
                If not provided, elements are sorted by their value.
                Supported in cluster mode since Valkey version 8.0.
            limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for
                more information.
            get_patterns (Optional[List[TEncodable]]): A pattern used to retrieve external keys' values, instead of the
                elements at `key`.
                The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
                from `key` replaces the asterisk to create the key name. This allows the sorted elements to be
                transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern`
                can be used to retrieve specific attributes of these users, such as their names or email addresses.
                E.g., if `get_pattern` is `name_*`, the command will return the values of the keys `name_<element>`
                for each sorted element. Multiple `get_pattern` arguments can be provided to retrieve multiple attributes.
                The special value `#` can be used to include the actual element from `key` being sorted.
                If not provided, only the sorted elements themselves are returned.
                Supported in cluster mode since Valkey version 8.0.
            order (Optional[OrderBy]): Specifies the order to sort the elements.
                Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending).
            alpha (Optional[bool]): When `True`, sorts elements lexicographically. When `False` (default), sorts elements
                numerically.
                Use this when the list, set, or sorted set contains string values that cannot be converted into double
                precision floating point numbers.

        Command response:
            int: The number of elements in the sorted key stored at `store`.
        """
        args = _build_sort_args(
            key, by_pattern, limit, get_patterns, order, alpha, store=destination
        )
        return self.append_command(RequestType.Sort, args)

append(key, value)

Appends a value to a key. If key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to which the value will be appended.

required
value TEncodable

The value to append.

required
Commands response

int: The length of the string after appending the value.

Source code in glide/async_commands/transaction.py
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def append(self: TTransaction, key: TEncodable, value: TEncodable) -> TTransaction:
    """
    Appends a value to a key.
    If `key` does not exist it is created and set as an empty string, so `APPEND` will be similar to
    SET in this special case.

    See [valkey.io](https://valkey.io/commands/append) for more details.

    Args:
        key (TEncodable): The key to which the value will be appended.
        value (TEncodable): The value to append.

    Commands response:
        int: The length of the string after appending the value.
    """
    return self.append_command(RequestType.Append, [key, value])

bitcount(key, options=None)

Counts the number of set bits (population counting) in a string stored at key. The options argument can optionally be provided to count the number of bits in a specific string interval.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key for the string to count the set bits of.

required
options Optional[OffsetOptions]

The offset options.

None
Command response

int: If options is provided, returns the number of set bits in the string interval specified by options.

If options is not provided, returns the number of set bits in the string stored at key.

Otherwise, if key is missing, returns 0 as it is treated as an empty string.

Source code in glide/async_commands/transaction.py
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
def bitcount(
    self: TTransaction,
    key: TEncodable,
    options: Optional[OffsetOptions] = None,
) -> TTransaction:
    """
    Counts the number of set bits (population counting) in a string stored at `key`. The `options` argument can
    optionally be provided to count the number of bits in a specific string interval.

    See [valkey.io](https://valkey.io/commands/bitcount) for more details.

    Args:
        key (TEncodable): The key for the string to count the set bits of.
        options (Optional[OffsetOptions]): The offset options.

    Command response:
        int: If `options` is provided, returns the number of set bits in the string interval specified by `options`.

        If `options` is not provided, returns the number of set bits in the string stored at `key`.

        Otherwise, if `key` is missing, returns `0` as it is treated as an empty string.
    """
    args: List[TEncodable] = [key]
    if options is not None:
        args.extend(options.to_args())

    return self.append_command(RequestType.BitCount, args)

bitfield(key, subcommands)

Reads or modifies the array of bits representing the string that is held at key based on the specified subcommands.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the string.

required
subcommands List[BitFieldSubCommands]

The subcommands to be performed on the binary value of the string at key, which could be any of the following:

- `BitFieldGet`
- `BitFieldSet`
- `BitFieldIncrBy`
- `BitFieldOverflow`
required
Command response

List[Optional[int]]: An array of results from the executed subcommands:

- `BitFieldGet` returns the value in `BitOffset` or `BitOffsetMultiplier`.
- `BitFieldSet` returns the old value in `BitOffset` or `BitOffsetMultiplier`.
- `BitFieldIncrBy` returns the new value in `BitOffset` or `BitOffsetMultiplier`.
- `BitFieldOverflow` determines the behavior of the "SET" and "INCRBY" subcommands when an overflow or
  underflow occurs. "OVERFLOW" does not return a value and does not contribute a value to the list
  response.
Source code in glide/async_commands/transaction.py
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
def bitfield(
    self: TTransaction,
    key: TEncodable,
    subcommands: List[BitFieldSubCommands],
) -> TTransaction:
    """
    Reads or modifies the array of bits representing the string that is held at `key` based on the specified
    `subcommands`.

    See [valkey.io](https://valkey.io/commands/bitfield) for more details.

    Args:
        key (TEncodable): The key of the string.
        subcommands (List[BitFieldSubCommands]): The subcommands to be performed on the binary value of the string
            at `key`, which could be any of the following:

                - `BitFieldGet`
                - `BitFieldSet`
                - `BitFieldIncrBy`
                - `BitFieldOverflow`

    Command response:
        List[Optional[int]]: An array of results from the executed subcommands:

            - `BitFieldGet` returns the value in `BitOffset` or `BitOffsetMultiplier`.
            - `BitFieldSet` returns the old value in `BitOffset` or `BitOffsetMultiplier`.
            - `BitFieldIncrBy` returns the new value in `BitOffset` or `BitOffsetMultiplier`.
            - `BitFieldOverflow` determines the behavior of the "SET" and "INCRBY" subcommands when an overflow or
              underflow occurs. "OVERFLOW" does not return a value and does not contribute a value to the list
              response.
    """
    args = [key] + _create_bitfield_args(subcommands)
    return self.append_command(RequestType.BitField, args)

bitfield_read_only(key, subcommands)

Reads the array of bits representing the string that is held at key based on the specified subcommands.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the string.

required
subcommands List[BitFieldGet]

The "GET" subcommands to be performed.

required
Command response

List[int]: An array of results from the "GET" subcommands.

Since: Valkey version 6.0.0.

Source code in glide/async_commands/transaction.py
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
def bitfield_read_only(
    self: TTransaction, key: TEncodable, subcommands: List[BitFieldGet]
) -> TTransaction:
    """
    Reads the array of bits representing the string that is held at `key` based on the specified `subcommands`.

    See [valkey.io](https://valkey.io/commands/bitfield_ro) for more details.

    Args:
        key (TEncodable): The key of the string.
        subcommands (List[BitFieldGet]): The "GET" subcommands to be performed.

    Command response:
        List[int]: An array of results from the "GET" subcommands.

    Since: Valkey version 6.0.0.
    """
    args = [key] + _create_bitfield_read_only_args(subcommands)
    return self.append_command(RequestType.BitFieldReadOnly, args)

bitop(operation, destination, keys)

Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination.

See valkey.io for more details.

Parameters:

Name Type Description Default
operation BitwiseOperation

The bitwise operation to perform.

required
destination TEncodable

The key that will store the resulting string.

required
keys List[TEncodable]

The list of keys to perform the bitwise operation on.

required
Command response

int: The size of the string stored in destination.

Source code in glide/async_commands/transaction.py
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
def bitop(
    self: TTransaction,
    operation: BitwiseOperation,
    destination: TEncodable,
    keys: List[TEncodable],
) -> TTransaction:
    """
    Perform a bitwise operation between multiple keys (containing string values) and store the result in the
    `destination`.

    See [valkey.io](https://valkey.io/commands/bitop) for more details.

    Args:
        operation (BitwiseOperation): The bitwise operation to perform.
        destination (TEncodable): The key that will store the resulting string.
        keys (List[TEncodable]): The list of keys to perform the bitwise operation on.

    Command response:
        int: The size of the string stored in `destination`.
    """
    return self.append_command(
        RequestType.BitOp, [operation.value, destination] + keys
    )

bitpos(key, bit, options=None)

Returns the position of the first bit matching the given bit value. The optional starting offset start is a zero-based index, with 0 being the first byte of the list, 1 being the next byte and so on. The offset can also be a negative number indicating an offset starting at the end of the list, with -1 being the last byte of the list, -2 being the penultimate, and so on.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the string.

required
bit int

The bit value to match. Must be 0 or 1.

required
options Optional[OffsetOptions]

The offset options.

None
Command response

int: The position of the first occurrence of bit in the binary value of the string held at key.

If start was provided, the search begins at the offset indicated by start.

Source code in glide/async_commands/transaction.py
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
def bitpos(
    self: TTransaction,
    key: TEncodable,
    bit: int,
    options: Optional[OffsetOptions] = None,
) -> TTransaction:
    """
    Returns the position of the first bit matching the given `bit` value. The optional starting offset
    `start` is a zero-based index, with `0` being the first byte of the list, `1` being the next byte and so on.
    The offset can also be a negative number indicating an offset starting at the end of the list, with `-1` being
    the last byte of the list, `-2` being the penultimate, and so on.

    See [valkey.io](https://valkey.io/commands/bitpos) for more details.

    Args:
        key (TEncodable): The key of the string.
        bit (int): The bit value to match. Must be `0` or `1`.
        options (Optional[OffsetOptions]): The offset options.

    Command response:
        int: The position of the first occurrence of `bit` in the binary value of the string held at `key`.

        If `start` was provided, the search begins at the offset indicated by `start`.
    """
    args: List[TEncodable] = [key, str(bit)]
    if options is not None:
        args.extend(options.to_args())

    return self.append_command(RequestType.BitPos, args)

blmove(source, destination, where_from, where_to, timeout)

Blocks the connection until it pops atomically and removes the left/right-most element to the list stored at source depending on where_from, and pushes the element at the first/last element of the list stored at destination depending on where_to. blmove is the blocking variant of lmove.

See valkey.io for details.

Parameters:

Name Type Description Default
source TEncodable

The key to the source list.

required
destination TEncodable

The key to the destination list.

required
where_from ListDirection

The direction to remove the element from (ListDirection.LEFT or ListDirection.RIGHT).

required
where_to ListDirection

The direction to add the element to (ListDirection.LEFT or ListDirection.RIGHT).

required
timeout float

The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.

required
Command response

Optional[bytes]: The popped element.

None if source does not exist or if the operation timed-out.

Since: Valkey version 6.2.0.

Source code in glide/async_commands/transaction.py
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
def blmove(
    self: TTransaction,
    source: TEncodable,
    destination: TEncodable,
    where_from: ListDirection,
    where_to: ListDirection,
    timeout: float,
) -> TTransaction:
    """
    Blocks the connection until it pops atomically and removes the left/right-most element to the
    list stored at `source` depending on `where_from`, and pushes the element at the first/last element
    of the list stored at `destination` depending on `where_to`.
    `blmove` is the blocking variant of `lmove`.

    See [valkey.io](https://valkey.io/commands/blmove/) for details.

    Args:
        source (TEncodable): The key to the source list.
        destination (TEncodable): The key to the destination list.
        where_from (ListDirection): The direction to remove the element from
            (`ListDirection.LEFT` or `ListDirection.RIGHT`).
        where_to (ListDirection): The direction to add the element to
            (`ListDirection.LEFT` or `ListDirection.RIGHT`).
        timeout (float): The number of seconds to wait for a blocking operation to complete.
            A value of `0` will block indefinitely.

    Command response:
        Optional[bytes]: The popped element.

        `None` if `source` does not exist or if the operation timed-out.

    Since: Valkey version 6.2.0.
    """
    return self.append_command(
        RequestType.BLMove,
        [source, destination, where_from.value, where_to.value, str(timeout)],
    )

blmpop(keys, direction, timeout, count=None)

Blocks the connection until it pops one or more elements from the first non-empty list from the provided keys.

BLMPOP is the blocking variant of LMPOP.

See valkey.io for details.

Parameters:

Name Type Description Default
keys List[TEncodable]

An array of keys of lists.

required
direction ListDirection

The direction based on which elements are popped from (ListDirection.LEFT or ListDirection.RIGHT).

required
timeout float

The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.

required
count Optional[int]

The maximum number of popped elements. If not provided, defaults to popping a single element.

None
Command response

Optional[Mapping[bytes, List[bytes]]]: A map of key name mapped to an array of popped elements.

None if no elements could be popped and the timeout expired.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
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
def blmpop(
    self: TTransaction,
    keys: List[TEncodable],
    direction: ListDirection,
    timeout: float,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Blocks the connection until it pops one or more elements from the first non-empty list from the provided `keys`.

    `BLMPOP` is the blocking variant of `LMPOP`.

    See [valkey.io](https://valkey.io/commands/blmpop/) for details.

    Args:
        keys (List[TEncodable]): An array of keys of lists.
        direction (ListDirection): The direction based on which elements are popped from
            (`ListDirection.LEFT` or `ListDirection.RIGHT`).
        timeout (float): The number of seconds to wait for a blocking operation to complete.
            A value of `0` will block indefinitely.
        count (Optional[int]): The maximum number of popped elements. If not provided,
            defaults to popping a single element.

    Command response:
        Optional[Mapping[bytes, List[bytes]]]: A map of `key` name mapped to an array of popped elements.

        None if no elements could be popped and the timeout expired.

    Since: Valkey version 7.0.0.
    """
    args = [str(timeout), str(len(keys)), *keys, direction.value]
    if count is not None:
        args += ["COUNT", str(count)]

    return self.append_command(RequestType.BLMPop, args)

blpop(keys, timeout)

Pops an element from the head of the first list that is non-empty, with the given keys being checked in the order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.

See valkey.io for details.

Note

BLPOP is a client blocking command, see blocking commands for more details and best practices.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the lists to pop from.

required
timeout float

The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.

required
Command response

Optional[List[bytes]]: A two-element list containing the key from which the element was popped and the value of the popped element, formatted as [key, value].

If no element could be popped and the timeout expired, returns None.

Source code in glide/async_commands/transaction.py
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
def blpop(
    self: TTransaction, keys: List[TEncodable], timeout: float
) -> TTransaction:
    """
    Pops an element from the head of the first list that is non-empty, with the given keys being checked in the
    order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.

    See [valkey.io](https://valkey.io/commands/blpop) for details.

    Note:
        BLPOP is a client blocking command, see
        [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
        for more details and best practices.

    Args:
        keys (List[TEncodable]): The keys of the lists to pop from.
        timeout (float): The number of seconds to wait for a blocking operation to complete.
            A value of 0 will block indefinitely.

    Command response:
        Optional[List[bytes]]: A two-element list containing the key from which the element was popped and the value of the
        popped element, formatted as `[key, value]`.

        If no element could be popped and the `timeout` expired, returns None.
    """
    return self.append_command(RequestType.BLPop, keys + [str(timeout)])

brpop(keys, timeout)

Pops an element from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.

See valkey.io for details.

Note

BRPOP is a client blocking command, see blocking commands for more details and best practices.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the lists to pop from.

required
timeout float

The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.

required
Command response

Optional[List[bytes]]: A two-element list containing the key from which the element was popped and the value of the popped element, formatted as [key, value].

If no element could be popped and the timeout expired, returns None.

Source code in glide/async_commands/transaction.py
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
def brpop(
    self: TTransaction, keys: List[TEncodable], timeout: float
) -> TTransaction:
    """
    Pops an element from the tail of the first list that is non-empty, with the given keys being checked in the
    order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.

    See [valkey.io](https://valkey.io/commands/brpop) for details.

    Note:
        BRPOP is a client blocking command, see
        [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
        for more details and best practices.

    Args:
        keys (List[TEncodable]): The keys of the lists to pop from.
        timeout (float): The number of seconds to wait for a blocking operation to complete.
            A value of 0 will block indefinitely.

    Command response:
        Optional[List[bytes]]: A two-element list containing the key from which the element was popped and the value of the
        popped element, formatted as `[key, value]`.

        If no element could be popped and the `timeout` expired, returns None.
    """
    return self.append_command(RequestType.BRPop, keys + [str(timeout)])

bzmpop(keys, modifier, timeout, count=None)

Pops a member-score pair from the first non-empty sorted set, with the given keys being checked in the order that they are given. Blocks the connection when there are no members to pop from any of the given sorted sets.

The optional count argument can be used to specify the number of elements to pop, and is set to 1 by default.

The number of popped elements is the minimum from the sorted set's cardinality and count.

BZMPOP is the blocking variant of ZMPOP.

See valkey.io for more details.

Note

BZMPOP is a client blocking command, see blocking commands for more details and best practices.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
modifier ScoreFilter

The element pop criteria - either ScoreFilter.MIN or ScoreFilter.MAX to pop members with the lowest/highest scores accordingly.

required
timeout float

The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.

required
count Optional[int]

The number of elements to pop.

None
Command response

Optional[List[Union[bytes, Mapping[bytes, float]]]]: A two-element list containing the key name of the set from which elements were popped, and a member-score mapping.

If no members could be popped and the timeout expired, returns None.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
def bzmpop(
    self: TTransaction,
    keys: List[TEncodable],
    modifier: ScoreFilter,
    timeout: float,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Pops a member-score pair from the first non-empty sorted set, with the given keys being checked in the order
    that they are given. Blocks the connection when there are no members to pop from any of the given sorted sets.

    The optional `count` argument can be used to specify the number of elements to pop, and is set to 1 by default.

    The number of popped elements is the minimum from the sorted set's cardinality and `count`.

    `BZMPOP` is the blocking variant of `ZMPOP`.

    See [valkey.io](https://valkey.io/commands/bzmpop) for more details.

    Note:
        `BZMPOP` is a client blocking command, see
        [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
        for more details and best practices.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.
        modifier (ScoreFilter): The element pop criteria - either ScoreFilter.MIN or ScoreFilter.MAX to pop
            members with the lowest/highest scores accordingly.
        timeout (float): The number of seconds to wait for a blocking operation to complete. A value of 0 will
            block indefinitely.
        count (Optional[int]): The number of elements to pop.

    Command response:
        Optional[List[Union[bytes, Mapping[bytes, float]]]]: A two-element list containing the key name of the set from
        which elements were popped, and a member-score mapping.

        If no members could be popped and the timeout expired, returns None.

    Since: Valkey version 7.0.0.
    """
    args = [str(timeout), str(len(keys))] + keys + [modifier.value]
    if count is not None:
        args = args + ["COUNT", str(count)]

    return self.append_command(RequestType.BZMPop, args)

bzpopmax(keys, timeout)

Pops the member with the highest score from the first non-empty sorted set, with the given keys being checked in the order that they are given. Blocks the connection when there are no members to remove from any of the given sorted sets.

BZPOPMAX is the blocking variant of ZPOPMAX.

Note

BZPOPMAX is a client blocking command, see blocking commands for more details and best practices.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
timeout float

The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.

required
Command response

Optional[List[Union[bytes, float]]]: An array containing the key where the member was popped out, the member itself, and the member score.

If no member could be popped and the timeout expired, returns None.

Source code in glide/async_commands/transaction.py
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
def bzpopmax(
    self: TTransaction, keys: List[TEncodable], timeout: float
) -> TTransaction:
    """
    Pops the member with the highest score from the first non-empty sorted set, with the given keys being checked in
    the order that they are given. Blocks the connection when there are no members to remove from any of the given
    sorted sets.

    `BZPOPMAX` is the blocking variant of `ZPOPMAX`.

    Note:
        `BZPOPMAX` is a client blocking command, see
        [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
        for more details and best practices.

    See [valkey.io](https://valkey.io/commands/bzpopmax) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.
        timeout (float): The number of seconds to wait for a blocking operation to complete.
            A value of 0 will block indefinitely.

    Command response:
        Optional[List[Union[bytes, float]]]: An array containing the key where the member was popped out, the
        member itself, and the member score.

        If no member could be popped and the `timeout` expired, returns None.
    """
    return self.append_command(RequestType.BZPopMax, keys + [str(timeout)])

bzpopmin(keys, timeout)

Pops the member with the lowest score from the first non-empty sorted set, with the given keys being checked in the order that they are given. Blocks the connection when there are no members to remove from any of the given sorted sets.

BZPOPMIN is the blocking variant of ZPOPMIN.

Note

BZPOPMIN is a client blocking command, see blocking commands for more details and best practices.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
timeout float

The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.

required
Command response

Optional[List[Union[bytes, float]]]: An array containing the key where the member was popped out, the member itself, and the member score.

If no member could be popped and the timeout expired, returns None.

Source code in glide/async_commands/transaction.py
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
def bzpopmin(
    self: TTransaction, keys: List[TEncodable], timeout: float
) -> TTransaction:
    """
    Pops the member with the lowest score from the first non-empty sorted set, with the given keys being checked in
    the order that they are given. Blocks the connection when there are no members to remove from any of the given
    sorted sets.

    `BZPOPMIN` is the blocking variant of `ZPOPMIN`.

    Note:
        `BZPOPMIN` is a client blocking command, see
        [blocking commands](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands)
        for more details and best practices.

    See [valkey.io](https://valkey.io/commands/bzpopmin) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.
        timeout (float): The number of seconds to wait for a blocking operation to complete.
            A value of 0 will block indefinitely.

    Command response:
        Optional[List[Union[bytes, float]]]: An array containing the key where the member was popped out, the
        member itself, and the member score.

        If no member could be popped and the `timeout` expired, returns None.
    """
    return self.append_command(RequestType.BZPopMin, keys + [str(timeout)])

client_getname()

Get the name of the connection on which the transaction is being executed.

See valkey.io for more details.

Command response

Optional[bytes]: Returns the name of the client connection as a bytes string if a name is set,

Returns None if no name is assigned.

Source code in glide/async_commands/transaction.py
752
753
754
755
756
757
758
759
760
761
762
763
def client_getname(self: TTransaction) -> TTransaction:
    """
    Get the name of the connection on which the transaction is being executed.

    See [valkey.io](https://valkey.io/commands/client-getname/) for more details.

    Command response:
        Optional[bytes]: Returns the name of the client connection as a bytes string if a name is set,

        Returns `None` if no name is assigned.
    """
    return self.append_command(RequestType.ClientGetName, [])

client_id()

Returns the current connection id.

See valkey.io for more information.

Command response

int: the id of the client.

Source code in glide/async_commands/transaction.py
473
474
475
476
477
478
479
480
481
482
def client_id(self: TTransaction) -> TTransaction:
    """
    Returns the current connection id.

    See [valkey.io](https://valkey.io/commands/client-id/) for more information.

    Command response:
        int: the id of the client.
    """
    return self.append_command(RequestType.ClientId, [])

config_get(parameters)

Get the values of configuration parameters. Starting from server version 7, command supports multiple parameters.

See valkey.io for details.

Parameters:

Name Type Description Default
parameters List[TEncodable]

A list of configuration parameter names to retrieve values for.

required
Command response

Dict[bytes, bytes]: A dictionary of values corresponding to the configuration parameters.

Source code in glide/async_commands/transaction.py
339
340
341
342
343
344
345
346
347
348
349
350
351
352
def config_get(self: TTransaction, parameters: List[TEncodable]) -> TTransaction:
    """
    Get the values of configuration parameters.
    Starting from server version 7, command supports multiple parameters.

    See [valkey.io](https://valkey.io/commands/config-get/) for details.

    Args:
        parameters (List[TEncodable]): A list of configuration parameter names to retrieve values for.

    Command response:
        Dict[bytes, bytes]: A dictionary of values corresponding to the configuration parameters.
    """
    return self.append_command(RequestType.ConfigGet, parameters)

config_resetstat()

Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM commands.

See valkey.io for details.

Command response

OK: a simple OK response.

Source code in glide/async_commands/transaction.py
378
379
380
381
382
383
384
385
386
387
def config_resetstat(self: TTransaction) -> TTransaction:
    """
    Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM commands.

    See [valkey.io](https://valkey.io/commands/config-resetstat/) for details.

    Command response:
        OK: a simple OK response.
    """
    return self.append_command(RequestType.ConfigResetStat, [])

config_rewrite()

Rewrite the configuration file with the current configuration.

See valkey.io for details.

Command response

OK: OK is returned when the configuration was rewritten properly.

Otherwise, the transaction fails with an error.

Source code in glide/async_commands/transaction.py
460
461
462
463
464
465
466
467
468
469
470
471
def config_rewrite(self: TTransaction) -> TTransaction:
    """
    Rewrite the configuration file with the current configuration.

    See [valkey.io](https://valkey.io/commands/config-rewrite/) for details.

    Command response:
        OK: OK is returned when the configuration was rewritten properly.

        Otherwise, the transaction fails with an error.
    """
    return self.append_command(RequestType.ConfigRewrite, [])

config_set(parameters_map)

Set configuration parameters to the specified values. Starting from server version 7, command supports multiple parameters.

See valkey.io for details.

Parameters:

Name Type Description Default
parameters_map Mapping[TEncodable, TEncodable]

A map consisting of configuration

required
Command response

OK: Returns OK if all configurations have been successfully set.

Otherwise, the transaction fails with an error.

Source code in glide/async_commands/transaction.py
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
def config_set(
    self: TTransaction,
    parameters_map: Mapping[TEncodable, TEncodable],
) -> TTransaction:
    """
    Set configuration parameters to the specified values.
    Starting from server version 7, command supports multiple parameters.

    See [valkey.io](https://valkey.io/commands/config-set/) for details.

    Args:
        parameters_map (Mapping[TEncodable, TEncodable]): A map consisting of configuration
        parameters and their respective values to set.

    Command response:
        OK: Returns OK if all configurations have been successfully set.

        Otherwise, the transaction fails with an error.
    """
    parameters: List[TEncodable] = []
    for pair in parameters_map.items():
        parameters.extend(pair)
    return self.append_command(RequestType.ConfigSet, parameters)

custom_command(command_args)

Executes a single command, without checking inputs.

See the Valkey GLIDE Wiki custom command for details on the restrictions and limitations of the custom command API.

Parameters:

Name Type Description Default
command_args List[TEncodable]

List of command arguments. Every part of the command, including the command name and subcommands, should be added as a separate value in args.

required
Command response

TResult: The returning value depends on the executed command.

Example

Append a command to list of all pub/sub clients:

transaction.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"])

Source code in glide/async_commands/transaction.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
def custom_command(
    self: TTransaction, command_args: List[TEncodable]
) -> TTransaction:
    """
    Executes a single command, without checking inputs.

    See the Valkey GLIDE Wiki
    [custom command](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command)
    for details on the restrictions and limitations of the custom command API.

    Args:
        command_args (List[TEncodable]): List of command arguments.
            Every part of the command, including the command name and subcommands, should be added as a
            separate value in args.

    Command response:
        TResult: The returning value depends on the executed command.

    Example:
        Append a command to list of all pub/sub clients:

        >>> transaction.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"])
    """
    return self.append_command(RequestType.CustomCommand, command_args)

dbsize()

Returns the number of keys in the currently selected database.

See valkey.io for more details.

Commands response

int: The number of keys in the database.

Source code in glide/async_commands/transaction.py
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
def dbsize(self: TTransaction) -> TTransaction:
    """
    Returns the number of keys in the currently selected database.

    See [valkey.io](https://valkey.io/commands/dbsize) for more details.

    Commands response:
        int: The number of keys in the database.
    """
    return self.append_command(RequestType.DBSize, [])

decr(key)

Decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to decrement its value.

required
Command response

int: the value of key after the decrement.

Source code in glide/async_commands/transaction.py
549
550
551
552
553
554
555
556
557
558
559
560
561
562
def decr(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Decrements the number stored at `key` by one. If the key does not exist, it is set to 0 before performing the
    operation.

    See [valkey.io](https://valkey.io/commands/decr/) for more details.

    Args:
        key (TEncodable): The key to decrement its value.

    Command response:
        int: the value of `key` after the decrement.
    """
    return self.append_command(RequestType.Decr, [key])

decrby(key, amount)

Decrements the number stored at key by amount. If the key does not exist, it is set to 0 before performing the operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to decrement its value.

required
amount int)

The amount to decrement.

required
Command response

int: The value of key after the decrement.

Source code in glide/async_commands/transaction.py
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
def decrby(self: TTransaction, key: TEncodable, amount: int) -> TTransaction:
    """
    Decrements the number stored at `key` by `amount`. If the key does not exist, it is set to 0 before performing
    the operation.

    See [valkey.io](https://valkey.io/commands/decrby/) for more details.

    Args:
        key (TEncodable): The key to decrement its value.
        amount (int) : The amount to decrement.

    Command response:
        int: The value of `key` after the decrement.
    """
    return self.append_command(RequestType.DecrBy, [key, str(amount)])

delete(keys)

Delete one or more keys from the database. A key is ignored if it does not exist.

See valkey.io for details.

Parameters:

Name Type Description Default
keys List[TEncodable]

A list of keys to be deleted from the database.

required
Command response

int: The number of keys that were deleted.

Source code in glide/async_commands/transaction.py
325
326
327
328
329
330
331
332
333
334
335
336
337
def delete(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Delete one or more keys from the database. A key is ignored if it does not exist.

    See [valkey.io](https://valkey.io/commands/del/) for details.

    Args:
        keys (List[TEncodable]): A list of keys to be deleted from the database.

    Command response:
        int: The number of keys that were deleted.
    """
    return self.append_command(RequestType.Del, keys)

dump(key)

Serialize the value stored at key in a Valkey-specific format and return it to the user.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to serialize.

required
Command response

Optional[bytes]: The serialized value of the data stored at key.

If key does not exist, None will be returned.

Source code in glide/async_commands/transaction.py
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
def dump(
    self: TTransaction,
    key: TEncodable,
) -> TTransaction:
    """
    Serialize the value stored at `key` in a Valkey-specific format and return it to the user.

    See [valkey.io](https://valkey.io/commands/dump/) for more details.

    Args:
        key (TEncodable): The `key` to serialize.

    Command response:
        Optional[bytes]: The serialized value of the data stored at `key`.

        If `key` does not exist, `None` will be returned.
    """
    return self.append_command(RequestType.Dump, [key])

echo(message)

Echoes the provided message back.

See valkey.io for more details.

Parameters:

Name Type Description Default
message TEncodable

The message to be echoed back.

required
Commands response

bytes: The provided message.

Source code in glide/async_commands/transaction.py
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
def echo(self: TTransaction, message: TEncodable) -> TTransaction:
    """
    Echoes the provided `message` back.

    See [valkey.io](https://valkey.io/commands/echo) for more details.

    Args:
        message (TEncodable): The message to be echoed back.

    Commands response:
        bytes: The provided `message`.
    """
    return self.append_command(RequestType.Echo, [message])

exists(keys)

Returns the number of keys in keys that exist in the database.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The list of keys to check.

required
Commands response

int: The number of keys that exist. If the same existing key is mentioned in keys multiple times, it will be counted multiple times.

Source code in glide/async_commands/transaction.py
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
def exists(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Returns the number of keys in `keys` that exist in the database.

    See [valkey.io](https://valkey.io/commands/exists/) for more details.

    Args:
        keys (List[TEncodable]): The list of keys to check.

    Commands response:
        int: The number of keys that exist. If the same existing key is mentioned in `keys` multiple times,
        it will be counted multiple times.
    """
    return self.append_command(RequestType.Exists, keys)

expire(key, seconds, option=None)

Sets a timeout on key in seconds. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to set a timeout on.

required
seconds int

The timeout in seconds.

required
option Optional[ExpireOptions]

The expire option.

None
Commands response

bool: True if the timeout was set.

False if the timeout was not set (e.g., the key doesn't exist or the operation is skipped due to the provided arguments).

Source code in glide/async_commands/transaction.py
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
def expire(
    self: TTransaction,
    key: TEncodable,
    seconds: int,
    option: Optional[ExpireOptions] = None,
) -> TTransaction:
    """
    Sets a timeout on `key` in seconds. After the timeout has expired, the key will automatically be deleted.
    If `key` already has an existing expire set, the time to live is updated to the new value.
    If `seconds` is a non-positive number, the key will be deleted rather than expired.
    The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

    See [valkey.io](https://valkey.io/commands/expire/) for more details.

    Args:
        key (TEncodable): The key to set a timeout on.
        seconds (int): The timeout in seconds.
        option (Optional[ExpireOptions]): The expire option.

    Commands response:
        bool: `True` if the timeout was set.

        `False` if the timeout was not set (e.g., the key doesn't exist or the
        operation is skipped due to the provided arguments).
    """
    args: List[TEncodable] = (
        [key, str(seconds)] if option is None else [key, str(seconds), option.value]
    )
    return self.append_command(RequestType.Expire, args)

expireat(key, unix_seconds, option=None)

Sets a timeout on key using an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to set a timeout on.

required
unix_seconds int

The timeout in an absolute Unix timestamp.

required
option Optional[ExpireOptions]

The expire option.

None
Commands response

bool: True if the timeout was set.

False if the timeout was not set (e.g., the key doesn't exist or the operation is skipped due to the provided arguments).

Source code in glide/async_commands/transaction.py
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
def expireat(
    self: TTransaction,
    key: TEncodable,
    unix_seconds: int,
    option: Optional[ExpireOptions] = None,
) -> TTransaction:
    """
    Sets a timeout on `key` using an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the
    number of seconds.
    A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be
    deleted.
    If `key` already has an existing expire set, the time to live is updated to the new value.
    The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

    See [valkey.io](https://valkey.io/commands/expireat/) for more details.

    Args:
        key (TEncodable): The key to set a timeout on.
        unix_seconds (int): The timeout in an absolute Unix timestamp.
        option (Optional[ExpireOptions]): The expire option.

    Commands response:
        bool: `True` if the timeout was set.

        `False` if the timeout was not set (e.g., the key doesn't exist or the operation
        is skipped due to the provided arguments).
    """
    args = (
        [key, str(unix_seconds)]
        if option is None
        else [key, str(unix_seconds), option.value]
    )
    return self.append_command(RequestType.ExpireAt, args)

expiretime(key)

Returns the absolute Unix timestamp (since January 1, 1970) at which the given key will expire, in seconds. To get the expiration with millisecond precision, use pexpiretime.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key to determine the expiration value of.

required
Commands response

int: The expiration Unix timestamp in seconds.

-2 if key does not exist.

-1 if key exists but has no associated expire.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
def expiretime(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the absolute Unix timestamp (since January 1, 1970) at which
    the given `key` will expire, in seconds.
    To get the expiration with millisecond precision, use `pexpiretime`.

    See [valkey.io](https://valkey.io/commands/expiretime/) for details.

    Args:
        key (TEncodable): The `key` to determine the expiration value of.

    Commands response:
        int: The expiration Unix timestamp in seconds.

        -2 if `key` does not exist.

        -1 if `key` exists but has no associated expire.

    Since: Valkey version 7.0.0.
    """
    return self.append_command(RequestType.ExpireTime, [key])

fcall(function, keys=None, arguments=None)

Invokes a previously loaded function.

See valkey.io for more details.

Parameters:

Name Type Description Default
function TEncodable

The function name.

required
keys Optional[List[TEncodable]]

A list of keys accessed by the function. To ensure the correct execution of functions, both in standalone and clustered deployments, all names of keys that a function accesses must be explicitly provided as keys.

None
arguments Optional[List[TEncodable]]

A list of function arguments. Arguments should not represent names of keys.

None
Command Response

TResult: The invoked function's return value.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
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
def fcall(
    self: TTransaction,
    function: TEncodable,
    keys: Optional[List[TEncodable]] = None,
    arguments: Optional[List[TEncodable]] = None,
) -> TTransaction:
    """
    Invokes a previously loaded function.

    See [valkey.io](https://valkey.io/commands/fcall/) for more details.

    Args:
        function (TEncodable): The function name.
        keys (Optional[List[TEncodable]]): A list of keys accessed by the function. To ensure the correct
            execution of functions, both in standalone and clustered deployments, all names of keys
            that a function accesses must be explicitly provided as `keys`.
        arguments (Optional[List[TEncodable]]): A list of `function` arguments. `Arguments`
            should not represent names of keys.

    Command Response:
        TResult: The invoked function's return value.

    Since: Valkey version 7.0.0.
    """
    args = []
    if keys is not None:
        args.extend([function, str(len(keys))] + keys)
    else:
        args.extend([function, str(0)])
    if arguments is not None:
        args.extend(arguments)
    return self.append_command(RequestType.FCall, args)

fcall_ro(function, keys=None, arguments=None)

Invokes a previously loaded read-only function.

See valkey.io for more details.

Parameters:

Name Type Description Default
function TEncodable

The function name.

required
keys List[TEncodable]

An array of keys accessed by the function. To ensure the correct execution of functions, all names of keys that a function accesses must be explicitly provided as keys.

None
arguments List[TEncodable]

An array of function arguments. arguments should not represent names of keys.

None
Command Response

TResult: The return value depends on the function that was executed.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
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
def fcall_ro(
    self: TTransaction,
    function: TEncodable,
    keys: Optional[List[TEncodable]] = None,
    arguments: Optional[List[TEncodable]] = None,
) -> TTransaction:
    """
    Invokes a previously loaded read-only function.

    See [valkey.io](https://valkey.io/commands/fcall_ro) for more details.

    Args:
        function (TEncodable): The function name.
        keys (List[TEncodable]): An `array` of keys accessed by the function. To ensure the correct
            execution of functions, all names of keys that a function accesses must be
            explicitly provided as `keys`.
        arguments (List[TEncodable]): An `array` of `function` arguments. `arguments` should not
            represent names of keys.

    Command Response:
        TResult: The return value depends on the function that was executed.

    Since: Valkey version 7.0.0.
    """
    args = []
    if keys is not None:
        args.extend([function, str(len(keys))] + keys)
    else:
        args.extend([function, str(0)])
    if arguments is not None:
        args.extend(arguments)
    return self.append_command(RequestType.FCallReadOnly, args)

flushall(flush_mode=None)

Deletes all the keys of all the existing databases. This command never fails.

See valkey.io for more details.

Parameters:

Name Type Description Default
flush_mode Optional[FlushMode]

The flushing mode, could be either SYNC or ASYNC.

None
Command Response

TOK: OK.

Source code in glide/async_commands/transaction.py
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
def flushall(
    self: TTransaction, flush_mode: Optional[FlushMode] = None
) -> TTransaction:
    """
    Deletes all the keys of all the existing databases. This command never fails.

    See [valkey.io](https://valkey.io/commands/flushall) for more details.

    Args:
        flush_mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.

    Command Response:
        TOK: OK.
    """
    args: List[TEncodable] = []
    if flush_mode is not None:
        args.append(flush_mode.value)
    return self.append_command(RequestType.FlushAll, args)

flushdb(flush_mode=None)

Deletes all the keys of the currently selected database. This command never fails.

See valkey.io for more details.

Parameters:

Name Type Description Default
flush_mode Optional[FlushMode]

The flushing mode, could be either SYNC or ASYNC.

None
Command Response

TOK: OK.

Source code in glide/async_commands/transaction.py
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
def flushdb(
    self: TTransaction, flush_mode: Optional[FlushMode] = None
) -> TTransaction:
    """
    Deletes all the keys of the currently selected database. This command never fails.

    See [valkey.io](https://valkey.io/commands/flushdb) for more details.

    Args:
        flush_mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.

    Command Response:
        TOK: OK.
    """
    args: List[TEncodable] = []
    if flush_mode is not None:
        args.append(flush_mode.value)
    return self.append_command(RequestType.FlushDB, args)

function_delete(library_name)

Deletes a library and all its functions.

See valkey.io for more details.

Parameters:

Name Type Description Default
library_name TEncodable

The library name to delete

required
Commands response

TOK: A simple OK.

Since: Valkey 7.0.0.

Source code in glide/async_commands/transaction.py
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
def function_delete(self: TTransaction, library_name: TEncodable) -> TTransaction:
    """
    Deletes a library and all its functions.

    See [valkey.io](https://valkey.io/commands/function-delete/) for more details.

    Args:
        library_name (TEncodable): The library name to delete

    Commands response:
        TOK: A simple `OK`.

    Since: Valkey 7.0.0.
    """
    return self.append_command(
        RequestType.FunctionDelete,
        [library_name],
    )

function_dump()

Returns the serialized payload of all loaded libraries.

See valkey.io for more details.

Command response

bytes: The serialized payload of all loaded libraries.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
def function_dump(self: TTransaction) -> TTransaction:
    """
    Returns the serialized payload of all loaded libraries.

    See [valkey.io](https://valkey.io/commands/function-dump/) for more details.

    Command response:
        bytes: The serialized payload of all loaded libraries.

    Since: Valkey version 7.0.0.
    """
    return self.append_command(RequestType.FunctionDump, [])

function_flush(mode=None)

Deletes all function libraries.

See valkey.io for more details.

Parameters:

Name Type Description Default
mode Optional[FlushMode]

The flushing mode, could be either SYNC or ASYNC.

None
Commands response

TOK: A simple OK.

Since: Valkey 7.0.0.

Source code in glide/async_commands/transaction.py
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
def function_flush(
    self: TTransaction, mode: Optional[FlushMode] = None
) -> TTransaction:
    """
    Deletes all function libraries.

    See [valkey.io](https://valkey.io/commands/function-flush/) for more details.

    Args:
        mode (Optional[FlushMode]): The flushing mode, could be either `SYNC` or `ASYNC`.

    Commands response:
        TOK: A simple `OK`.

    Since: Valkey 7.0.0.
    """
    return self.append_command(
        RequestType.FunctionFlush,
        [mode.value] if mode else [],
    )

function_list(library_name_pattern=None, with_code=False)

Returns information about the functions and libraries.

See valkey.io for more details.

Parameters:

Name Type Description Default
library_name_pattern Optional[TEncodable]

A wildcard pattern for matching library names.

None
with_code bool

Specifies whether to request the library code from the server or not.

False
Commands response

TFunctionListResponse: Info about all or selected libraries and their functions.

Since: Valkey 7.0.0.

Source code in glide/async_commands/transaction.py
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
def function_list(
    self: TTransaction,
    library_name_pattern: Optional[TEncodable] = None,
    with_code: bool = False,
) -> TTransaction:
    """
    Returns information about the functions and libraries.

    See [valkey.io](https://valkey.io/commands/function-list/) for more details.

    Args:
        library_name_pattern (Optional[TEncodable]):  A wildcard pattern for matching library names.
        with_code (bool): Specifies whether to request the library code from the server or not.

    Commands response:
        TFunctionListResponse: Info about all or selected libraries and their functions.

    Since: Valkey 7.0.0.
    """
    args = []
    if library_name_pattern is not None:
        args.extend(["LIBRARYNAME", library_name_pattern])
    if with_code:
        args.append("WITHCODE")
    return self.append_command(
        RequestType.FunctionList,
        args,
    )

function_load(library_code, replace=False)

Loads a library to Valkey.

See valkey.io for more details.

Parameters:

Name Type Description Default
library_code TEncodable

The source code that implements the library.

required
replace bool

Whether the given library should overwrite a library with the same name if it already exists.

False
Commands response

bytes: The library name that was loaded.

Since: Valkey 7.0.0.

Source code in glide/async_commands/transaction.py
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
def function_load(
    self: TTransaction, library_code: TEncodable, replace: bool = False
) -> TTransaction:
    """
    Loads a library to Valkey.

    See [valkey.io](https://valkey.io/commands/function-load/) for more details.

    Args:
        library_code (TEncodable): The source code that implements the library.
        replace (bool): Whether the given library should overwrite a library with the same name if
            it already exists.

    Commands response:
        bytes: The library name that was loaded.

    Since: Valkey 7.0.0.
    """
    return self.append_command(
        RequestType.FunctionLoad,
        ["REPLACE", library_code] if replace else [library_code],
    )

function_restore(payload, policy=None)

Restores libraries from the serialized payload returned by the function_dump command.

See valkey.io for more details.

Parameters:

Name Type Description Default
payload TEncodable

The serialized data from the function_dump command.

required
policy Optional[FunctionRestorePolicy]

A policy for handling existing libraries.

None
Command response

TOK: A simple "OK" response.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
def function_restore(
    self: TTransaction,
    payload: TEncodable,
    policy: Optional[FunctionRestorePolicy] = None,
) -> TTransaction:
    """
    Restores libraries from the serialized payload returned by the `function_dump` command.

    See [valkey.io](https://valkey.io/commands/function-restore/) for more details.

    Args:
        payload (TEncodable): The serialized data from the `function_dump` command.
        policy (Optional[FunctionRestorePolicy]): A policy for handling existing libraries.

    Command response:
        TOK: A simple "OK" response.

    Since: Valkey version 7.0.0.
    """
    args: List[TEncodable] = [payload]
    if policy is not None:
        args.append(policy.value)
    return self.append_command(RequestType.FunctionRestore, args)

function_stats()

Returns information about the function that's currently running and information about the available execution engines.

See valkey.io for more details

Command Response

TFunctionStatsSingleNodeResponse: A Mapping with two keys:

- `running_script` with information about the running script.
- `engines` with information about available engines and their stats.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
def function_stats(self: TTransaction) -> TTransaction:
    """
    Returns information about the function that's currently running and information about the
    available execution engines.

    See [valkey.io](https://valkey.io/commands/function-stats/) for more details

    Command Response:
        TFunctionStatsSingleNodeResponse: A `Mapping` with two keys:

            - `running_script` with information about the running script.
            - `engines` with information about available engines and their stats.

    Since: Valkey version 7.0.0.
    """
    return self.append_command(RequestType.FunctionStats, [])

geoadd(key, members_geospatialdata, existing_options=None, changed=False)

Adds geospatial members with their positions to the specified sorted set stored at key. If a member is already a part of the sorted set, its position is updated.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
members_geospatialdata Mapping[TEncodable, GeospatialData]

A mapping of member names to their corresponding positions. See GeospatialData.

required
existing_options Optional[ConditionalChange]

Options for handling existing members.

  • NX: Only add new elements.
  • XX: Only update existing elements.
None
changed bool

Modify the return value to return the number of changed elements, instead of the number of new elements added.

False
Commands response

int: The number of elements added to the sorted set.

If changed is set, returns the number of elements updated in the sorted set.

Source code in glide/async_commands/transaction.py
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
def geoadd(
    self: TTransaction,
    key: TEncodable,
    members_geospatialdata: Mapping[TEncodable, GeospatialData],
    existing_options: Optional[ConditionalChange] = None,
    changed: bool = False,
) -> TTransaction:
    """
    Adds geospatial members with their positions to the specified sorted set stored at `key`.
    If a member is already a part of the sorted set, its position is updated.

    See [valkey.io](https://valkey.io/commands/geoadd) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        members_geospatialdata (Mapping[TEncodable, GeospatialData]): A mapping of member names to their
            corresponding positions. See `GeospatialData`.
        The command will report an error when the user attempts to index coordinates outside the specified ranges.
        existing_options (Optional[ConditionalChange]): Options for handling existing members.

            - NX: Only add new elements.
            - XX: Only update existing elements.

        changed (bool): Modify the return value to return the number of changed elements, instead of the
            number of new elements added.

    Commands response:
        int: The number of elements added to the sorted set.

        If `changed` is set, returns the number of elements updated in the sorted set.
    """
    args = [key]
    if existing_options:
        args.append(existing_options.value)

    if changed:
        args.append("CH")

    members_geospatialdata_list = [
        coord
        for member, position in members_geospatialdata.items()
        for coord in [str(position.longitude), str(position.latitude), member]
    ]
    args += members_geospatialdata_list

    return self.append_command(RequestType.GeoAdd, args)

geodist(key, member1, member2, unit=None)

Returns the distance between two members in the geospatial index stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
member1 TEncodable

The name of the first member.

required
member2 TEncodable

The name of the second member.

required
unit Optional[GeoUnit]

The unit of distance measurement. See GeoUnit. If not specified, the default unit is meters.

None
Commands response

Optional[float]: The distance between member1 and member2.

If one or both members do not exist, or if the key does not exist, returns None.

Source code in glide/async_commands/transaction.py
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
def geodist(
    self: TTransaction,
    key: TEncodable,
    member1: TEncodable,
    member2: TEncodable,
    unit: Optional[GeoUnit] = None,
) -> TTransaction:
    """
    Returns the distance between two members in the geospatial index stored at `key`.

    See [valkey.io](https://valkey.io/commands/geodist) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        member1 (TEncodable): The name of the first member.
        member2 (TEncodable): The name of the second member.
        unit (Optional[GeoUnit]): The unit of distance measurement. See `GeoUnit`.
            If not specified, the default unit is meters.

    Commands response:
        Optional[float]: The distance between `member1` and `member2`.

        If one or both members do not exist, or if the key does not exist, returns None.
    """
    args = [key, member1, member2]
    if unit:
        args.append(unit.value)

    return self.append_command(RequestType.GeoDist, args)

geohash(key, members)

Returns the GeoHash bytes strings representing the positions of all the specified members in the sorted set stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
members List[TEncodable]

The list of members whose GeoHash bytes strings are to be retrieved.

required
Commands response

List[Optional[bytes]]: A list of GeoHash bytes strings representing the positions of the specified members stored at key.

If a member does not exist in the sorted set, a None value is returned for that member.

Source code in glide/async_commands/transaction.py
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
def geohash(
    self: TTransaction, key: TEncodable, members: List[TEncodable]
) -> TTransaction:
    """
    Returns the GeoHash bytes strings representing the positions of all the specified members in the sorted set stored at
    `key`.

    See [valkey.io](https://valkey.io/commands/geohash) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        members (List[TEncodable]): The list of members whose GeoHash bytes strings are to be retrieved.

    Commands response:
        List[Optional[bytes]]: A list of GeoHash bytes strings representing the positions of the specified members
        stored at `key`.

        If a member does not exist in the sorted set, a None value is returned for that member.
    """
    return self.append_command(RequestType.GeoHash, [key] + members)

geopos(key, members)

Returns the positions (longitude and latitude) of all the given members of a geospatial index in the sorted set stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
members List[TEncodable]

The members for which to get the positions.

required
Commands response

List[Optional[List[float]]]: A list of positions (longitude and latitude) corresponding to the given members.

If a member does not exist, its position will be None.

Source code in glide/async_commands/transaction.py
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
def geopos(
    self: TTransaction,
    key: TEncodable,
    members: List[TEncodable],
) -> TTransaction:
    """
    Returns the positions (longitude and latitude) of all the given members of a geospatial index in the sorted set stored
    at `key`.

    See [valkey.io](https://valkey.io/commands/geopos) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        members (List[TEncodable]): The members for which to get the positions.

    Commands response:
        List[Optional[List[float]]]: A list of positions (longitude and latitude) corresponding to the given members.

        If a member does not exist, its position will be None.
    """
    return self.append_command(RequestType.GeoPos, [key] + members)

geosearch(key, search_from, search_by, order_by=None, count=None, with_coord=False, with_dist=False, with_hash=False)

Searches for members in a sorted set stored at key representing geospatial data within a circular or rectangular area.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set representing geospatial data.

required
search_from Union[TEncodable, GeospatialData]

The location to search from. Can be specified either as a member from the sorted set or as a geospatial data (see GeospatialData).

required
search_by Union[GeoSearchByRadius, GeoSearchByBox]

The search criteria. For circular area search, see GeoSearchByRadius. For rectangle area search, see GeoSearchByBox.

required
order_by Optional[OrderBy]

Specifies the order in which the results should be returned.

  • ASC: Sorts items from the nearest to the farthest, relative to the center point.
  • DESC: Sorts items from the farthest to the nearest, relative to the center point.

If not specified, the results would be unsorted.

None
count Optional[GeoSearchCount]

Specifies the maximum number of results to return. See GeoSearchCount. If not specified, return all results.

None
with_coord bool

Whether to include coordinates of the returned items. Defaults to False.

False
with_dist bool

Whether to include distance from the center in the returned items. The distance is returned in the same unit as specified for the search_by arguments. Defaults to False.

False
with_hash bool

Whether to include geohash of the returned items. Defaults to False.

False
Command Response

List[Union[bytes, List[Union[bytes, float, int, List[float]]]]]: By default, returns a list of members (locations) names.

If any of with_coord, with_dist or with_hash are True, returns an array of arrays, where each sub array represents a single item in the following order:

- (bytes): The member (location) name.
- (float): The distance from the center as a floating point number, in the same unit specified in the radius,
  if `with_dist` is set to True.
- (int): The Geohash integer, if `with_hash` is set to True.
- List[float]: The coordinates as a two item [longitude,latitude] array, if `with_coord` is set to True.

Since: Valkey version 6.2.0.

Source code in glide/async_commands/transaction.py
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
def geosearch(
    self: TTransaction,
    key: TEncodable,
    search_from: Union[TEncodable, GeospatialData],
    search_by: Union[GeoSearchByRadius, GeoSearchByBox],
    order_by: Optional[OrderBy] = None,
    count: Optional[GeoSearchCount] = None,
    with_coord: bool = False,
    with_dist: bool = False,
    with_hash: bool = False,
) -> TTransaction:
    """
    Searches for members in a sorted set stored at `key` representing geospatial data within a circular or
    rectangular area.

    See [valkey.io](https://valkey.io/commands/geosearch/) for more details.

    Args:
        key (TEncodable): The key of the sorted set representing geospatial data.
        search_from (Union[TEncodable, GeospatialData]): The location to search from. Can be specified either as a member
            from the sorted set or as a geospatial data (see `GeospatialData`).
        search_by (Union[GeoSearchByRadius, GeoSearchByBox]): The search criteria.
            For circular area search, see `GeoSearchByRadius`.
            For rectangle area search, see `GeoSearchByBox`.
        order_by (Optional[OrderBy]): Specifies the order in which the results should be returned.

            - `ASC`: Sorts items from the nearest to the farthest, relative to the center point.
            - `DESC`: Sorts items from the farthest to the nearest, relative to the center point.

            If not specified, the results would be unsorted.
        count (Optional[GeoSearchCount]): Specifies the maximum number of results to return. See `GeoSearchCount`.
            If not specified, return all results.
        with_coord (bool): Whether to include coordinates of the returned items. Defaults to False.
        with_dist (bool): Whether to include distance from the center in the returned items.
            The distance is returned in the same unit as specified for the `search_by` arguments. Defaults to False.
        with_hash (bool): Whether to include geohash of the returned items. Defaults to False.

    Command Response:
        List[Union[bytes, List[Union[bytes, float, int, List[float]]]]]: By default, returns a list of members (locations)
        names.

        If any of `with_coord`, `with_dist` or `with_hash` are True, returns an array of arrays, where each sub array
        represents a single item in the following order:

            - (bytes): The member (location) name.
            - (float): The distance from the center as a floating point number, in the same unit specified in the radius,
              if `with_dist` is set to True.
            - (int): The Geohash integer, if `with_hash` is set to True.
            - List[float]: The coordinates as a two item [longitude,latitude] array, if `with_coord` is set to True.

    Since: Valkey version 6.2.0.
    """
    args = _create_geosearch_args(
        [key],
        search_from,
        search_by,
        order_by,
        count,
        with_coord,
        with_dist,
        with_hash,
    )

    return self.append_command(RequestType.GeoSearch, args)

geosearchstore(destination, source, search_from, search_by, count=None, store_dist=False)

Searches for members in a sorted set stored at key representing geospatial data within a circular or rectangular area and stores the result in destination. If destination already exists, it is overwritten. Otherwise, a new sorted set will be created.

To get the result directly, see geosearch.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key to store the search results.

required
source TEncodable

The key of the sorted set representing geospatial data to search from.

required
search_from Union[TEncodable, GeospatialData]

The location to search from. Can be specified either as a member from the sorted set or as a geospatial data (see GeospatialData).

required
search_by Union[GeoSearchByRadius, GeoSearchByBox]

The search criteria. For circular area search, see GeoSearchByRadius. For rectangular area search, see GeoSearchByBox.

required
count Optional[GeoSearchCount]

Specifies the maximum number of results to store. See GeoSearchCount. If not specified, stores all results.

None
store_dist bool

Determines what is stored as the sorted set score. Defaults to False.

  • If set to False, the geohash of the location will be stored as the sorted set score.
  • If set to True, the distance from the center of the shape (circle or box) will be stored as the sorted set score. The distance is represented as a floating-point number in the same unit specified for that shape.
False
Commands response

int: The number of elements in the resulting sorted set stored at destination.

Since: Valkey version 6.2.0.

Source code in glide/async_commands/transaction.py
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
def geosearchstore(
    self: TTransaction,
    destination: TEncodable,
    source: TEncodable,
    search_from: Union[TEncodable, GeospatialData],
    search_by: Union[GeoSearchByRadius, GeoSearchByBox],
    count: Optional[GeoSearchCount] = None,
    store_dist: bool = False,
) -> TTransaction:
    """
    Searches for members in a sorted set stored at `key` representing geospatial data within a circular or rectangular
    area and stores the result in `destination`.
    If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.

    To get the result directly, see `geosearch`.

    See [valkey.io](https://valkey.io/commands/geosearch/) for more details.

    Args:
        destination (TEncodable): The key to store the search results.
        source (TEncodable): The key of the sorted set representing geospatial data to search from.
        search_from (Union[TEncodable, GeospatialData]): The location to search from. Can be specified either as a member
            from the sorted set or as a geospatial data (see `GeospatialData`).
        search_by (Union[GeoSearchByRadius, GeoSearchByBox]): The search criteria.
            For circular area search, see `GeoSearchByRadius`.
            For rectangular area search, see `GeoSearchByBox`.
        count (Optional[GeoSearchCount]): Specifies the maximum number of results to store. See `GeoSearchCount`.
            If not specified, stores all results.
        store_dist (bool): Determines what is stored as the sorted set score. Defaults to False.

            - If set to False, the geohash of the location will be stored as the sorted set score.
            - If set to True, the distance from the center of the shape (circle or box) will be stored as the sorted set
              score. The distance is represented as a floating-point number in the same unit specified for that shape.

    Commands response:
        int: The number of elements in the resulting sorted set stored at `destination`.

    Since: Valkey version 6.2.0.
    """
    args = _create_geosearch_args(
        [destination, source],
        search_from,
        search_by,
        None,
        count,
        False,
        False,
        False,
        store_dist,
    )

    return self.append_command(RequestType.GeoSearchStore, args)

get(key)

Get the value associated with the given key, or null if no such value exists.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key to retrieve from the database.

required
Command response

Optional[bytes]: If the key exists, returns the value of the key as a bytes string.

Otherwise, return None.

Source code in glide/async_commands/transaction.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def get(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Get the value associated with the given key, or null if no such value exists.

    See [valkey.io](https://valkey.io/commands/get/) for details.

    Args:
        key (TEncodable): The key to retrieve from the database.

    Command response:
        Optional[bytes]: If the key exists, returns the value of the key as a bytes string.

        Otherwise, return None.
    """
    return self.append_command(RequestType.Get, [key])

getbit(key, offset)

Returns the bit value at offset in the string value stored at key. offset should be greater than or equal to zero.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the string.

required
offset int

The index of the bit to return.

required
Command response

int: The bit at the given offset of the string.

Returns 0 if the key is empty or if the offset exceeds the length of the string.

Source code in glide/async_commands/transaction.py
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
def getbit(self: TTransaction, key: TEncodable, offset: int) -> TTransaction:
    """
    Returns the bit value at `offset` in the string value stored at `key`.
    `offset` should be greater than or equal to zero.

    See [valkey.io](https://valkey.io/commands/getbit) for more details.

    Args:
        key (TEncodable): The key of the string.
        offset (int): The index of the bit to return.

    Command response:
        int: The bit at the given `offset` of the string.

        Returns `0` if the key is empty or if the `offset` exceeds the length of the string.
    """
    return self.append_command(RequestType.GetBit, [key, str(offset)])

getdel(key)

Gets a value associated with the given string key and deletes the key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to retrieve from the database.

required
Command response

Optional[bytes]: If key exists, returns the value of key.

Otherwise, returns None.

Source code in glide/async_commands/transaction.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def getdel(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Gets a value associated with the given string `key` and deletes the key.

    See [valkey.io](https://valkey.io/commands/getdel) for more details.

    Args:
        key (TEncodable): The `key` to retrieve from the database.

    Command response:
        Optional[bytes]: If `key` exists, returns the `value` of `key`.

        Otherwise, returns `None`.
    """
    return self.append_command(RequestType.GetDel, [key])

getex(key, expiry=None)

Get the value of key and optionally set its expiration. GETEX is similar to GET.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to get.

required
expiry Optional[ExpirySet]

set expiriation to the given key. Equivalent to [EX | PX | EXAT | PXAT | PERSIST] in the Valkey API.

None
Command Response

Optional[bytes]: If key exists, return the value stored at key

If 'key` does not exist, return 'None'

Since: Valkey version 6.2.0.

Source code in glide/async_commands/transaction.py
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
def getex(
    self: TTransaction, key: TEncodable, expiry: Optional[ExpiryGetEx] = None
) -> TTransaction:
    """
    Get the value of `key` and optionally set its expiration. GETEX is similar to GET.

    See [valkey.io](https://valkey.io/commands/getex) for more details.

    Args:
        key (TEncodable): The key to get.
        expiry (Optional[ExpirySet], optional): set expiriation to the given key.
            Equivalent to [`EX` | `PX` | `EXAT` | `PXAT` | `PERSIST`] in the Valkey API.

    Command Response:
        Optional[bytes]: If `key` exists, return the value stored at `key`

        If 'key` does not exist, return 'None'

    Since: Valkey version 6.2.0.
    """
    args: List[TEncodable] = [key]
    if expiry is not None:
        args.extend(expiry.get_cmd_args())
    return self.append_command(RequestType.GetEx, args)

getrange(key, start, end)

Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth.

If key does not exist, an empty string is returned. If start or end are out of range, returns the substring within the valid range of the string.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the string.

required
start int

The starting offset.

required
end int

The ending offset.

required
Commands response

bytes: A substring extracted from the value stored at key.

Source code in glide/async_commands/transaction.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def getrange(
    self: TTransaction, key: TEncodable, start: int, end: int
) -> TTransaction:
    """
    Returns the substring of the string value stored at `key`, determined by the offsets `start` and `end`
    (both are inclusive).
    Negative offsets can be used in order to provide an offset starting from the end of the string.
    So `-1` means the last character, `-2` the penultimate and so forth.

    If `key` does not exist, an empty string is returned. If `start` or `end`
    are out of range, returns the substring within the valid range of the string.

    See [valkey.io](https://valkey.io/commands/getrange/) for more details.

    Args:
        key (TEncodable): The key of the string.
        start (int): The starting offset.
        end (int): The ending offset.

    Commands response:
        bytes: A substring extracted from the value stored at `key`.
    """
    return self.append_command(RequestType.GetRange, [key, str(start), str(end)])

hdel(key, fields)

Remove specified fields from the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
fields List[TEncodable]

The list of fields to remove from the hash stored at key.

required

Returns:

Name Type Description
int TTransaction

The number of fields that were removed from the hash, excluding specified but non-existing fields.

TTransaction

If key does not exist, it is treated as an empty hash, and the function returns 0.

Source code in glide/async_commands/transaction.py
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
def hdel(
    self: TTransaction, key: TEncodable, fields: List[TEncodable]
) -> TTransaction:
    """
    Remove specified fields from the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hdel/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        fields (List[TEncodable]): The list of fields to remove from the hash stored at `key`.

    Returns:
        int: The number of fields that were removed from the hash, excluding specified but non-existing fields.

        If `key` does not exist, it is treated as an empty hash, and the function returns 0.
    """
    return self.append_command(RequestType.HDel, [key] + fields)

hexists(key, field)

Check if a field exists in the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
field TEncodable

The field to check in the hash stored at key.

required
Command response

bool: Returns True if the hash contains the specified field. If the hash does not contain the field,

Returns False if the key does not exist.

Source code in glide/async_commands/transaction.py
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
def hexists(self: TTransaction, key: TEncodable, field: TEncodable) -> TTransaction:
    """
    Check if a field exists in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hexists/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        field (TEncodable): The field to check in the hash stored at `key`.

    Command response:
        bool: Returns `True` if the hash contains the specified field. If the hash does not contain the field,

        Returns `False` if the key does not exist.
    """
    return self.append_command(RequestType.HExists, [key, field])

hget(key, field)

Retrieves the value associated with field in the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
field TEncodable

The field whose value should be retrieved.

required
Command response

Optional[bytes]: The value associated field in the hash.

Returns None if field is not presented in the hash or key does not exist.

Source code in glide/async_commands/transaction.py
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
def hget(self: TTransaction, key: TEncodable, field: TEncodable) -> TTransaction:
    """
    Retrieves the value associated with `field` in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hget/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        field (TEncodable): The field whose value should be retrieved.

    Command response:
        Optional[bytes]: The value associated `field` in the hash.

        Returns None if `field` is not presented in the hash or `key` does not exist.
    """
    return self.append_command(RequestType.HGet, [key, field])

hgetall(key)

Returns all fields and values of the hash stored at key.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
Command response

Dict[bytes, bytes]: A dictionary of fields and their values stored in the hash. Every field name in the list is followed by its value.

If key does not exist, it returns an empty dictionary.

Source code in glide/async_commands/transaction.py
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
def hgetall(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns all fields and values of the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hgetall/) for details.

    Args:
        key (TEncodable): The key of the hash.

    Command response:
        Dict[bytes, bytes]: A dictionary of fields and their values stored in the hash. Every field name in the
        list is followed by its value.

        If `key` does not exist, it returns an empty dictionary.
    """
    return self.append_command(RequestType.HGetAll, [key])

hincrby(key, field, amount)

Increment or decrement the value of a field in the hash stored at key by the specified amount. By using a negative increment value, the value stored at field in the hash stored at key is decremented. If field or key does not exist, it is set to 0 before performing the operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
field TEncodable

The field in the hash stored at key to increment or decrement its value.

required
amount int

The amount by which to increment or decrement the field's value. Use a negative value to decrement.

required
Command response

int: The value of the specified field in the hash stored at key after the increment or decrement.

Source code in glide/async_commands/transaction.py
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
def hincrby(
    self: TTransaction,
    key: TEncodable,
    field: TEncodable,
    amount: int,
) -> TTransaction:
    """
    Increment or decrement the value of a `field` in the hash stored at `key` by the specified amount.
    By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented.
    If `field` or `key` does not exist, it is set to 0 before performing the operation.

    See [valkey.io](https://valkey.io/commands/hincrby/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        field (TEncodable): The field in the hash stored at `key` to increment or decrement its value.
        amount (int): The amount by which to increment or decrement the field's value.
            Use a negative value to decrement.

    Command response:
        int: The value of the specified field in the hash stored at `key` after the increment or decrement.
    """
    return self.append_command(RequestType.HIncrBy, [key, field, str(amount)])

hincrbyfloat(key, field, amount)

Increment or decrement the floating-point value stored at field in the hash stored at key by the specified amount. By using a negative increment value, the value stored at field in the hash stored at key is decremented. If field or key does not exist, it is set to 0 before performing the operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
field TEncodable

The field in the hash stored at key to increment or decrement its value.

required
amount float

The amount by which to increment or decrement the field's value. Use a negative value to decrement.

required
Command response

float: The value of the specified field in the hash stored at key after the increment as a string.

Source code in glide/async_commands/transaction.py
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
def hincrbyfloat(
    self: TTransaction,
    key: TEncodable,
    field: TEncodable,
    amount: float,
) -> TTransaction:
    """
    Increment or decrement the floating-point value stored at `field` in the hash stored at `key` by the specified
    amount.
    By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented.
    If `field` or `key` does not exist, it is set to 0 before performing the operation.

    See [valkey.io](https://valkey.io/commands/hincrbyfloat/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        field (TEncodable): The field in the hash stored at `key` to increment or decrement its value.
        amount (float): The amount by which to increment or decrement the field's value.
            Use a negative value to decrement.

    Command response:
        float: The value of the specified field in the hash stored at `key` after the increment as a string.
    """
    return self.append_command(RequestType.HIncrByFloat, [key, field, str(amount)])

hkeys(key)

Returns all field names in the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
Command response

List[bytes]: A list of field names for the hash.

An empty list when the key does not exist.

Source code in glide/async_commands/transaction.py
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
def hkeys(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns all field names in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hkeys/) for more details.

    Args:
        key (TEncodable): The key of the hash.

    Command response:
        List[bytes]: A list of field names for the hash.

        An empty list when the key does not exist.
    """
    return self.append_command(RequestType.HKeys, [key])

hlen(key)

Returns the number of fields contained in the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
Command response

int: The number of fields in the hash, or 0 when the key does not exist.

If key holds a value that is not a hash, the transaction fails with an error.

Source code in glide/async_commands/transaction.py
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
def hlen(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the number of fields contained in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hlen/) for more details.

    Args:
        key (TEncodable): The key of the hash.

    Command response:
        int: The number of fields in the hash, or 0 when the key does not exist.

        If `key` holds a value that is not a hash, the transaction fails with an error.
    """
    return self.append_command(RequestType.HLen, [key])

hmget(key, fields)

Retrieve the values associated with specified fields in the hash stored at key.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
fields List[TEncodable]

The list of fields in the hash stored at key to retrieve from the database.

required

Returns:

Type Description
TTransaction

List[Optional[bytes]]: A list of values associated with the given fields, in the same order as they are requested.

TTransaction

For every field that does not exist in the hash, a null value is returned.

TTransaction

If key does not exist, it is treated as an empty hash, and the function returns a list of null values.

Source code in glide/async_commands/transaction.py
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
def hmget(
    self: TTransaction, key: TEncodable, fields: List[TEncodable]
) -> TTransaction:
    """
    Retrieve the values associated with specified fields in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hmget/) for details.

    Args:
        key (TEncodable): The key of the hash.
        fields (List[TEncodable]): The list of fields in the hash stored at `key` to retrieve from the database.

    Returns:
        List[Optional[bytes]]: A list of values associated with the given fields, in the same order as they are requested.
        For every field that does not exist in the hash, a null value is returned.

        If `key` does not exist, it is treated as an empty hash, and the function returns a list of null values.
    """
    return self.append_command(RequestType.HMGet, [key] + fields)

hrandfield(key)

Returns a random field name from the hash value stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
Command response

Optional[bytes]: A random field name from the hash stored at key.

If the hash does not exist or is empty, None will be returned.

Source code in glide/async_commands/transaction.py
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
def hrandfield(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns a random field name from the hash value stored at `key`.

    See [valkey.io](https://valkey.io/commands/hrandfield) for more details.

    Args:
        key (TEncodable): The key of the hash.

    Command response:
        Optional[bytes]: A random field name from the hash stored at `key`.

        If the hash does not exist or is empty, None will be returned.
    """
    return self.append_command(RequestType.HRandField, [key])

hrandfield_count(key, count)

Retrieves up to count random field names from the hash value stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
count int

The number of field names to return.

  • If count is positive, returns unique elements.
  • If count is negative, allows for duplicates elements.
required
Command response

List[bytes]: A list of random field names from the hash.

If the hash does not exist or is empty, the response will be an empty list.

Source code in glide/async_commands/transaction.py
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
def hrandfield_count(
    self: TTransaction, key: TEncodable, count: int
) -> TTransaction:
    """
    Retrieves up to `count` random field names from the hash value stored at `key`.

    See [valkey.io](https://valkey.io/commands/hrandfield) for more details.

    Args:
        key (TEncodable): The key of the hash.
        count (int): The number of field names to return.

            - If `count` is positive, returns unique elements.
            - If `count` is negative, allows for duplicates elements.

    Command response:
        List[bytes]: A list of random field names from the hash.

        If the hash does not exist or is empty, the response will be an empty list.
    """
    return self.append_command(RequestType.HRandField, [key, str(count)])

hrandfield_withvalues(key, count)

Retrieves up to count random field names along with their values from the hash value stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
count int

The number of field names to return.

  • If count is positive, returns unique elements.
  • If count is negative, allows for duplicates elements.
required
Command response

List[List[bytes]]: A list of [field_name, value] lists, where field_name is a random field name from the hash and value is the associated value of the field name.

If the hash does not exist or is empty, the response will be an empty list.

Source code in glide/async_commands/transaction.py
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
def hrandfield_withvalues(
    self: TTransaction, key: TEncodable, count: int
) -> TTransaction:
    """
    Retrieves up to `count` random field names along with their values from the hash value stored at `key`.

    See [valkey.io](https://valkey.io/commands/hrandfield) for more details.

    Args:
        key (TEncodable): The key of the hash.
        count (int): The number of field names to return.

            - If `count` is positive, returns unique elements.
            - If `count` is negative, allows for duplicates elements.

    Command response:
        List[List[bytes]]: A list of `[field_name, value]` lists, where `field_name` is a random field name from the
        hash and `value` is the associated value of the field name.

        If the hash does not exist or is empty, the response will be an empty list.
    """
    return self.append_command(
        RequestType.HRandField, [key, str(count), "WITHVALUES"]
    )

hscan(key, cursor, match=None, count=None, no_values=False)

Iterates incrementally over a hash.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the set.

required
cursor TEncodable

The cursor that points to the next iteration of results. A value of "0" indicates the start of the search.

required
match Optional[TEncodable]

The match filter is applied to the result of the command and will only include strings or byte strings that match the pattern specified. If the hash is large enough for scan commands to return only a subset of the hash then there could be a case where the result is empty although there are items that match the pattern specified. This is due to the default COUNT being 10 which indicates that it will only fetch and match 10 items from the list.

None
count Optional[int]

COUNT is a just a hint for the command for how many elements to fetch from the hash. COUNT could be ignored until the hash is large enough for the SCAN commands to represent the results as compact single-allocation packed encoding.

None
no_values bool

If True, the command will not return values the fields in the hash. Since Valkey "8.0.0".

False

Returns:

Type Description
TTransaction

List[Union[bytes, List[bytes]]]: An Array of the cursor and the subset of the hash held by key.

TTransaction

The first element is always the cursor for the next iteration of results. 0 will be the cursor

TTransaction

returned on the last iteration of the hash. The second element is always an Array of the subset of the

TTransaction

hash held in key. The Array in the second element is a flattened series of String pairs,

TTransaction

where the value is at even indices and the score is at odd indices.

TTransaction

If no_values is set to True, the second element will only contain the fields without the values.

Source code in glide/async_commands/transaction.py
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
def hscan(
    self: TTransaction,
    key: TEncodable,
    cursor: TEncodable,
    match: Optional[TEncodable] = None,
    count: Optional[int] = None,
    no_values: bool = False,
) -> TTransaction:
    """
    Iterates incrementally over a hash.

    See [valkey.io](https://valkey.io/commands/hscan) for more details.

    Args:
        key (TEncodable): The key of the set.
        cursor (TEncodable): The cursor that points to the next iteration of results. A value of "0" indicates the start of
            the search.
        match (Optional[TEncodable]): The match filter is applied to the result of the command and will only include
            strings or byte strings that match the pattern specified. If the hash is large enough for scan commands to
            return only a subset of the hash then there could be a case where the result is empty although there are
            items that match the pattern specified. This is due to the default `COUNT` being `10` which indicates that
            it will only fetch and match `10` items from the list.
        count (Optional[int]): `COUNT` is a just a hint for the command for how many elements to fetch from the hash.
            `COUNT` could be ignored until the hash is large enough for the `SCAN` commands to represent the results
            as compact single-allocation packed encoding.
        no_values (bool): If `True`, the command will not return values the fields in the hash. Since Valkey "8.0.0".

    Returns:
        List[Union[bytes, List[bytes]]]: An `Array` of the `cursor` and the subset of the hash held by `key`.
        The first element is always the `cursor` for the next iteration of results. `0` will be the `cursor`
        returned on the last iteration of the hash. The second element is always an `Array` of the subset of the
        hash held in `key`. The `Array` in the second element is a flattened series of `String` pairs,
        where the value is at even indices and the score is at odd indices.

        If `no_values` is set to `True`, the second element will only contain the fields without the values.
    """
    args = [key, cursor]
    if match is not None:
        args += ["MATCH", match]
    if count is not None:
        args += ["COUNT", str(count)]
    if no_values:
        args.append("NOVALUES")

    return self.append_command(RequestType.HScan, args)

hset(key, field_value_map)

Sets the specified fields to their respective values in the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
field_value_map Mapping[TEncodable, TEncodable]

A field-value map consisting of fields and their corresponding values to be set in the hash stored at the specified key.

required
Command response

int: The number of fields that were added to the hash.

Source code in glide/async_commands/transaction.py
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
def hset(
    self: TTransaction,
    key: TEncodable,
    field_value_map: Mapping[TEncodable, TEncodable],
) -> TTransaction:
    """
    Sets the specified fields to their respective values in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hset/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        field_value_map (Mapping[TEncodable, TEncodable]): A field-value map consisting of fields and their
            corresponding values to be set in the hash stored at the specified key.

    Command response:
        int: The number of fields that were added to the hash.
    """
    field_value_list: List[TEncodable] = [key]
    for pair in field_value_map.items():
        field_value_list.extend(pair)
    return self.append_command(RequestType.HSet, field_value_list)

hsetnx(key, field, value)

Sets field in the hash stored at key to value, only if field does not yet exist. If key does not exist, a new key holding a hash is created. If field already exists, this operation has no effect.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
field TEncodable

The field to set the value for.

required
value TEncodable

The value to set.

required
Commands response

bool: True if the field was set.

False if the field already existed and was not set.

Source code in glide/async_commands/transaction.py
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
def hsetnx(
    self: TTransaction,
    key: TEncodable,
    field: TEncodable,
    value: TEncodable,
) -> TTransaction:
    """
    Sets `field` in the hash stored at `key` to `value`, only if `field` does not yet exist.
    If `key` does not exist, a new key holding a hash is created.
    If `field` already exists, this operation has no effect.

    See [valkey.io](https://valkey.io/commands/hsetnx/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        field (TEncodable): The field to set the value for.
        value (TEncodable): The value to set.

    Commands response:
        bool: True if the field was set.

        False if the field already existed and was not set.
    """
    return self.append_command(RequestType.HSetNX, [key, field, value])

hstrlen(key, field)

Returns the string length of the value associated with field in the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
field TEncodable

The field in the hash.

required
Commands response

int: The string length.

Returns 0 if field or key does not exist.

Source code in glide/async_commands/transaction.py
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
def hstrlen(self: TTransaction, key: TEncodable, field: TEncodable) -> TTransaction:
    """
    Returns the string length of the value associated with `field` in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hstrlen/) for more details.

    Args:
        key (TEncodable): The key of the hash.
        field (TEncodable): The field in the hash.

    Commands response:
        int: The string length.

        Returns `0` if `field` or `key` does not exist.
    """
    return self.append_command(RequestType.HStrlen, [key, field])

hvals(key)

Returns all values in the hash stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the hash.

required
Command response

List[bytes]: A list of values in the hash.

An empty list when the key does not exist.

Source code in glide/async_commands/transaction.py
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
def hvals(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns all values in the hash stored at `key`.

    See [valkey.io](https://valkey.io/commands/hvals/) for more details.

    Args:
        key (TEncodable): The key of the hash.

    Command response:
        List[bytes]: A list of values in the hash.

        An empty list when the key does not exist.
    """
    return self.append_command(RequestType.HVals, [key])

incr(key)

Increments the number stored at key by one. If key does not exist, it is set to 0 before performing the operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to increment its value.

required
Command response

int: the value of key after the increment.

Source code in glide/async_commands/transaction.py
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
def incr(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Increments the number stored at `key` by one.
    If `key` does not exist, it is set to 0 before performing the
    operation.

    See [valkey.io](https://valkey.io/commands/incr/) for more details.

    Args:
        key (TEncodable): The key to increment its value.

    Command response:
        int: the value of `key` after the increment.
    """
    return self.append_command(RequestType.Incr, [key])

incrby(key, amount)

Increments the number stored at key by amount. If the key does not exist, it is set to 0 before performing the operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to increment its value.

required
amount int)

The amount to increment.

required
Command response

int: The value of key after the increment.

Source code in glide/async_commands/transaction.py
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
def incrby(self: TTransaction, key: TEncodable, amount: int) -> TTransaction:
    """
    Increments the number stored at `key` by `amount`. If the key does not exist, it is set to 0 before performing
    the operation.

    See [valkey.io](https://valkey.io/commands/incrby/) for more details.

    Args:
      key (TEncodable): The key to increment its value.
      amount (int) : The amount to increment.

    Command response:
        int: The value of `key` after the increment.
    """
    return self.append_command(RequestType.IncrBy, [key, str(amount)])

incrbyfloat(key, amount)

Increment the string representing a floating point number stored at key by amount. By using a negative increment value, the value stored at the key is decremented. If the key does not exist, it is set to 0 before performing the operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to increment its value.

required
amount float)

The amount to increment.

required
Command response

float: The value of key after the increment.

Source code in glide/async_commands/transaction.py
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
def incrbyfloat(self: TTransaction, key: TEncodable, amount: float) -> TTransaction:
    """
    Increment the string representing a floating point number stored at `key` by `amount`.
    By using a negative increment value, the value stored at the `key` is decremented.
    If the key does not exist, it is set to 0 before performing the operation.

    See [valkey.io](https://valkey.io/commands/incrbyfloat/) for more details.

    Args:
      key (TEncodable): The key to increment its value.
      amount (float) : The amount to increment.

    Command response:
        float: The value of key after the increment.
    """
    return self.append_command(RequestType.IncrByFloat, [key, str(amount)])

info(sections=None)

Get information and statistics about the server.

See valkey.io for details.

Parameters:

Name Type Description Default
sections Optional[List[InfoSection]]

A list of InfoSection values specifying which sections of information to retrieve. When no parameter is provided, the default option is assumed.

None
Command response

bytes: Returns a bytes string containing the information for the sections requested.

Source code in glide/async_commands/transaction.py
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
def info(
    self: TTransaction,
    sections: Optional[List[InfoSection]] = None,
) -> TTransaction:
    """
    Get information and statistics about the server.

    See [valkey.io](https://valkey.io/commands/info/) for details.

    Args:
        sections (Optional[List[InfoSection]]): A list of InfoSection values specifying which sections of
            information to retrieve. When no parameter is provided, the default option is assumed.

    Command response:
        bytes: Returns a bytes string containing the information for the sections requested.
    """
    args: List[TEncodable] = (
        [section.value for section in sections] if sections else []
    )
    return self.append_command(RequestType.Info, args)

lastsave()

Returns the Unix time of the last DB save timestamp or startup timestamp if no save was made since then.

See valkey.io for more details.

Command response

int: The Unix time of the last successful DB save.

Source code in glide/async_commands/transaction.py
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
def lastsave(self: TTransaction) -> TTransaction:
    """
    Returns the Unix time of the last DB save timestamp or startup timestamp if no save was made since then.

    See [valkey.io](https://valkey.io/commands/lastsave) for more details.

    Command response:
        int: The Unix time of the last successful DB save.
    """
    return self.append_command(RequestType.LastSave, [])

lcs(key1, key2)

Returns the longest common subsequence between strings stored at key1 and key2.

Note

This is different than the longest common string algorithm, since matching characters in the two strings do not need to be contiguous.

For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings from left to right, the longest common set of characters is composed of the first "f" and then the "o".

See valkey.io for more details.

Parameters:

Name Type Description Default
key1 TEncodable

The key that stores the first value.

required
key2 TEncodable

The key that stores the second value.

required
Command Response

A Bytes String containing the longest common subsequence between the 2 strings.

An empty Bytes String is returned if the keys do not exist or have no common subsequences.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
def lcs(
    self: TTransaction,
    key1: TEncodable,
    key2: TEncodable,
) -> TTransaction:
    """
    Returns the longest common subsequence between strings stored at key1 and key2.

    Note:
        This is different than the longest common string algorithm, since
        matching characters in the two strings do not need to be contiguous.

        For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings
        from left to right, the longest common set of characters is composed of the first "f" and then the "o".

    See [valkey.io](https://valkey.io/commands/lcs) for more details.

    Args:
        key1 (TEncodable): The key that stores the first value.
        key2 (TEncodable): The key that stores the second value.

    Command Response:
        A Bytes String containing the longest common subsequence between the 2 strings.

        An empty Bytes String is returned if the keys do not exist or have no common subsequences.

    Since: Valkey version 7.0.0.
    """
    args = [key1, key2]

    return self.append_command(RequestType.LCS, args)

lcs_idx(key1, key2, min_match_len=None, with_match_len=False)

Returns the indices and length of the longest common subsequence between strings stored at key1 and key2.

Note

This is different than the longest common string algorithm, since matching characters in the two strings do not need to be contiguous.

For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings from left to right, the longest common set of characters is composed of the first "f" and then the "o".

See valkey.io for more details.

Parameters:

Name Type Description Default
key1 TEncodable

The key that stores the first value.

required
key2 TEncodable

The key that stores the second value.

required
min_match_len Optional[int]

The minimum length of matches to include in the result.

None
with_match_len Optional[bool]

If True, include the length of the substring matched for each substring.

False
Command Response

A Map containing the indices of the longest common subsequence between the 2 strings and the length of the longest common subsequence. The resulting map contains two keys, "matches" and "len":

- "len" is mapped to the length of the longest common subsequence between the 2 strings.
- "matches" is mapped to a three dimensional int array that stores pairs of indices that
  represent the location of the common subsequences in the strings held by key1 and key2,
  with the length of the match after each matches, if with_match_len is enabled.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
def lcs_idx(
    self: TTransaction,
    key1: TEncodable,
    key2: TEncodable,
    min_match_len: Optional[int] = None,
    with_match_len: Optional[bool] = False,
) -> TTransaction:
    """
    Returns the indices and length of the longest common subsequence between strings stored at key1 and key2.

    Note:
        This is different than the longest common string algorithm, since
        matching characters in the two strings do not need to be contiguous.

        For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings
        from left to right, the longest common set of characters is composed of the first "f" and then the "o".

    See [valkey.io](https://valkey.io/commands/lcs) for more details.

    Args:
        key1 (TEncodable): The key that stores the first value.
        key2 (TEncodable): The key that stores the second value.
        min_match_len (Optional[int]): The minimum length of matches to include in the result.
        with_match_len (Optional[bool]): If True, include the length of the substring matched for each substring.

    Command Response:
        A Map containing the indices of the longest common subsequence between the
        2 strings and the length of the longest common subsequence. The resulting map contains two
        keys, "matches" and "len":

            - "len" is mapped to the length of the longest common subsequence between the 2 strings.
            - "matches" is mapped to a three dimensional int array that stores pairs of indices that
              represent the location of the common subsequences in the strings held by key1 and key2,
              with the length of the match after each matches, if with_match_len is enabled.

    Since: Valkey version 7.0.0.
    """
    args = [key1, key2, "IDX"]

    if min_match_len is not None:
        args.extend(["MINMATCHLEN", str(min_match_len)])

    if with_match_len:
        args.append("WITHMATCHLEN")

    return self.append_command(RequestType.LCS, args)

lcs_len(key1, key2)

Returns the length of the longest common subsequence between strings stored at key1 and key2.

Note

This is different than the longest common string algorithm, since matching characters in the two strings do not need to be contiguous.

For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings from left to right, the longest common set of characters is composed of the first "f" and then the "o".

See valkey.io for more details.

Parameters:

Name Type Description Default
key1 TEncodable

The key that stores the first value.

required
key2 TEncodable

The key that stores the second value.

required
Command Response

The length of the longest common subsequence between the 2 strings.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
def lcs_len(
    self: TTransaction,
    key1: TEncodable,
    key2: TEncodable,
) -> TTransaction:
    """
    Returns the length of the longest common subsequence between strings stored at key1 and key2.

    Note:
        This is different than the longest common string algorithm, since
        matching characters in the two strings do not need to be contiguous.

        For instance the LCS between "foo" and "fao" is "fo", since scanning the two strings
        from left to right, the longest common set of characters is composed of the first "f" and then the "o".

    See [valkey.io](https://valkey.io/commands/lcs) for more details.

    Args:
        key1 (TEncodable): The key that stores the first value.
        key2 (TEncodable): The key that stores the second value.

    Command Response:
        The length of the longest common subsequence between the 2 strings.

    Since: Valkey version 7.0.0.
    """
    args = [key1, key2, "LEN"]

    return self.append_command(RequestType.LCS, args)

lindex(key, index)

Returns the element at index in the list stored at key.

The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here, -1 means the last element, -2 means the penultimate and so forth.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
index int

The index of the element in the list to retrieve.

required
Command response

Optional[bytes]: The element at index in the list stored at key.

If index is out of range or if key does not exist, None is returned.

Source code in glide/async_commands/transaction.py
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
def lindex(
    self: TTransaction,
    key: TEncodable,
    index: int,
) -> TTransaction:
    """
    Returns the element at `index` in the list stored at `key`.

    The index is zero-based, so 0 means the first element, 1 the second element and so on.
    Negative indices can be used to designate elements starting at the tail of the list.
    Here, -1 means the last element, -2 means the penultimate and so forth.

    See [valkey.io](https://valkey.io/commands/lindex/) for more details.

    Args:
        key (TEncodable): The key of the list.
        index (int): The index of the element in the list to retrieve.

    Command response:
        Optional[bytes]: The element at `index` in the list stored at `key`.

        If `index` is out of range or if `key` does not exist, None is returned.
    """
    return self.append_command(RequestType.LIndex, [key, str(index)])

linsert(key, position, pivot, element)

Inserts element in the list at key either before or after the pivot.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
position InsertPosition

The relative position to insert into - either InsertPosition.BEFORE or InsertPosition.AFTER the pivot.

required
pivot TEncodable

An element of the list.

required
element TEncodable

The new element to insert.

required
Command response

int: The list length after a successful insert operation.

If the key doesn't exist returns -1.

If the pivot wasn't found, returns 0.

Source code in glide/async_commands/transaction.py
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
def linsert(
    self: TTransaction,
    key: TEncodable,
    position: InsertPosition,
    pivot: TEncodable,
    element: TEncodable,
) -> TTransaction:
    """
    Inserts `element` in the list at `key` either before or after the `pivot`.

    See [valkey.io](https://valkey.io/commands/linsert/) for details.

    Args:
        key (TEncodable): The key of the list.
        position (InsertPosition): The relative position to insert into - either `InsertPosition.BEFORE` or
            `InsertPosition.AFTER` the `pivot`.
        pivot (TEncodable): An element of the list.
        element (TEncodable): The new element to insert.

    Command response:
        int: The list length after a successful insert operation.

        If the `key` doesn't exist returns `-1`.

        If the `pivot` wasn't found, returns `0`.
    """
    return self.append_command(
        RequestType.LInsert, [key, position.value, pivot, element]
    )

llen(key)

Get the length of the list stored at key.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
Commands response

int: The length of the list at the specified key.

If key does not exist, it is interpreted as an empty list and 0 is returned.

Source code in glide/async_commands/transaction.py
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
def llen(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Get the length of the list stored at `key`.

    See [valkey.io](https://valkey.io/commands/llen/) for details.

    Args:
        key (TEncodable): The key of the list.

    Commands response:
        int: The length of the list at the specified key.

        If `key` does not exist, it is interpreted as an empty list and 0 is returned.
    """
    return self.append_command(RequestType.LLen, [key])

lmove(source, destination, where_from, where_to)

Atomically pops and removes the left/right-most element to the list stored at source depending on where_from, and pushes the element at the first/last element of the list stored at destination depending on where_to.

See valkey.io for details.

Parameters:

Name Type Description Default
source TEncodable

The key to the source list.

required
destination TEncodable

The key to the destination list.

required
where_from ListDirection

The direction to remove the element from (ListDirection.LEFT or ListDirection.RIGHT).

required
where_to ListDirection

The direction to add the element to (ListDirection.LEFT or ListDirection.RIGHT).

required
Command response

Optional[bytes]: The popped element.

None if source does not exist.

Since: Valkey version 6.2.0.

Source code in glide/async_commands/transaction.py
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
def lmove(
    self: TTransaction,
    source: TEncodable,
    destination: TEncodable,
    where_from: ListDirection,
    where_to: ListDirection,
) -> TTransaction:
    """
    Atomically pops and removes the left/right-most element to the list stored at `source`
    depending on `where_from`, and pushes the element at the first/last element of the list
    stored at `destination` depending on `where_to`.

    See [valkey.io](https://valkey.io/commands/lmove/) for details.

    Args:
        source (TEncodable): The key to the source list.
        destination (TEncodable): The key to the destination list.
        where_from (ListDirection): The direction to remove the element from
            (`ListDirection.LEFT` or `ListDirection.RIGHT`).
        where_to (ListDirection): The direction to add the element to
            (`ListDirection.LEFT` or `ListDirection.RIGHT`).

    Command response:
        Optional[bytes]: The popped element.

        `None` if `source` does not exist.

    Since: Valkey version 6.2.0.
    """
    return self.append_command(
        RequestType.LMove, [source, destination, where_from.value, where_to.value]
    )

lmpop(keys, direction, count=None)

Pops one or more elements from the first non-empty list from the provided keys.

See valkey.io for details.

Parameters:

Name Type Description Default
keys List[TEncodable]

An array of keys of lists.

required
direction ListDirection

The direction based on which elements are popped from (ListDirection.LEFT or ListDirection.RIGHT).

required
count Optional[int]

The maximum number of popped elements. If not provided, defaults to popping a single element.

None
Command response

Optional[Mapping[bytes, List[bytes]]]: A map of key name mapped to an array of popped elements.

None if no elements could be popped.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
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
def lmpop(
    self: TTransaction,
    keys: List[TEncodable],
    direction: ListDirection,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Pops one or more elements from the first non-empty list from the provided `keys`.

    See [valkey.io](https://valkey.io/commands/lmpop/) for details.

    Args:
        keys (List[TEncodable]): An array of keys of lists.
        direction (ListDirection): The direction based on which elements are popped from
            (`ListDirection.LEFT` or `ListDirection.RIGHT`).
        count (Optional[int]): The maximum number of popped elements. If not provided,
            defaults to popping a single element.

    Command response:
        Optional[Mapping[bytes, List[bytes]]]: A map of `key` name mapped to an array of popped elements.

        None if no elements could be popped.

    Since: Valkey version 7.0.0.
    """
    args = [str(len(keys)), *keys, direction.value]
    if count is not None:
        args += ["COUNT", str(count)]

    return self.append_command(RequestType.LMPop, args)

lolwut(version=None, parameters=None)

Displays a piece of generative computer art and the Valkey version.

See valkey.io for more details.

Parameters:

Name Type Description Default
version Optional[int]

Version of computer art to generate.

None
parameters Optional[List[int]]

Additional set of arguments in order to change the output:

  • For version 5, those are length of the line, number of squares per row, and number of squares per column.
  • For version 6, those are number of columns and number of lines.
None
Command Response

bytes: A piece of generative computer art along with the current Valkey version.

Source code in glide/async_commands/transaction.py
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
def lolwut(
    self: TTransaction,
    version: Optional[int] = None,
    parameters: Optional[List[int]] = None,
) -> TTransaction:
    """
    Displays a piece of generative computer art and the Valkey version.

    See [valkey.io](https://valkey.io/commands/lolwut) for more details.

    Args:
        version (Optional[int]): Version of computer art to generate.
        parameters (Optional[List[int]]): Additional set of arguments in order to change the output:

            - For version `5`, those are length of the line, number of squares per row, and number of squares per column.
            - For version `6`, those are number of columns and number of lines.

    Command Response:
        bytes: A piece of generative computer art along with the current Valkey version.
    """
    args: List[TEncodable] = []
    if version is not None:
        args.extend(["VERSION", str(version)])
    if parameters:
        for var in parameters:
            args.extend(str(var))
    return self.append_command(RequestType.Lolwut, args)

lpop(key)

Remove and return the first elements of the list stored at key. The command pops a single element from the beginning of the list.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
Command response

Optional[bytes]: The value of the first element.

If key does not exist, None will be returned.

Source code in glide/async_commands/transaction.py
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
def lpop(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Remove and return the first elements of the list stored at `key`.
    The command pops a single element from the beginning of the list.

    See [valkey.io](https://valkey.io/commands/lpop/) for details.

    Args:
        key (TEncodable): The key of the list.

    Command response:
        Optional[bytes]: The value of the first element.

        If `key` does not exist, None will be returned.
    """
    return self.append_command(RequestType.LPop, [key])

lpop_count(key, count)

Remove and return up to count elements from the list stored at key, depending on the list's length.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
count int

The count of elements to pop from the list.

required
Command response

Optional[List[bytes]]: A a list of popped elements will be returned depending on the list's length.

If key does not exist, None will be returned.

Source code in glide/async_commands/transaction.py
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
def lpop_count(self: TTransaction, key: TEncodable, count: int) -> TTransaction:
    """
    Remove and return up to `count` elements from the list stored at `key`, depending on the list's length.

    See [valkey.io](https://valkey.io/commands/lpop/) for details.

    Args:
        key (TEncodable): The key of the list.
        count (int): The count of elements to pop from the list.

    Command response:
        Optional[List[bytes]]: A a list of popped elements will be returned depending on the list's length.

        If `key` does not exist, None will be returned.
    """
    return self.append_command(RequestType.LPop, [key, str(count)])

lpos(key, element, rank=None, count=None, max_len=None)

Returns the index or indexes of element(s) matching element in the key list. If no match is found, None is returned.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The name of the list.

required
element TEncodable

The value to search for within the list.

required
rank Optional[int]

The rank of the match to return.

None
count Optional[int]

The number of matches wanted. A count of 0 returns all the matches.

None
max_len Optional[int]

The maximum number of comparisons to make between the element and the items in the list. A max_len of 0 means unlimited amount of comparisons.

None
Command Response

Union[int, List[int], None]: The index of the first occurrence of element.

None if element is not in the list.

With the count option, a list of indices of matching elements will be returned.

Since: Valkey version 6.0.6.

Source code in glide/async_commands/transaction.py
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
def lpos(
    self: TTransaction,
    key: TEncodable,
    element: TEncodable,
    rank: Optional[int] = None,
    count: Optional[int] = None,
    max_len: Optional[int] = None,
) -> TTransaction:
    """
    Returns the index or indexes of element(s) matching `element` in the `key` list. If no match is found,
    None is returned.

    See [valkey.io](https://valkey.io/commands/lpos) for more details.

    Args:
        key (TEncodable): The name of the list.
        element (TEncodable): The value to search for within the list.
        rank (Optional[int]): The rank of the match to return.
        count (Optional[int]): The number of matches wanted. A `count` of 0 returns all the matches.
        max_len (Optional[int]): The maximum number of comparisons to make between the element and the items
            in the list. A `max_len` of 0 means unlimited amount of comparisons.

    Command Response:
        Union[int, List[int], None]: The index of the first occurrence of `element`.

        None if `element` is not in the list.

        With the `count` option, a list of indices of matching elements will be returned.

    Since: Valkey version 6.0.6.
    """
    args = [key, element]

    if rank is not None:
        args.extend(["RANK", str(rank)])

    if count is not None:
        args.extend(["COUNT", str(count)])

    if max_len is not None:
        args.extend(["MAXLEN", str(max_len)])

    return self.append_command(RequestType.LPos, args)

lpush(key, elements)

Insert all the specified values at the head of the list stored at key. elements are inserted one after the other to the head of the list, from the leftmost element to the rightmost element. If key does not exist, it is created as empty list before performing the push operations.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
elements List[TEncodable]

The elements to insert at the head of the list stored at key.

required
Command response

int: The length of the list after the push operations.

Source code in glide/async_commands/transaction.py
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
def lpush(
    self: TTransaction, key: TEncodable, elements: List[TEncodable]
) -> TTransaction:
    """
    Insert all the specified values at the head of the list stored at `key`.
    `elements` are inserted one after the other to the head of the list, from the leftmost element
    to the rightmost element. If `key` does not exist, it is created as empty list before performing the push operations.

    See [valkey.io](https://valkey.io/commands/lpush/) for more details.

    Args:
        key (TEncodable): The key of the list.
        elements (List[TEncodable]): The elements to insert at the head of the list stored at `key`.

    Command response:
        int: The length of the list after the push operations.
    """
    return self.append_command(RequestType.LPush, [key] + elements)

lpushx(key, elements)

Inserts all the specified values at the head of the list stored at key, only if key exists and holds a list. If key is not a list, this performs no operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
elements List[TEncodable]

The elements to insert at the head of the list stored at key.

required
Command response

int: The length of the list after the push operation.

Source code in glide/async_commands/transaction.py
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
def lpushx(
    self: TTransaction, key: TEncodable, elements: List[TEncodable]
) -> TTransaction:
    """
    Inserts all the specified values at the head of the list stored at `key`, only if `key` exists and holds a list.
    If `key` is not a list, this performs no operation.

    See [valkey.io](https://valkey.io/commands/lpushx/) for more details.

    Args:
        key (TEncodable): The key of the list.
        elements (List[TEncodable]): The elements to insert at the head of the list stored at `key`.

    Command response:
        int: The length of the list after the push operation.
    """
    return self.append_command(RequestType.LPushX, [key] + elements)

lrange(key, start, end)

Retrieve the specified elements of the list stored at key within the given range. The offsets start and end are zero-based indexes, with 0 being the first element of the list, 1 being the next element and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list, with -1 being the last element of the list, -2 being the penultimate, and so on.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
start int

The starting point of the range.

required
end int

The end of the range.

required
Command response

List[byte]: A list of elements within the specified range.

If start exceeds the end of the list, or if start is greater than end, an empty list will be returned.

If end exceeds the actual end of the list, the range will stop at the actual end of the list.

If key does not exist an empty list will be returned.

Source code in glide/async_commands/transaction.py
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
def lrange(
    self: TTransaction, key: TEncodable, start: int, end: int
) -> TTransaction:
    """
    Retrieve the specified elements of the list stored at `key` within the given range.
    The offsets `start` and `end` are zero-based indexes, with 0 being the first element of the list, 1 being the next
    element and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list,
    with -1 being the last element of the list, -2 being the penultimate, and so on.

    See [valkey.io](https://valkey.io/commands/lrange/) for details.

    Args:
        key (TEncodable): The key of the list.
        start (int): The starting point of the range.
        end (int): The end of the range.

    Command response:
        List[byte]: A list of elements within the specified range.

        If `start` exceeds the `end` of the list, or if `start` is greater than `end`, an empty list will be returned.

        If `end` exceeds the actual end of the list, the range will stop at the actual end of the list.

        If `key` does not exist an empty list will be returned.
    """
    return self.append_command(RequestType.LRange, [key, str(start), str(end)])

lrem(key, count, element)

Removes the first count occurrences of elements equal to element from the list stored at key. If count is positive, it removes elements equal to element moving from head to tail. If count is negative, it removes elements equal to element moving from tail to head. If count is 0 or greater than the occurrences of elements equal to element, it removes all elements equal to element.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
count int

The count of occurrences of elements equal to element to remove.

required
element TEncodable

The element to remove from the list.

required
Commands response

int: The number of removed elements.

If key does not exist, 0 is returned.

Source code in glide/async_commands/transaction.py
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
def lrem(
    self: TTransaction,
    key: TEncodable,
    count: int,
    element: TEncodable,
) -> TTransaction:
    """
    Removes the first `count` occurrences of elements equal to `element` from the list stored at `key`.
    If `count` is positive, it removes elements equal to `element` moving from head to tail.
    If `count` is negative, it removes elements equal to `element` moving from tail to head.
    If `count` is 0 or greater than the occurrences of elements equal to `element`, it removes all elements
    equal to `element`.

    See [valkey.io](https://valkey.io/commands/lrem/) for more details.

    Args:
        key (TEncodable): The key of the list.
        count (int): The count of occurrences of elements equal to `element` to remove.
        element (TEncodable): The element to remove from the list.

    Commands response:
        int: The number of removed elements.

        If `key` does not exist, 0 is returned.
    """
    return self.append_command(RequestType.LRem, [key, str(count), element])

lset(key, index, element)

Sets the list element at index to element.

The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here, -1 means the last element, -2 means the penultimate and so forth.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
index int

The index of the element in the list to be set.

required
element TEncodable

The new element to set at the specified index.

required
Commands response

TOK: A simple OK response.

Source code in glide/async_commands/transaction.py
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
def lset(
    self: TTransaction,
    key: TEncodable,
    index: int,
    element: TEncodable,
) -> TTransaction:
    """
    Sets the list element at `index` to `element`.

    The index is zero-based, so `0` means the first element, `1` the second element and so on.
    Negative indices can be used to designate elements starting at the tail of the list.
    Here, `-1` means the last element, `-2` means the penultimate and so forth.

    See [valkey.io](https://valkey.io/commands/lset/) for details.

    Args:
        key (TEncodable): The key of the list.
        index (int): The index of the element in the list to be set.
        element (TEncodable): The new element to set at the specified index.

    Commands response:
        TOK: A simple `OK` response.
    """
    return self.append_command(RequestType.LSet, [key, str(index), element])

ltrim(key, start, end)

Trim an existing list so that it will contain only the specified range of elements specified. The offsets start and end are zero-based indexes, with 0 being the first element of the list, 1 being the next element and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list, with -1 being the last element of the list, -2 being the penultimate, and so on.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
start int

The starting point of the range.

required
end int

The end of the range.

required
Commands response

TOK: A simple "OK" response.

If start exceeds the end of the list, or if start is greater than end, the result will be an empty list (which causes key to be removed).

If end exceeds the actual end of the list, it will be treated like the last element of the list.

If key does not exist, the response will be "OK" without changes to the database.

Source code in glide/async_commands/transaction.py
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
def ltrim(
    self: TTransaction, key: TEncodable, start: int, end: int
) -> TTransaction:
    """
    Trim an existing list so that it will contain only the specified range of elements specified.
    The offsets `start` and `end` are zero-based indexes, with 0 being the first element of the list, 1 being the next
    element and so on.
    These offsets can also be negative numbers indicating offsets starting at the end of the list, with -1 being the last
    element of the list, -2 being the penultimate, and so on.

    See [valkey.io](https://valkey.io/commands/ltrim/) for more details.

    Args:
        key (TEncodable): The key of the list.
        start (int): The starting point of the range.
        end (int): The end of the range.

    Commands response:
        TOK: A simple "OK" response.

        If `start` exceeds the end of the list, or if `start` is greater than `end`, the result will be an empty list
        (which causes `key` to be removed).

        If `end` exceeds the actual end of the list, it will be treated like the last element of the list.

        If `key` does not exist, the response will be "OK" without changes to the database.
    """
    return self.append_command(RequestType.LTrim, [key, str(start), str(end)])

mget(keys)

Retrieve the values of multiple keys.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

A list of keys to retrieve values for.

required
Command response

List[Optional[bytes]]: A list of values corresponding to the provided keys. If a key is not found, its corresponding value in the list will be None.

Source code in glide/async_commands/transaction.py
431
432
433
434
435
436
437
438
439
440
441
442
443
444
def mget(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Retrieve the values of multiple keys.

    See [valkey.io](https://valkey.io/commands/mget/) for more details.

    Args:
        keys (List[TEncodable]): A list of keys to retrieve values for.

    Command response:
        List[Optional[bytes]]: A list of values corresponding to the provided keys. If a key is not found,
        its corresponding value in the list will be None.
    """
    return self.append_command(RequestType.MGet, keys)

mset(key_value_map)

Set multiple keys to multiple values in a single atomic operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
parameters Mapping[TEncodable, TEncodable]

A map of key value pairs.

required
Command response

OK: a simple OK response.

Source code in glide/async_commands/transaction.py
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
def mset(
    self: TTransaction, key_value_map: Mapping[TEncodable, TEncodable]
) -> TTransaction:
    """
    Set multiple keys to multiple values in a single atomic operation.

    See [valkey.io](https://valkey.io/commands/mset/) for more details.

    Args:
        parameters (Mapping[TEncodable, TEncodable]): A map of key value pairs.

    Command response:
        OK: a simple OK response.
    """
    parameters: List[TEncodable] = []
    for pair in key_value_map.items():
        parameters.extend(pair)
    return self.append_command(RequestType.MSet, parameters)

msetnx(key_value_map)

Sets multiple keys to values if the key does not exist. The operation is atomic, and if one or more keys already exist, the entire operation fails.

See valkey.io for more details.

Parameters:

Name Type Description Default
key_value_map Mapping[TEncodable, TEncodable]

A key-value map consisting of keys and their respective values to set.

required
Commands response

bool: True if all keys were set.

False if no key was set.

Source code in glide/async_commands/transaction.py
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
def msetnx(
    self: TTransaction, key_value_map: Mapping[TEncodable, TEncodable]
) -> TTransaction:
    """
    Sets multiple keys to values if the key does not exist. The operation is atomic, and if one or
    more keys already exist, the entire operation fails.

    See [valkey.io](https://valkey.io/commands/msetnx/) for more details.

    Args:
        key_value_map (Mapping[TEncodable, TEncodable]): A key-value map consisting of keys and their respective
            values to set.

    Commands response:
        bool: True if all keys were set.

        False if no key was set.
    """
    parameters: List[TEncodable] = []
    for pair in key_value_map.items():
        parameters.extend(pair)
    return self.append_command(RequestType.MSetNX, parameters)

object_encoding(key)

Returns the internal encoding for the Valkey object stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the object to get the internal encoding of.

required
Command response

Optional[bytes]: If key exists, returns the internal encoding of the object stored at key as a bytes string.

Otherwise, returns None.

Source code in glide/async_commands/transaction.py
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
def object_encoding(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the internal encoding for the Valkey object stored at `key`.

    See [valkey.io](https://valkey.io/commands/object-encoding) for more details.

    Args:
        key (TEncodable): The `key` of the object to get the internal encoding of.

    Command response:
        Optional[bytes]: If `key` exists, returns the internal encoding of the object stored at
        `key` as a bytes string.

        Otherwise, returns None.
    """
    return self.append_command(RequestType.ObjectEncoding, [key])

object_freq(key)

Returns the logarithmic access frequency counter of a Valkey object stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the object to get the logarithmic access frequency counter of.

required
Command response

Optional[int]: If key exists, returns the logarithmic access frequency counter of the object stored at key as an integer.

Otherwise, returns None.

Source code in glide/async_commands/transaction.py
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
def object_freq(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the logarithmic access frequency counter of a Valkey object stored at `key`.

    See [valkey.io](https://valkey.io/commands/object-freq) for more details.

    Args:
        key (TEncodable): The key of the object to get the logarithmic access frequency counter of.

    Command response:
        Optional[int]: If `key` exists, returns the logarithmic access frequency counter of the object stored at `key` as
        an integer.

        Otherwise, returns None.
    """
    return self.append_command(RequestType.ObjectFreq, [key])

object_idletime(key)

Returns the time in seconds since the last access to the value stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the object to get the idle time of.

required
Command response

Optional[int]: If key exists, returns the idle time in seconds.

Otherwise, returns None.

Source code in glide/async_commands/transaction.py
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
def object_idletime(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the time in seconds since the last access to the value stored at `key`.

    See [valkey.io](https://valkey.io/commands/object-idletime) for more details.

    Args:
        key (TEncodable): The key of the object to get the idle time of.

    Command response:
        Optional[int]: If `key` exists, returns the idle time in seconds.

        Otherwise, returns None.
    """
    return self.append_command(RequestType.ObjectIdleTime, [key])

object_refcount(key)

Returns the reference count of the object stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the object to get the reference count of.

required
Command response

Optional[int]: If key exists, returns the reference count of the object stored at key as an integer.

Otherwise, returns None.

Source code in glide/async_commands/transaction.py
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
def object_refcount(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the reference count of the object stored at `key`.

    See [valkey.io](https://valkey.io/commands/object-refcount) for more details.

    Args:
        key (TEncodable): The key of the object to get the reference count of.

    Command response:
        Optional[int]: If `key` exists, returns the reference count of the object stored at `key` as an integer.

        Otherwise, returns None.
    """
    return self.append_command(RequestType.ObjectRefCount, [key])

persist(key)

Remove the existing timeout on key, turning the key from volatile (a key with an expire set) to persistent (a key that will never expire as no timeout is associated).

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to remove the existing timeout on.

required
Commands response

bool: False if key does not exist or does not have an associated timeout.

True if the timeout has been removed.

Source code in glide/async_commands/transaction.py
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
def persist(
    self: TTransaction,
    key: TEncodable,
) -> TTransaction:
    """
    Remove the existing timeout on `key`, turning the key from volatile (a key with an expire set) to
    persistent (a key that will never expire as no timeout is associated).

    See [valkey.io](https://valkey.io/commands/persist/) for more details.

    Args:
        key (TEncodable): The key to remove the existing timeout on.

    Commands response:
        bool: False if `key` does not exist or does not have an associated timeout.

        True if the timeout has been removed.
    """
    return self.append_command(RequestType.Persist, [key])

pexpire(key, milliseconds, option=None)

Sets a timeout on key in milliseconds. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. If milliseconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to set a timeout on.

required
milliseconds int

The timeout in milliseconds.

required
option Optional[ExpireOptions]

The expire option.

None
Commands response

bool: True if the timeout was set.

False if the timeout was not set (e.g., the key doesn't exist or the operation is skipped due to the provided arguments).

Source code in glide/async_commands/transaction.py
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
def pexpire(
    self: TTransaction,
    key: TEncodable,
    milliseconds: int,
    option: Optional[ExpireOptions] = None,
) -> TTransaction:
    """
    Sets a timeout on `key` in milliseconds. After the timeout has expired, the key will automatically be deleted.
    If `key` already has an existing expire set, the time to live is updated to the new value.
    If `milliseconds` is a non-positive number, the key will be deleted rather than expired.
    The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

    See [valkey.io](https://valkey.io/commands/pexpire/) for more details.

    Args:
        key (TEncodable): The key to set a timeout on.
        milliseconds (int): The timeout in milliseconds.
        option (Optional[ExpireOptions]): The expire option.

    Commands response:
        bool: `True` if the timeout was set.

        `False` if the timeout was not set (e.g., the key doesn't exist or the operation
        is skipped due to the provided arguments).
    """
    args = (
        [key, str(milliseconds)]
        if option is None
        else [key, str(milliseconds), option.value]
    )
    return self.append_command(RequestType.PExpire, args)

pexpireat(key, unix_milliseconds, option=None)

Sets a timeout on key using an absolute Unix timestamp in milliseconds (milliseconds since January 1, 1970) instead of specifying the number of milliseconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to set a timeout on.

required
unix_milliseconds int

The timeout in an absolute Unix timestamp in milliseconds.

required
option Optional[ExpireOptions]

The expire option.

None
Commands response

bool: True if the timeout was set.

False if the timeout was not set (e.g., the key doesn't exist or the operation is skipped due to the provided arguments).

Source code in glide/async_commands/transaction.py
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
def pexpireat(
    self: TTransaction,
    key: TEncodable,
    unix_milliseconds: int,
    option: Optional[ExpireOptions] = None,
) -> TTransaction:
    """
    Sets a timeout on `key` using an absolute Unix timestamp in milliseconds (milliseconds since January 1, 1970) instead
    of specifying the number of milliseconds.
    A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be
    deleted.
    If `key` already has an existing expire set, the time to live is updated to the new value.
    The timeout will only be cleared by commands that delete or overwrite the contents of `key`.

    See [valkey.io](https://valkey.io/commands/pexpireat/) for more details.

    Args:
        key (TEncodable): The key to set a timeout on.
        unix_milliseconds (int): The timeout in an absolute Unix timestamp in milliseconds.
        option (Optional[ExpireOptions]): The expire option.

    Commands response:
        bool: `True` if the timeout was set.

        `False` if the timeout was not set (e.g., the key doesn't exist or the operation
        is skipped due to the provided arguments).
    """
    args = (
        [key, str(unix_milliseconds)]
        if option is None
        else [key, str(unix_milliseconds), option.value]
    )
    return self.append_command(RequestType.PExpireAt, args)

pexpiretime(key)

Returns the absolute Unix timestamp (since January 1, 1970) at which the given key will expire, in milliseconds.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key to determine the expiration value of.

required
Commands response

int: The expiration Unix timestamp in milliseconds.

-2 if key does not exist.

-1 if key exists but has no associated expiration.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
def pexpiretime(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the absolute Unix timestamp (since January 1, 1970) at which
    the given `key` will expire, in milliseconds.

    See [valkey.io](https://valkey.io/commands/pexpiretime/) for details.

    Args:
        key (TEncodable): The `key` to determine the expiration value of.

    Commands response:
        int: The expiration Unix timestamp in milliseconds.

        -2 if `key` does not exist.

        -1 if `key` exists but has no associated expiration.

    Since: Valkey version 7.0.0.
    """
    return self.append_command(RequestType.PExpireTime, [key])

pfadd(key, elements)

Adds all elements to the HyperLogLog data structure stored at the specified key. Creates a new structure if the key does not exist. When no elements are provided, and key exists and is a HyperLogLog, then no operation is performed.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the HyperLogLog data structure to add elements into.

required
elements List[TEncodable]

A list of members to add to the HyperLogLog stored at key.

required
Commands response

int: If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is altered, then returns 1.

Otherwise, returns 0.

Source code in glide/async_commands/transaction.py
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
def pfadd(
    self: TTransaction, key: TEncodable, elements: List[TEncodable]
) -> TTransaction:
    """
    Adds all elements to the HyperLogLog data structure stored at the specified `key`.
    Creates a new structure if the `key` does not exist.
    When no elements are provided, and `key` exists and is a HyperLogLog, then no operation is performed.

    See [valkey.io](https://valkey.io/commands/pfadd/) for more details.

    Args:
        key (TEncodable): The key of the HyperLogLog data structure to add elements into.
        elements (List[TEncodable]): A list of members to add to the HyperLogLog stored at `key`.

    Commands response:
        int: If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is
        altered, then returns 1.

        Otherwise, returns 0.
    """
    return self.append_command(RequestType.PfAdd, [key] + elements)

pfcount(keys)

Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or calculates the combined cardinality of multiple keys by merging their HyperLogLogs temporarily.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the HyperLogLog data structures to be analyzed.

required
Command response

int: The approximated cardinality of given HyperLogLog data structures. The cardinality of a key that does not exist is 0.

Source code in glide/async_commands/transaction.py
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
def pfcount(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or
    calculates the combined cardinality of multiple keys by merging their HyperLogLogs temporarily.

    See [valkey.io](https://valkey.io/commands/pfcount) for more details.

    Args:
        keys (List[TEncodable]): The keys of the HyperLogLog data structures to be analyzed.

    Command response:
        int: The approximated cardinality of given HyperLogLog data structures.
        The cardinality of a key that does not exist is 0.
    """
    return self.append_command(RequestType.PfCount, keys)

pfmerge(destination, source_keys)

Merges multiple HyperLogLog values into a unique value. If the destination variable exists, it is treated as one of the source HyperLogLog data sets, otherwise a new HyperLogLog is created.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key of the destination HyperLogLog where the merged data sets will be stored.

required
source_keys List[TEncodable]

The keys of the HyperLogLog structures to be merged.

required
Command response

OK: A simple OK response.

Source code in glide/async_commands/transaction.py
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
def pfmerge(
    self: TTransaction,
    destination: TEncodable,
    source_keys: List[TEncodable],
) -> TTransaction:
    """
    Merges multiple HyperLogLog values into a unique value. If the destination variable exists, it is treated as one
    of the source HyperLogLog data sets, otherwise a new HyperLogLog is created.

    See [valkey.io](https://valkey.io/commands/pfmerge) for more details.

    Args:
        destination (TEncodable): The key of the destination HyperLogLog where the merged data sets will be stored.
        source_keys (List[TEncodable]): The keys of the HyperLogLog structures to be merged.

    Command response:
        OK: A simple OK response.
    """
    return self.append_command(RequestType.PfMerge, [destination] + source_keys)

ping(message=None)

Ping the server.

See valkey.io for more details.

Parameters:

Name Type Description Default
message Optional[TEncodable]

An optional message to include in the PING command. If not provided,

None
Command response

bytes: b"PONG" if message is not provided, otherwise return a copy of message.

Source code in glide/async_commands/transaction.py
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
def ping(self: TTransaction, message: Optional[TEncodable] = None) -> TTransaction:
    """
    Ping the server.

    See [valkey.io](https://valkey.io/commands/ping/) for more details.

    Args:
        message (Optional[TEncodable]): An optional message to include in the PING command. If not provided,
        the server will respond with "PONG". If provided, the server will respond with a copy of the message.

    Command response:
       bytes: b"PONG" if `message` is not provided, otherwise return a copy of `message`.
    """
    argument = [] if message is None else [message]
    return self.append_command(RequestType.Ping, argument)

pttl(key)

Returns the remaining time to live of key that has a timeout, in milliseconds.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to return its timeout.

required
Commands Response

int: TTL in milliseconds.

-2 if key does not exist.

-1 if key exists but has no associated expire.

Source code in glide/async_commands/transaction.py
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
def pttl(
    self: TTransaction,
    key: TEncodable,
) -> TTransaction:
    """
    Returns the remaining time to live of `key` that has a timeout, in milliseconds.

    See [valkey.io](https://valkey.io/commands/pttl) for more details.

    Args:
        key (TEncodable): The key to return its timeout.

    Commands Response:
        int: TTL in milliseconds.

        -2 if `key` does not exist.

        -1 if `key` exists but has no associated expire.
    """
    return self.append_command(RequestType.PTTL, [key])

pubsub_channels(pattern=None)

Lists the currently active channels.

See valkey.io for details.

Parameters:

Name Type Description Default
pattern Optional[TEncodable]

A glob-style pattern to match active channels. If not provided, all active channels are returned.

None
Command response

List[bytes]: A list of currently active channels matching the given pattern.

If no pattern is specified, all active channels are returned.

Source code in glide/async_commands/transaction.py
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
def pubsub_channels(
    self: TTransaction, pattern: Optional[TEncodable] = None
) -> TTransaction:
    """
    Lists the currently active channels.

    See [valkey.io](https://valkey.io/commands/pubsub-channels) for details.

    Args:
        pattern (Optional[TEncodable]): A glob-style pattern to match active channels.
            If not provided, all active channels are returned.

    Command response:
        List[bytes]: A list of currently active channels matching the given pattern.

        If no pattern is specified, all active channels are returned.
    """

    return self.append_command(
        RequestType.PubSubChannels, [pattern] if pattern else []
    )

pubsub_numpat()

Returns the number of unique patterns that are subscribed to by clients.

Note

This is the total number of unique patterns all the clients are subscribed to, not the count of clients subscribed to patterns.

See valkey.io for details.

Command response

int: The number of unique patterns.

Source code in glide/async_commands/transaction.py
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
def pubsub_numpat(self: TTransaction) -> TTransaction:
    """
    Returns the number of unique patterns that are subscribed to by clients.

    Note:
        This is the total number of unique patterns all the clients are subscribed to,
        not the count of clients subscribed to patterns.

    See [valkey.io](https://valkey.io/commands/pubsub-numpat) for details.

    Command response:
        int: The number of unique patterns.
    """
    return self.append_command(RequestType.PubSubNumPat, [])

pubsub_numsub(channels=None)

Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.

Note

It is valid to call this command without channels. In this case, it will just return an empty map.

See valkey.io for details.

Parameters:

Name Type Description Default
channels Optional[List[str]]

The list of channels to query for the number of subscribers. If not provided, returns an empty map.

None
Command response

Mapping[bytes, int]: A map where keys are the channel names and values are the number of subscribers.

Source code in glide/async_commands/transaction.py
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
def pubsub_numsub(
    self: TTransaction, channels: Optional[List[TEncodable]] = None
) -> TTransaction:
    """
    Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.

    Note:
        It is valid to call this command without channels. In this case, it will just return an empty map.

    See [valkey.io](https://valkey.io/commands/pubsub-numsub) for details.

    Args:
        channels (Optional[List[str]]): The list of channels to query for the number of subscribers.
            If not provided, returns an empty map.

    Command response:
        Mapping[bytes, int]: A map where keys are the channel names and values are the number of subscribers.
    """
    return self.append_command(
        RequestType.PubSubNumSub, channels if channels else []
    )

random_key()

Returns a random existing key name.

See valkey.io for more details.

Command response

Optional[bytes]: A random existing key name.

Source code in glide/async_commands/transaction.py
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
def random_key(self: TTransaction) -> TTransaction:
    """
    Returns a random existing key name.

    See [valkey.io](https://valkey.io/commands/randomkey) for more details.

    Command response:
        Optional[bytes]: A random existing key name.
    """
    return self.append_command(RequestType.RandomKey, [])

rename(key, new_key)

Renames key to new_key. If newkey already exists it is overwritten.

Note

In Cluster mode, both key and newkey must be in the same hash slot, meaning that in practice only keys that have the same hash tag can be reliably renamed in cluster.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable)

The key to rename.

required
new_key TEncodable)

The new name of the key.

required
Command response

OK: If the key was successfully renamed, return "OK".

If key does not exist, the transaction fails with an error.

Source code in glide/async_commands/transaction.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def rename(
    self: TTransaction, key: TEncodable, new_key: TEncodable
) -> TTransaction:
    """
    Renames `key` to `new_key`.
    If `newkey` already exists it is overwritten.

    Note:
        In Cluster mode, both `key` and `newkey` must be in the same hash slot,
        meaning that in practice only keys that have the same hash tag can be reliably renamed in cluster.

    See [valkey.io](https://valkey.io/commands/rename/) for more details.

    Args:
        key (TEncodable) : The key to rename.
        new_key (TEncodable) : The new name of the key.

    Command response:
        OK: If the `key` was successfully renamed, return "OK".

        If `key` does not exist, the transaction fails with an error.
    """
    return self.append_command(RequestType.Rename, [key, new_key])

renamenx(key, new_key)

Renames key to new_key if new_key does not yet exist.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to rename.

required
new_key TEncodable

The new key name.

required
Command response

bool: True if key was renamed to new_key.

False if new_key already exists.

Source code in glide/async_commands/transaction.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def renamenx(
    self: TTransaction, key: TEncodable, new_key: TEncodable
) -> TTransaction:
    """
    Renames `key` to `new_key` if `new_key` does not yet exist.

    See [valkey.io](https://valkey.io/commands/renamenx) for more details.

    Args:
        key (TEncodable): The key to rename.
        new_key (TEncodable): The new key name.

    Command response:
        bool: True if `key` was renamed to `new_key`.

        False if `new_key` already exists.
    """
    return self.append_command(RequestType.RenameNX, [key, new_key])

restore(key, ttl, value, replace=False, absttl=False, idletime=None, frequency=None)

Create a key associated with a value that is obtained by deserializing the provided serialized value obtained via dump.

See valkey.io for more details.

Note

IDLETIME and FREQ modifiers cannot be set at the same time.

Parameters:

Name Type Description Default
key TEncodable

The key to create.

required
ttl int

The expiry time (in milliseconds). If 0, the key will persist.

required
replace bool

Set to True to replace the key if it exists.

False
absttl bool

Set to True to specify that ttl represents an absolute Unix timestamp (in milliseconds).

False
idletime Optional[int]

Set the IDLETIME option with object idletime to the given key.

None
frequency Optional[int]

Set the FREQ option with object frequency to the given key.

None
Command response

TOK: A simple "OK" response.

Source code in glide/async_commands/transaction.py
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
def restore(
    self: TTransaction,
    key: TEncodable,
    ttl: int,
    value: TEncodable,
    replace: bool = False,
    absttl: bool = False,
    idletime: Optional[int] = None,
    frequency: Optional[int] = None,
) -> TTransaction:
    """
    Create a `key` associated with a `value` that is obtained by deserializing the provided
    serialized `value` obtained via `dump`.

    See [valkey.io](https://valkey.io/commands/restore) for more details.

    Note:
        `IDLETIME` and `FREQ` modifiers cannot be set at the same time.

    Args:
        key (TEncodable): The `key` to create.
        ttl (int): The expiry time (in milliseconds). If `0`, the `key` will persist.
        value (TEncodable) The serialized value to deserialize and assign to `key`.
        replace (bool): Set to `True` to replace the key if it exists.
        absttl (bool): Set to `True` to specify that `ttl` represents an absolute Unix
            timestamp (in milliseconds).
        idletime (Optional[int]): Set the `IDLETIME` option with object idletime to the given key.
        frequency (Optional[int]): Set the `FREQ` option with object frequency to the given key.

    Command response:
        TOK: A simple "OK" response.
    """
    args = [key, str(ttl), value]
    if replace is True:
        args.append("REPLACE")
    if absttl is True:
        args.append("ABSTTL")
    if idletime is not None:
        args.extend(["IDLETIME", str(idletime)])
    if frequency is not None:
        args.extend(["FREQ", str(frequency)])
    return self.append_command(RequestType.Restore, args)

rpop(key, count=None)

Removes and returns the last elements of the list stored at key. The command pops a single element from the end of the list.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
Commands response

Optional[bytes]: The value of the last element.

If key does not exist, None will be returned.

Source code in glide/async_commands/transaction.py
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
def rpop(
    self: TTransaction, key: TEncodable, count: Optional[int] = None
) -> TTransaction:
    """
    Removes and returns the last elements of the list stored at `key`.
    The command pops a single element from the end of the list.

    See [valkey.io](https://valkey.io/commands/rpop/) for details.

    Args:
        key (TEncodable): The key of the list.

    Commands response:
        Optional[bytes]: The value of the last element.

        If `key` does not exist, None will be returned.
    """
    return self.append_command(RequestType.RPop, [key])

rpop_count(key, count)

Removes and returns up to count elements from the list stored at key, depending on the list's length.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
count int

The count of elements to pop from the list.

required
Commands response

Optional[List[bytes]: A list of popped elements will be returned depending on the list's length.

If key does not exist, None will be returned.

Source code in glide/async_commands/transaction.py
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
def rpop_count(self: TTransaction, key: TEncodable, count: int) -> TTransaction:
    """
    Removes and returns up to `count` elements from the list stored at `key`, depending on the list's length.

    See [valkey.io](https://valkey.io/commands/rpop/) for details.

    Args:
        key (TEncodable): The key of the list.
        count (int): The count of elements to pop from the list.

    Commands response:
        Optional[List[bytes]: A list of popped elements will be returned depending on the list's length.

        If `key` does not exist, None will be returned.
    """
    return self.append_command(RequestType.RPop, [key, str(count)])

rpush(key, elements)

Inserts all the specified values at the tail of the list stored at key. elements are inserted one after the other to the tail of the list, from the leftmost element to the rightmost element. If key does not exist, it is created as empty list before performing the push operations.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
elements List[TEncodable]

The elements to insert at the tail of the list stored at key.

required
Command response

int: The length of the list after the push operations.

If key holds a value that is not a list, the transaction fails.

Source code in glide/async_commands/transaction.py
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
def rpush(
    self: TTransaction, key: TEncodable, elements: List[TEncodable]
) -> TTransaction:
    """
    Inserts all the specified values at the tail of the list stored at `key`.
    `elements` are inserted one after the other to the tail of the list, from the leftmost element
    to the rightmost element. If `key` does not exist, it is created as empty list before performing the push operations.

    See [valkey.io](https://valkey.io/commands/rpush/) for more details.

    Args:
        key (TEncodable): The key of the list.
        elements (List[TEncodable]): The elements to insert at the tail of the list stored at `key`.

    Command response:
        int: The length of the list after the push operations.

        If `key` holds a value that is not a list, the transaction fails.
    """
    return self.append_command(RequestType.RPush, [key] + elements)

rpushx(key, elements)

Inserts all the specified values at the tail of the list stored at key, only if key exists and holds a list. If key is not a list, this performs no operation.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the list.

required
elements List[TEncodable]

The elements to insert at the tail of the list stored at key.

required
Command response

int: The length of the list after the push operation.

Source code in glide/async_commands/transaction.py
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
def rpushx(
    self: TTransaction, key: TEncodable, elements: List[TEncodable]
) -> TTransaction:
    """
    Inserts all the specified values at the tail of the list stored at `key`, only if `key` exists and holds a list.
    If `key` is not a list, this performs no operation.

    See [valkey.io](https://valkey.io/commands/rpushx/) for more details.

    Args:
        key (TEncodable): The key of the list.
        elements (List[TEncodable]): The elements to insert at the tail of the list stored at `key`.

    Command response:
        int: The length of the list after the push operation.
    """
    return self.append_command(RequestType.RPushX, [key] + elements)

sadd(key, members)

Add specified members to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding members.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key where members will be added to its set.

required
members List[TEncodable]

A list of members to add to the set stored at key.

required
Command response

int: The number of members that were added to the set, excluding members already present.

Source code in glide/async_commands/transaction.py
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
def sadd(
    self: TTransaction, key: TEncodable, members: List[TEncodable]
) -> TTransaction:
    """
    Add specified members to the set stored at `key`.
    Specified members that are already a member of this set are ignored.
    If `key` does not exist, a new set is created before adding `members`.

    See [valkey.io](https://valkey.io/commands/sadd/) for more details.

    Args:
        key (TEncodable): The key where members will be added to its set.
        members (List[TEncodable]): A list of members to add to the set stored at key.

    Command response:
        int: The number of members that were added to the set, excluding members already present.
    """
    return self.append_command(RequestType.SAdd, [key] + members)

scard(key)

Retrieve the set cardinality (number of elements) of the set stored at key.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key from which to retrieve the number of set members.

required
Commands response

int: The cardinality (number of elements) of the set.

Returns 0 if the key does not exist.

Source code in glide/async_commands/transaction.py
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
def scard(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Retrieve the set cardinality (number of elements) of the set stored at `key`.

    See [valkey.io](https://valkey.io/commands/scard/) for details.

    Args:
        key (TEncodable): The key from which to retrieve the number of set members.

    Commands response:
        int: The cardinality (number of elements) of the set.

        Returns `0` if the key does not exist.
    """
    return self.append_command(RequestType.SCard, [key])

sdiff(keys)

Computes the difference between the first set and all the successive sets in keys.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sets to diff.

required
Command response

Set[bytes]: A set of elements representing the difference between the sets.

If any of the keys in keys do not exist, they are treated as empty sets.

Source code in glide/async_commands/transaction.py
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
def sdiff(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Computes the difference between the first set and all the successive sets in `keys`.

    See [valkey.io](https://valkey.io/commands/sdiff) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sets to diff.

    Command response:
        Set[bytes]: A set of elements representing the difference between the sets.

        If any of the keys in `keys` do not exist, they are treated as empty sets.
    """
    return self.append_command(RequestType.SDiff, keys)

sdiffstore(destination, keys)

Stores the difference between the first set and all the successive sets in keys into a new set at destination.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key of the destination set.

required
keys List[TEncodable]

The keys of the sets to diff.

required
Command response

int: The number of elements in the resulting set.

Source code in glide/async_commands/transaction.py
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
def sdiffstore(
    self: TTransaction,
    destination: TEncodable,
    keys: List[TEncodable],
) -> TTransaction:
    """
    Stores the difference between the first set and all the successive sets in `keys` into a new set at
    `destination`.

    See [valkey.io](https://valkey.io/commands/sdiffstore) for more details.

    Args:
        destination (TEncodable): The key of the destination set.
        keys (List[TEncodable]): The keys of the sets to diff.

    Command response:
        int: The number of elements in the resulting set.
    """
    return self.append_command(RequestType.SDiffStore, [destination] + keys)

set(key, value, conditional_set=None, expiry=None, return_old_value=False)

Set the given key with the given value. Return value is dependent on the passed options.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

the key to store.

required
value TEncodable

the value to store with the given key.

required
conditional_set Optional[ConditionalChange]

set the key only if the given condition is met. Equivalent to [XX | NX] in the Valkey API. Defaults to None.

None
expiry Optional[ExpirySet]

set expiriation to the given key. Equivalent to [EX | PX | EXAT | PXAT | KEEPTTL] in the Valkey API. Defaults to None.

None
return_old_value bool

Return the old value stored at key, or None if key did not exist. An error is returned and SET aborted if the value stored at key is not a string. Equivalent to GET in the Valkey API. Defaults to False.

False
Command response

Optional[bytes]: If the value is successfully set, return OK.

If value isn't set because of only_if_exists or only_if_does_not_exist conditions, return None.

If return_old_value is set, return the old value as a bytes string.
Example

Set "foo" to "bar" only if "foo" already exists, and set the key expiration to 5 seconds:

connection.set("foo", "bar", conditional_set=ConditionalChange.ONLY_IF_EXISTS, ... expiry=Expiry(ExpiryType.SEC, 5))

Source code in glide/async_commands/transaction.py
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
def set(
    self: TTransaction,
    key: TEncodable,
    value: TEncodable,
    conditional_set: Union[ConditionalChange, None] = None,
    expiry: Union[ExpirySet, None] = None,
    return_old_value: bool = False,
) -> TTransaction:
    """
    Set the given key with the given value. Return value is dependent on the passed options.

    See [valkey.io](https://valkey.io/commands/set/) for details.

    Args:
        key (TEncodable): the key to store.
        value (TEncodable): the value to store with the given key.
        conditional_set (Optional[ConditionalChange], optional): set the key only if the given condition is met.
            Equivalent to [`XX` | `NX`] in the Valkey API. Defaults to None.
        expiry (Optional[ExpirySet], optional): set expiriation to the given key.
            Equivalent to [`EX` | `PX` | `EXAT` | `PXAT` | `KEEPTTL`] in the Valkey API. Defaults to None.
        return_old_value (bool, optional): Return the old value stored at key, or None if key did not exist.
            An error is returned and SET aborted if the value stored at key is not a string.
            Equivalent to `GET` in the Valkey API. Defaults to False.

    Command response:
        Optional[bytes]:
            If the value is successfully set, return OK.

            If value isn't set because of only_if_exists or only_if_does_not_exist conditions, return None.

            If return_old_value is set, return the old value as a bytes string.

    Example:
        Set "foo" to "bar" only if "foo" already exists, and set the key expiration to 5 seconds:

        >>> connection.set("foo", "bar", conditional_set=ConditionalChange.ONLY_IF_EXISTS,
        ... expiry=Expiry(ExpiryType.SEC, 5))
    """
    args = [key, value]
    if conditional_set:
        if conditional_set == ConditionalChange.ONLY_IF_EXISTS:
            args.append("XX")
        if conditional_set == ConditionalChange.ONLY_IF_DOES_NOT_EXIST:
            args.append("NX")
    if return_old_value:
        args.append("GET")
    if expiry is not None:
        args.extend(expiry.get_cmd_args())
    return self.append_command(RequestType.Set, args)

setbit(key, offset, value)

Sets or clears the bit at offset in the string value stored at key. The offset is a zero-based index, with 0 being the first element of the list, 1 being the next element, and so on. The offset must be less than 2^32 and greater than or equal to 0. If a key is non-existent then the bit at offset is set to value and the preceding bits are set to 0.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the string.

required
offset int

The index of the bit to be set.

required
value int

The bit value to set at offset. The value must be 0 or 1.

required
Command response

int: The bit value that was previously stored at offset.

Source code in glide/async_commands/transaction.py
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
def setbit(
    self: TTransaction, key: TEncodable, offset: int, value: int
) -> TTransaction:
    """
    Sets or clears the bit at `offset` in the string value stored at `key`. The `offset` is a zero-based index,
    with `0` being the first element of the list, `1` being the next element, and so on. The `offset` must be less
    than `2^32` and greater than or equal to `0`. If a key is non-existent then the bit at `offset` is set to
    `value` and the preceding bits are set to `0`.

    See [valkey.io](https://valkey.io/commands/setbit) for more details.

    Args:
        key (TEncodable): The key of the string.
        offset (int): The index of the bit to be set.
        value (int): The bit value to set at `offset`. The value must be `0` or `1`.

    Command response:
        int: The bit value that was previously stored at `offset`.
    """
    return self.append_command(RequestType.SetBit, [key, str(offset), str(value)])

setrange(key, offset, value)

Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. If the offset is larger than the current length of the string at key, the string is padded with zero bytes to make offset fit. Creates the key if it doesn't exist.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the string to update.

required
offset int

The position in the string where value should be written.

required
value TEncodable

The value written with offset.

required
Command response

int: The length of the value stored at key after it was modified.

Source code in glide/async_commands/transaction.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
def setrange(
    self: TTransaction,
    key: TEncodable,
    offset: int,
    value: TEncodable,
) -> TTransaction:
    """
    Overwrites part of the string stored at `key`, starting at the specified
    `offset`, for the entire length of `value`.
    If the `offset` is larger than the current length of the string at `key`,
    the string is padded with zero bytes to make `offset` fit. Creates the `key`
    if it doesn't exist.

    See [valkey.io](https://valkey.io/commands/setrange) for more details.

    Args:
        key (TEncodable): The key of the string to update.
        offset (int): The position in the string where `value` should be written.
        value (TEncodable): The value written with `offset`.

    Command response:
        int: The length of the value stored at `key` after it was modified.
    """
    return self.append_command(RequestType.SetRange, [key, str(offset), value])

sinter(keys)

Gets the intersection of all the given sets.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sets.

required
Command response

Set[bytes]: A set of members which are present in all given sets.

If one or more sets do not exist, an empty set will be returned.

Source code in glide/async_commands/transaction.py
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
def sinter(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Gets the intersection of all the given sets.

    See [valkey.io](https://valkey.io/commands/sinter) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sets.

    Command response:
        Set[bytes]: A set of members which are present in all given sets.

        If one or more sets do not exist, an empty set will be returned.
    """
    return self.append_command(RequestType.SInter, keys)

sintercard(keys, limit=None)

Gets the cardinality of the intersection of all the given sets. Optionally, a limit can be specified to stop the computation early if the intersection cardinality reaches the specified limit.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

A list of keys representing the sets to intersect.

required
limit Optional[int]

An optional limit to the maximum number of intersecting elements to count. If specified, the computation stops as soon as the cardinality reaches this limit.

None
Command response

int: The number of elements in the resulting set of the intersection.

Source code in glide/async_commands/transaction.py
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
def sintercard(
    self: TTransaction, keys: List[TEncodable], limit: Optional[int] = None
) -> TTransaction:
    """
    Gets the cardinality of the intersection of all the given sets.
    Optionally, a `limit` can be specified to stop the computation early if the intersection
    cardinality reaches the specified limit.

    See [valkey.io](https://valkey.io/commands/sintercard) for more details.

    Args:
        keys (List[TEncodable]): A list of keys representing the sets to intersect.
        limit (Optional[int]): An optional limit to the maximum number of intersecting elements to count.
            If specified, the computation stops as soon as the cardinality reaches this limit.

    Command response:
        int: The number of elements in the resulting set of the intersection.
    """
    args: List[TEncodable] = [str(len(keys))]
    args.extend(keys)
    if limit is not None:
        args.extend(["LIMIT", str(limit)])
    return self.append_command(RequestType.SInterCard, args)

sinterstore(destination, keys)

Stores the members of the intersection of all given sets specified by keys into a new set at destination.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key of the destination set.

required
keys List[TEncodable]

The keys from which to retrieve the set members.

required
Command response

int: The number of elements in the resulting set.

Source code in glide/async_commands/transaction.py
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
def sinterstore(
    self: TTransaction,
    destination: TEncodable,
    keys: List[TEncodable],
) -> TTransaction:
    """
    Stores the members of the intersection of all given sets specified by `keys` into a new set at `destination`.

    See [valkey.io](https://valkey.io/commands/sinterstore) for more details.

    Args:
        destination (TEncodable): The key of the destination set.
        keys (List[TEncodable]): The keys from which to retrieve the set members.

    Command response:
        int: The number of elements in the resulting set.
    """
    return self.append_command(RequestType.SInterStore, [destination] + keys)

sismember(key, member)

Returns if member is a member of the set stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the set.

required
member TEncodable

The member to check for existence in the set.

required
Commands response

bool: True if the member exists in the set, False otherwise.

If key doesn't exist, it is treated as an empty set and the command returns False.

Source code in glide/async_commands/transaction.py
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
def sismember(
    self: TTransaction,
    key: TEncodable,
    member: TEncodable,
) -> TTransaction:
    """
    Returns if `member` is a member of the set stored at `key`.

    See [valkey.io](https://valkey.io/commands/sismember/) for more details.

    Args:
        key (TEncodable): The key of the set.
        member (TEncodable): The member to check for existence in the set.

    Commands response:
        bool: True if the member exists in the set, False otherwise.

        If `key` doesn't exist, it is treated as an empty set and the command returns False.
    """
    return self.append_command(RequestType.SIsMember, [key, member])

smembers(key)

Retrieve all the members of the set value stored at key.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key from which to retrieve the set members.

required
Commands response

Set[bytes]: A set of all members of the set.

If key does not exist an empty list will be returned.

Source code in glide/async_commands/transaction.py
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
def smembers(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Retrieve all the members of the set value stored at `key`.

    See [valkey.io](https://valkey.io/commands/smembers/) for details.

    Args:
        key (TEncodable): The key from which to retrieve the set members.

    Commands response:
        Set[bytes]: A set of all members of the set.

        If `key` does not exist an empty list will be returned.
    """
    return self.append_command(RequestType.SMembers, [key])

smismember(key, members)

Checks whether each member is contained in the members of the set stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the set to check.

required
members List[TEncodable]

A list of members to check for existence in the set.

required
Command response

List[bool]: A list of bool values, each indicating if the respective member exists in the set.

Source code in glide/async_commands/transaction.py
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
def smismember(
    self: TTransaction, key: TEncodable, members: List[TEncodable]
) -> TTransaction:
    """
    Checks whether each member is contained in the members of the set stored at `key`.

    See [valkey.io](https://valkey.io/commands/smismember) for more details.

    Args:
        key (TEncodable): The key of the set to check.
        members (List[TEncodable]): A list of members to check for existence in the set.

    Command response:
        List[bool]: A list of bool values, each indicating if the respective member exists in the set.
    """
    return self.append_command(RequestType.SMIsMember, [key] + members)

smove(source, destination, member)

Moves member from the set at source to the set at destination, removing it from the source set. Creates a new destination set if needed. The operation is atomic.

See valkey.io for more details.

Parameters:

Name Type Description Default
source TEncodable

The key of the set to remove the element from.

required
destination TEncodable

The key of the set to add the element to.

required
member TEncodable

The set element to move.

required
Command response

bool: True on success.

False if the source set does not exist or the element is not a member of the source set.

Source code in glide/async_commands/transaction.py
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
def smove(
    self: TTransaction,
    source: TEncodable,
    destination: TEncodable,
    member: TEncodable,
) -> TTransaction:
    """
    Moves `member` from the set at `source` to the set at `destination`, removing it from the source set. Creates a
    new destination set if needed. The operation is atomic.

    See [valkey.io](https://valkey.io/commands/smove) for more details.

    Args:
        source (TEncodable): The key of the set to remove the element from.
        destination (TEncodable): The key of the set to add the element to.
        member (TEncodable): The set element to move.

    Command response:
        bool: True on success.

        False if the `source` set does not exist or the element is not a member of the source set.
    """
    return self.append_command(RequestType.SMove, [source, destination, member])

sort(key, by_pattern=None, limit=None, get_patterns=None, order=None, alpha=None)

Sorts the elements in the list, set, or sorted set at key and returns the result. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To store the result into a new key, see sort_store.

See valkey.io for more details.

Note

When in cluster mode, key, and any patterns specified in by_pattern or get_patterns must map to the same hash slot. The use of by_pattern and get_patterns in cluster mode is supported only since Valkey version 8.0.

Parameters:

Name Type Description Default
key TEncodable

The key of the list, set, or sorted set to be sorted.

required
by_pattern Optional[TEncodable]

A pattern to sort by external keys instead of by the elements stored at the key themselves. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from the key replaces the asterisk to create the key name. For example, if key contains IDs of objects, by_pattern can be used to sort these IDs based on an attribute of the objects, like their weights or timestamps. E.g., if by_pattern is weight_*, the command will sort the elements by the values of the keys weight_<element>. If not provided, elements are sorted by their value. Supported in cluster mode since Valkey version 8.0.

None
limit Optional[Limit]

Limiting the range of the query by setting offset and result count. See Limit class for more information.

None
get_patterns Optional[List[TEncodable]]

A pattern used to retrieve external keys' values, instead of the elements at key. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from key replaces the asterisk to create the key name. This allows the sorted elements to be transformed based on the related keys values. For example, if key contains IDs of users, get_pattern can be used to retrieve specific attributes of these users, such as their names or email addresses. E.g., if get_pattern is name_*, the command will return the values of the keys name_<element> for each sorted element. Multiple get_pattern arguments can be provided to retrieve multiple attributes. The special value # can be used to include the actual element from key being sorted. If not provided, only the sorted elements themselves are returned. Supported in cluster mode since Valkey version 8.0.

None
order Optional[OrderBy]

Specifies the order to sort the elements. Can be OrderBy.ASC (ascending) or OrderBy.DESC (descending).

None
alpha Optional[bool]

When True, sorts elements lexicographically. When False (default), sorts elements numerically. Use this when the list, set, or sorted set contains string values that cannot be converted into double precision floating point numbers.

None
Command response

List[Optional[bytes]]: Returns a list of sorted elements.

Source code in glide/async_commands/transaction.py
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
def sort(
    self: TTransaction,
    key: TEncodable,
    by_pattern: Optional[TEncodable] = None,
    limit: Optional[Limit] = None,
    get_patterns: Optional[List[TEncodable]] = None,
    order: Optional[OrderBy] = None,
    alpha: Optional[bool] = None,
) -> TTransaction:
    """
    Sorts the elements in the list, set, or sorted set at `key` and returns the result.
    The `sort` command can be used to sort elements based on different criteria and apply transformations on sorted
    elements.
    To store the result into a new key, see `sort_store`.

    See [valkey.io](https://valkey.io/commands/sort) for more details.

    Note:
        When in cluster mode, `key`, and any patterns specified in `by_pattern` or `get_patterns`
        must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
        only since Valkey version 8.0.

    Args:
        key (TEncodable): The key of the list, set, or sorted set to be sorted.
        by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key
            themselves.
            The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
            from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects,
            `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or
            timestamps.
            E.g., if `by_pattern` is `weight_*`, the command will sort the elements by the values of the
            keys `weight_<element>`.
            If not provided, elements are sorted by their value.
            Supported in cluster mode since Valkey version 8.0.
        limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for
            more information.
        get_patterns (Optional[List[TEncodable]]): A pattern used to retrieve external keys' values, instead of the
            elements at `key`.
            The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
            from `key` replaces the asterisk to create the key name. This allows the sorted elements to be
            transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern`
            can be used to retrieve specific attributes of these users, such as their names or email addresses.
            E.g., if `get_pattern` is `name_*`, the command will return the values of the keys `name_<element>`
            for each sorted element. Multiple `get_pattern` arguments can be provided to retrieve multiple attributes.
            The special value `#` can be used to include the actual element from `key` being sorted.
            If not provided, only the sorted elements themselves are returned.
            Supported in cluster mode since Valkey version 8.0.
        order (Optional[OrderBy]): Specifies the order to sort the elements.
            Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending).
        alpha (Optional[bool]): When `True`, sorts elements lexicographically. When `False` (default),
            sorts elements numerically.
            Use this when the list, set, or sorted set contains string values that cannot be converted into
            double precision floating point numbers.

    Command response:
        List[Optional[bytes]]: Returns a list of sorted elements.
    """
    args = _build_sort_args(key, by_pattern, limit, get_patterns, order, alpha)
    return self.append_command(RequestType.Sort, args)

sort_ro(key, by_pattern=None, limit=None, get_patterns=None, order=None, alpha=None)

Sorts the elements in the list, set, or sorted set at key and returns the result. The sort_ro command can be used to sort elements based on different criteria and apply transformations on sorted elements. This command is routed depending on the client's ReadFrom strategy.

See valkey.io for more details.

Note

When in cluster mode, key, and any patterns specified in by_pattern or get_patterns must map to the same hash slot. The use of by_pattern and get_patterns in cluster mode is supported only since Valkey version 8.0.

Parameters:

Name Type Description Default
key TEncodable

The key of the list, set, or sorted set to be sorted.

required
by_pattern Optional[TEncodable]

A pattern to sort by external keys instead of by the elements stored at the key themselves. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from the key replaces the asterisk to create the key name. For example, if key contains IDs of objects, by_pattern can be used to sort these IDs based on an attribute of the objects, like their weights or timestamps. E.g., if by_pattern is weight_*, the command will sort the elements by the values of the keys weight_<element>. If not provided, elements are sorted by their value. Supported in cluster mode since Valkey version 8.0.

None
limit Optional[Limit]

Limiting the range of the query by setting offset and result count. See Limit class for more information.

None
get_patterns Optional[List[TEncodable]]

A pattern used to retrieve external keys' values, instead of the elements at key. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from key replaces the asterisk to create the key name. This allows the sorted elements to be transformed based on the related keys values. For example, if key contains IDs of users, get_pattern can be used to retrieve specific attributes of these users, such as their names or email addresses. E.g., if get_pattern is name_*, the command will return the values of the keys name_<element> for each sorted element. Multiple get_pattern arguments can be provided to retrieve multiple attributes. The special value # can be used to include the actual element from key being sorted. If not provided, only the sorted elements themselves are returned. Supported in cluster mode since Valkey version 8.0.

None
order Optional[OrderBy]

Specifies the order to sort the elements. Can be OrderBy.ASC (ascending) or OrderBy.DESC (descending).

None
alpha Optional[bool]

When True, sorts elements lexicographically. When False (default), sorts elements numerically. Use this when the list, set, or sorted set contains string values that cannot be converted into double precision floating point numbers.

None
Command response

List[Optional[bytes]]: Returns a list of sorted elements.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
def sort_ro(
    self: TTransaction,
    key: TEncodable,
    by_pattern: Optional[TEncodable] = None,
    limit: Optional[Limit] = None,
    get_patterns: Optional[List[TEncodable]] = None,
    order: Optional[OrderBy] = None,
    alpha: Optional[bool] = None,
) -> TTransaction:
    """
    Sorts the elements in the list, set, or sorted set at `key` and returns the result.
    The `sort_ro` command can be used to sort elements based on different criteria and apply transformations
    on sorted elements.
    This command is routed depending on the client's `ReadFrom` strategy.

    See [valkey.io](https://valkey.io/commands/sort) for more details.

    Note:
        When in cluster mode, `key`, and any patterns specified in `by_pattern` or `get_patterns`
        must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
        only since Valkey version 8.0.

    Args:
        key (TEncodable): The key of the list, set, or sorted set to be sorted.
        by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key
            themselves.
            The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
            from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects,
            `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or
            timestamps.
            E.g., if `by_pattern` is `weight_*`, the command will sort the elements by the values of the
            keys `weight_<element>`.
            If not provided, elements are sorted by their value.
            Supported in cluster mode since Valkey version 8.0.
        limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for
            more information.
        get_patterns (Optional[List[TEncodable]]): A pattern used to retrieve external keys' values, instead of the
            elements at `key`.
            The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
            from `key` replaces the asterisk to create the key name. This allows the sorted elements to be
            transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern`
            can be used to retrieve specific attributes of these users, such as their names or email addresses.
            E.g., if `get_pattern` is `name_*`, the command will return the values of the keys `name_<element>`
            for each sorted element. Multiple `get_pattern` arguments can be provided to retrieve multiple attributes.
            The special value `#` can be used to include the actual element from `key` being sorted.
            If not provided, only the sorted elements themselves are returned.
            Supported in cluster mode since Valkey version 8.0.
        order (Optional[OrderBy]): Specifies the order to sort the elements.
            Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending).
        alpha (Optional[bool]): When `True`, sorts elements lexicographically. When `False` (default), sorts elements
            numerically.
            Use this when the list, set, or sorted set contains string values that cannot be converted into double
            precision floating point numbers.

    Command response:
        List[Optional[bytes]]: Returns a list of sorted elements.

    Since: Valkey version 7.0.0.
    """
    args = _build_sort_args(key, by_pattern, limit, get_patterns, order, alpha)
    return self.append_command(RequestType.SortReadOnly, args)

sort_store(key, destination, by_pattern=None, limit=None, get_patterns=None, order=None, alpha=None)

Sorts the elements in the list, set, or sorted set at key and stores the result in store. The sort command can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key. To get the sort result without storing it into a key, see sort.

See valkey.io for more details.

Note

When in cluster mode, key, destination, and any patterns specified in by_pattern or get_patterns must map to the same hash slot. The use of by_pattern and get_patterns in cluster mode is supported only since Valkey version 8.0.

Parameters:

Name Type Description Default
key TEncodable

The key of the list, set, or sorted set to be sorted.

required
destination TEncodable

The key where the sorted result will be stored.

required
by_pattern Optional[TEncodable]

A pattern to sort by external keys instead of by the elements stored at the key themselves. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from the key replaces the asterisk to create the key name. For example, if key contains IDs of objects, by_pattern can be used to sort these IDs based on an attribute of the objects, like their weights or timestamps. E.g., if by_pattern is weight_*, the command will sort the elements by the values of the keys weight_<element>. If not provided, elements are sorted by their value. Supported in cluster mode since Valkey version 8.0.

None
limit Optional[Limit]

Limiting the range of the query by setting offset and result count. See Limit class for more information.

None
get_patterns Optional[List[TEncodable]]

A pattern used to retrieve external keys' values, instead of the elements at key. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from key replaces the asterisk to create the key name. This allows the sorted elements to be transformed based on the related keys values. For example, if key contains IDs of users, get_pattern can be used to retrieve specific attributes of these users, such as their names or email addresses. E.g., if get_pattern is name_*, the command will return the values of the keys name_<element> for each sorted element. Multiple get_pattern arguments can be provided to retrieve multiple attributes. The special value # can be used to include the actual element from key being sorted. If not provided, only the sorted elements themselves are returned. Supported in cluster mode since Valkey version 8.0.

None
order Optional[OrderBy]

Specifies the order to sort the elements. Can be OrderBy.ASC (ascending) or OrderBy.DESC (descending).

None
alpha Optional[bool]

When True, sorts elements lexicographically. When False (default), sorts elements numerically. Use this when the list, set, or sorted set contains string values that cannot be converted into double precision floating point numbers.

None
Command response

int: The number of elements in the sorted key stored at store.

Source code in glide/async_commands/transaction.py
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
def sort_store(
    self: TTransaction,
    key: TEncodable,
    destination: TEncodable,
    by_pattern: Optional[TEncodable] = None,
    limit: Optional[Limit] = None,
    get_patterns: Optional[List[TEncodable]] = None,
    order: Optional[OrderBy] = None,
    alpha: Optional[bool] = None,
) -> TTransaction:
    """
    Sorts the elements in the list, set, or sorted set at `key` and stores the result in `store`.
    The `sort` command can be used to sort elements based on different criteria, apply transformations on sorted elements,
    and store the result in a new key.
    To get the sort result without storing it into a key, see `sort`.

    See [valkey.io](https://valkey.io/commands/sort) for more details.

    Note:
        When in cluster mode, `key`, `destination`, and any patterns specified in `by_pattern` or `get_patterns`
        must map to the same hash slot. The use of `by_pattern` and `get_patterns` in cluster mode is supported
        only since Valkey version 8.0.

    Args:
        key (TEncodable): The key of the list, set, or sorted set to be sorted.
        destination (TEncodable): The key where the sorted result will be stored.
        by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key
            themselves.
            The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
            from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects,
            `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or
            timestamps.
            E.g., if `by_pattern` is `weight_*`, the command will sort the elements by the values of the
            keys `weight_<element>`.
            If not provided, elements are sorted by their value.
            Supported in cluster mode since Valkey version 8.0.
        limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for
            more information.
        get_patterns (Optional[List[TEncodable]]): A pattern used to retrieve external keys' values, instead of the
            elements at `key`.
            The pattern should contain an asterisk (*) as a placeholder for the element values, where the value
            from `key` replaces the asterisk to create the key name. This allows the sorted elements to be
            transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern`
            can be used to retrieve specific attributes of these users, such as their names or email addresses.
            E.g., if `get_pattern` is `name_*`, the command will return the values of the keys `name_<element>`
            for each sorted element. Multiple `get_pattern` arguments can be provided to retrieve multiple attributes.
            The special value `#` can be used to include the actual element from `key` being sorted.
            If not provided, only the sorted elements themselves are returned.
            Supported in cluster mode since Valkey version 8.0.
        order (Optional[OrderBy]): Specifies the order to sort the elements.
            Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending).
        alpha (Optional[bool]): When `True`, sorts elements lexicographically. When `False` (default), sorts elements
            numerically.
            Use this when the list, set, or sorted set contains string values that cannot be converted into double
            precision floating point numbers.

    Command response:
        int: The number of elements in the sorted key stored at `store`.
    """
    args = _build_sort_args(
        key, by_pattern, limit, get_patterns, order, alpha, store=destination
    )
    return self.append_command(RequestType.Sort, args)

spop(key)

Removes and returns one random member from the set stored at key.

See valkey.io for more details. To pop multiple members, see spop_count.

Parameters:

Name Type Description Default
key TEncodable

The key of the set.

required
Commands response

Optional[bytes]: The value of the popped member.

If key does not exist, None will be returned.

Source code in glide/async_commands/transaction.py
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
def spop(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Removes and returns one random member from the set stored at `key`.

    See [valkey.io](https://valkey-io.github.io/commands/spop/) for more details.
    To pop multiple members, see `spop_count`.

    Args:
        key (TEncodable): The key of the set.

    Commands response:
        Optional[bytes]: The value of the popped member.

        If `key` does not exist, None will be returned.
    """
    return self.append_command(RequestType.SPop, [key])

spop_count(key, count)

Removes and returns up to count random members from the set stored at key, depending on the set's length.

See valkey.io for more details.

To pop a single member, see spop.

Parameters:

Name Type Description Default
key TEncodable

The key of the set.

required
count int

The count of the elements to pop from the set.

required
Commands response

Set[bytes]: A set of popped elements will be returned depending on the set's length.

If key does not exist, an empty set will be returned.

Source code in glide/async_commands/transaction.py
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
def spop_count(self: TTransaction, key: TEncodable, count: int) -> TTransaction:
    """
    Removes and returns up to `count` random members from the set stored at `key`, depending on the set's length.

    See [valkey.io](https://valkey-io.github.io/commands/spop/) for more details.

    To pop a single member, see `spop`.

    Args:
        key (TEncodable): The key of the set.
        count (int): The count of the elements to pop from the set.

    Commands response:
        Set[bytes]: A set of popped elements will be returned depending on the set's length.

        If `key` does not exist, an empty set will be returned.
    """
    return self.append_command(RequestType.SPop, [key, str(count)])

srandmember(key)

Returns a random element from the set value stored at 'key'.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key from which to retrieve the set member.

required
Command Response

bytes: A random element from the set.

None if 'key' does not exist.

Source code in glide/async_commands/transaction.py
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
def srandmember(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns a random element from the set value stored at 'key'.

    See [valkey.io](https://valkey.io/commands/srandmember) for more details.

    Args:
        key (TEncodable): The key from which to retrieve the set member.

    Command Response:
        bytes: A random element from the set.

        `None` if 'key' does not exist.
    """
    return self.append_command(RequestType.SRandMember, [key])

srandmember_count(key, count)

Returns one or more random elements from the set value stored at 'key'.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
count int

The number of members to return.

  • If count is positive, returns unique members.
  • If count is negative, allows for duplicates members.
required
Command Response

List[TEncodable]: A list of members from the set.

If the set does not exist or is empty, the response will be an empty list.

Source code in glide/async_commands/transaction.py
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
def srandmember_count(
    self: TTransaction, key: TEncodable, count: int
) -> TTransaction:
    """
    Returns one or more random elements from the set value stored at 'key'.

    See [valkey.io](https://valkey.io/commands/srandmember) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        count (int): The number of members to return.

            - If `count` is positive, returns unique members.
            - If `count` is negative, allows for duplicates members.

    Command Response:
        List[TEncodable]: A list of members from the set.

        If the set does not exist or is empty, the response will be an empty list.
    """
    return self.append_command(RequestType.SRandMember, [key, str(count)])

srem(key, members)

Remove specified members from the set stored at key. Specified members that are not a member of this set are ignored.

See valkey.io for details.

Parameters:

Name Type Description Default
key TEncodable

The key from which members will be removed.

required
members List[TEncodable]

A list of members to remove from the set stored at key.

required
Commands response

int: The number of members that were removed from the set, excluding non-existing members.

If key does not exist, it is treated as an empty set and this command returns 0.

Source code in glide/async_commands/transaction.py
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
def srem(
    self: TTransaction, key: TEncodable, members: List[TEncodable]
) -> TTransaction:
    """
    Remove specified members from the set stored at `key`.
    Specified members that are not a member of this set are ignored.

    See [valkey.io](https://valkey.io/commands/srem/) for details.

    Args:
        key (TEncodable): The key from which members will be removed.
        members (List[TEncodable]): A list of members to remove from the set stored at key.

    Commands response:
        int: The number of members that were removed from the set, excluding non-existing members.

        If `key` does not exist, it is treated as an empty set and this command returns 0.
    """
    return self.append_command(RequestType.SRem, [key] + members)

sscan(key, cursor, match=None, count=None)

Iterates incrementally over a set.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the set.

required
cursor TEncodable

The cursor that points to the next iteration of results. A value of "0" indicates the start of the search.

required
match Optional[TEncodable]

The match filter is applied to the result of the command and will only include strings or bytes strings that match the pattern specified. If the set is large enough for scan commands to return only a subset of the set then there could be a case where the result is empty although there are items that match the pattern specified. This is due to the default COUNT being 10 which indicates that it will only fetch and match 10 items from the list.

None
count Optional[int]

COUNT is a just a hint for the command for how many elements to fetch from the set. COUNT could be ignored until the set is large enough for the SCAN commands to represent the results as compact single-allocation packed encoding.

None
Command Response

List[Union[bytes, List[bytes]]]: An Array of the cursor and the subset of the set held by key. The first element is always the cursor for the next iteration of results. 0 will be the cursor returned on the last iteration of the set. The second element is always an Array of the subset of the set held in key.

Source code in glide/async_commands/transaction.py
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
def sscan(
    self: TTransaction,
    key: TEncodable,
    cursor: TEncodable,
    match: Optional[TEncodable] = None,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Iterates incrementally over a set.

    See [valkey.io](https://valkey.io/commands/sscan) for more details.

    Args:
        key (TEncodable): The key of the set.
        cursor (TEncodable): The cursor that points to the next iteration of results. A value of "0" indicates the start of
            the search.
        match (Optional[TEncodable]): The match filter is applied to the result of the command and will only include
            strings or bytes strings that match the pattern specified. If the set is large enough for scan commands to
            return only a subset of the set then there could be a case where the result is empty although there are items
            that match the pattern specified. This is due to the default `COUNT` being `10` which indicates that it will
            only fetch and match `10` items from the list.
        count (Optional[int]): `COUNT` is a just a hint for the command for how many elements to fetch from the set.
            `COUNT` could be ignored until the set is large enough for the `SCAN` commands to represent the results
            as compact single-allocation packed encoding.

    Command Response:
        List[Union[bytes, List[bytes]]]: An `Array` of the `cursor` and the subset of the set held by `key`.
        The first element is always the `cursor` for the next iteration of results. `0` will be the `cursor`
        returned on the last iteration of the set. The second element is always an `Array` of the subset of the
        set held in `key`.
    """
    args = [key, cursor]
    if match is not None:
        args += ["MATCH", match]
    if count is not None:
        args += ["COUNT", str(count)]

    return self.append_command(RequestType.SScan, args)

strlen(key)

Get the length of the string value stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to return its length.

required
Commands response

int: The length of the string value stored at key.

If key does not exist, it is treated as an empty string and 0 is returned.

Source code in glide/async_commands/transaction.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
def strlen(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Get the length of the string value stored at `key`.

    See [valkey.io](https://valkey.io/commands/strlen/) for more details.

    Args:
        key (TEncodable): The key to return its length.

    Commands response:
        int: The length of the string value stored at `key`.

        If `key` does not exist, it is treated as an empty string and 0 is returned.
    """
    return self.append_command(RequestType.Strlen, [key])

sunion(keys)

Gets the union of all the given sets.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sets.

required
Commands response

Set[bytes]: A set of members which are present in at least one of the given sets.

If none of the sets exist, an empty set will be returned.

Source code in glide/async_commands/transaction.py
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
def sunion(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Gets the union of all the given sets.

    See [valkey.io](https://valkey.io/commands/sunion) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sets.

    Commands response:
        Set[bytes]: A set of members which are present in at least one of the given sets.

        If none of the sets exist, an empty set will be returned.
    """
    return self.append_command(RequestType.SUnion, keys)

sunionstore(destination, keys)

Stores the members of the union of all given sets specified by keys into a new set at destination.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key of the destination set.

required
keys List[TEncodable]

The keys from which to retrieve the set members.

required
Command response

int: The number of elements in the resulting set.

Source code in glide/async_commands/transaction.py
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
def sunionstore(
    self: TTransaction,
    destination: TEncodable,
    keys: List[TEncodable],
) -> TTransaction:
    """
    Stores the members of the union of all given sets specified by `keys` into a new set at `destination`.

    See [valkey.io](https://valkey.io/commands/sunionstore) for more details.

    Args:
        destination (TEncodable): The key of the destination set.
        keys (List[TEncodable]): The keys from which to retrieve the set members.

    Command response:
        int: The number of elements in the resulting set.
    """
    return self.append_command(RequestType.SUnionStore, [destination] + keys)

touch(keys)

Updates the last access time of specified keys.

See valkey.io for details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys to update last access time.

required
Commands response

int: The number of keys that were updated, a key is ignored if it doesn't exist.

Source code in glide/async_commands/transaction.py
446
447
448
449
450
451
452
453
454
455
456
457
458
def touch(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Updates the last access time of specified keys.

    See [valkey.io](https://valkey.io/commands/touch/) for details.

    Args:
        keys (List[TEncodable]): The keys to update last access time.

    Commands response:
        int: The number of keys that were updated, a key is ignored if it doesn't exist.
    """
    return self.append_command(RequestType.Touch, keys)

ttl(key)

Returns the remaining time to live of key that has a timeout.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to return its timeout.

required
Commands response

int: TTL in seconds.

-2 if key does not exist.

-1 if key exists but has no associated expire.

Source code in glide/async_commands/transaction.py
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
def ttl(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the remaining time to live of `key` that has a timeout.

    See [valkey.io](https://valkey.io/commands/ttl/) for more details.

    Args:
        key (TEncodable): The key to return its timeout.

    Commands response:
        int: TTL in seconds.

        -2 if `key` does not exist.

        -1 if `key` exists but has no associated expire.
    """
    return self.append_command(RequestType.TTL, [key])

type(key)

Returns the string representation of the type of the value stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key to check its data type.

required
Commands response

bytes: If the key exists, the type of the stored value is returned.

Otherwise, a "none" string is returned.

Source code in glide/async_commands/transaction.py
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
def type(self: TTransaction, key: TEncodable) -> TTransaction:
    """
     Returns the string representation of the type of the value stored at `key`.

     See [valkey.io](https://valkey.io/commands/type/) for more details.

    Args:
        key (TEncodable): The key to check its data type.

    Commands response:
        bytes: If the key exists, the type of the stored value is returned.

        Otherwise, a "none" string is returned.
    """
    return self.append_command(RequestType.Type, [key])

Unlink (delete) multiple keys from the database. A key is ignored if it does not exist. This command, similar to DEL, removes specified keys and ignores non-existent ones. However, this command does not block the server, while DEL <[valkey.io](https://valkey.io/commands/del>_) does.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The list of keys to unlink.

required
Commands response

int: The number of keys that were unlinked.

Source code in glide/async_commands/transaction.py
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
def unlink(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Unlink (delete) multiple keys from the database.
    A key is ignored if it does not exist.
    This command, similar to DEL, removes specified keys and ignores non-existent ones.
    However, this command does not block the server, while `DEL <[valkey.io](https://valkey.io/commands/del>`_) does.

    See [valkey.io](https://valkey.io/commands/unlink/) for more details.

    Args:
        keys (List[TEncodable]): The list of keys to unlink.

    Commands response:
        int: The number of keys that were unlinked.
    """
    return self.append_command(RequestType.Unlink, keys)

wait(numreplicas, timeout)

Returns the number of replicas that acknowledged the write commands sent by the current client before this command, both in the case where the specified number of replicas are reached, or when the timeout is reached.

See valkey.io for more details.

Parameters:

Name Type Description Default
numreplicas int

The number of replicas to reach.

required
timeout int

The timeout value specified in milliseconds.

required
Command Response

bytes: The number of replicas reached by all the writes performed in the context of the current connection.

Source code in glide/async_commands/transaction.py
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
def wait(
    self: TTransaction,
    numreplicas: int,
    timeout: int,
) -> TTransaction:
    """
    Returns the number of replicas that acknowledged the write commands sent by the current client
    before this command, both in the case where the specified number of replicas are reached, or
    when the timeout is reached.

    See [valkey.io](https://valkey.io/commands/wait) for more details.

    Args:
        numreplicas (int): The number of replicas to reach.
        timeout (int): The timeout value specified in milliseconds.

    Command Response:
        bytes: The number of replicas reached by all the writes performed in the context of the current connection.
    """
    args: List[TEncodable] = [str(numreplicas), str(timeout)]
    return self.append_command(RequestType.Wait, args)

xack(key, group_name, ids)

Removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group. This command should be called on pending messages so that such messages do not get processed again by the consumer group.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
ids List[TEncodable]

The stream entry IDs to acknowledge and consume for the given consumer group.

required
Command response

int: The number of messages that were successfully acknowledged.

Source code in glide/async_commands/transaction.py
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
def xack(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    ids: List[TEncodable],
) -> TTransaction:
    """
    Removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group.
    This command should be called on pending messages so that such messages do not get processed again by the
    consumer group.

    See [valkey.io](https://valkey.io/commands/xack) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.
        ids (List[TEncodable]): The stream entry IDs to acknowledge and consume for the given consumer group.

    Command response:
        int: The number of messages that were successfully acknowledged.
    """
    return self.append_command(RequestType.XAck, [key, group_name] + ids)

xadd(key, values, options=StreamAddOptions())

Adds an entry to the specified stream stored at key. If the key doesn't exist, the stream is created.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
values List[Tuple[TEncodable, TEncodable]]

List[Tuple[TEncodable, TEncodable]]: Field-value pairs to be added to the entry.

required
options Optional[StreamAddOptions]

Additional options for adding entries to the stream. Default to None. See StreamAddOptions.

StreamAddOptions()
Commands response

bytes: The id of the added entry.

None if options.make_stream is set to False and no stream with the matching key exists.

Source code in glide/async_commands/transaction.py
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
def xadd(
    self: TTransaction,
    key: TEncodable,
    values: List[Tuple[TEncodable, TEncodable]],
    options: StreamAddOptions = StreamAddOptions(),
) -> TTransaction:
    """
    Adds an entry to the specified stream stored at `key`. If the `key` doesn't exist, the stream is created.

    See [valkey.io](https://valkey.io/commands/xadd) for more details.

    Args:
        key (TEncodable): The key of the stream.
        values: List[Tuple[TEncodable, TEncodable]]: Field-value pairs to be added to the entry.
        options (Optional[StreamAddOptions]): Additional options for adding entries to the stream.
            Default to None. See `StreamAddOptions`.

    Commands response:
        bytes: The id of the added entry.

        None if `options.make_stream` is set to False and no stream with the matching `key` exists.
    """
    args = [key]
    if options:
        args.extend(options.to_args())
    args.extend([field for pair in values for field in pair])

    return self.append_command(RequestType.XAdd, args)

xautoclaim(key, group_name, consumer_name, min_idle_time_ms, start, count=None)

Transfers ownership of pending stream entries that match the specified criteria.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
consumer_name TEncodable

The consumer name.

required
min_idle_time_ms int

Filters the claimed entries to those that have been idle for more than the specified value.

required
start TEncodable

Filters the claimed entries to those that have an ID equal or greater than the specified value.

required
count Optional[int]

Limits the number of claimed entries to the specified value.

None
Command response

List[Union[str, Mapping[bytes, List[List[bytes]]], List[bytes]]]: A list containing the following elements:

- A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent
  to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was
  scanned.
- A mapping of the claimed entries, with the keys being the claimed entry IDs and the values being a
  2D list of the field-value pairs in the format `[[field1, value1], [field2, value2], ...]`.
- If you are using Valkey 7.0.0 or above, the response list will also include a list containing the
  message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are
  deleted from the Pending Entries List.

Since: Valkey version 6.2.0.

Source code in glide/async_commands/transaction.py
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
def xautoclaim(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    consumer_name: TEncodable,
    min_idle_time_ms: int,
    start: TEncodable,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Transfers ownership of pending stream entries that match the specified criteria.

    See [valkey.io](https://valkey.io/commands/xautoclaim) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.
        consumer_name (TEncodable): The consumer name.
        min_idle_time_ms (int): Filters the claimed entries to those that have been idle for more than the specified
            value.
        start (TEncodable): Filters the claimed entries to those that have an ID equal or greater than the specified value.
        count (Optional[int]): Limits the number of claimed entries to the specified value.

    Command response:
        List[Union[str, Mapping[bytes, List[List[bytes]]], List[bytes]]]: A list containing the following elements:

            - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent
              to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was
              scanned.
            - A mapping of the claimed entries, with the keys being the claimed entry IDs and the values being a
              2D list of the field-value pairs in the format `[[field1, value1], [field2, value2], ...]`.
            - If you are using Valkey 7.0.0 or above, the response list will also include a list containing the
              message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are
              deleted from the Pending Entries List.

    Since: Valkey version 6.2.0.
    """
    args = [key, group_name, consumer_name, str(min_idle_time_ms), start]
    if count is not None:
        args.extend(["COUNT", str(count)])

    return self.append_command(RequestType.XAutoClaim, args)

xautoclaim_just_id(key, group_name, consumer_name, min_idle_time_ms, start, count=None)

Transfers ownership of pending stream entries that match the specified criteria. This command uses the JUSTID argument to further specify that the return value should contain a list of claimed IDs without their field-value info.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
consumer_name TEncodable

The consumer name.

required
min_idle_time_ms int

Filters the claimed entries to those that have been idle for more than the specified value.

required
start TEncodable

Filters the claimed entries to those that have an ID equal or greater than the specified value.

required
count Optional[int]

Limits the number of claimed entries to the specified value.

None
Command response

List[Union[bytes, List[bytes]]]: A list containing the following elements:

- A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent
  to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was
  scanned.
- A list of the IDs for the claimed entries.
- If you are using Valkey 7.0.0 or above, the response list will also include a list containing the
  message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are
  deleted from the Pending Entries List.

Since: Valkey version 6.2.0.

Source code in glide/async_commands/transaction.py
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
def xautoclaim_just_id(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    consumer_name: TEncodable,
    min_idle_time_ms: int,
    start: TEncodable,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Transfers ownership of pending stream entries that match the specified criteria. This command uses the JUSTID
    argument to further specify that the return value should contain a list of claimed IDs without their
    field-value info.

    See [valkey.io](https://valkey.io/commands/xautoclaim) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.
        consumer_name (TEncodable): The consumer name.
        min_idle_time_ms (int): Filters the claimed entries to those that have been idle for more than the specified
            value.
        start (TEncodable): Filters the claimed entries to those that have an ID equal or greater than the specified value.
        count (Optional[int]): Limits the number of claimed entries to the specified value.

    Command response:
        List[Union[bytes, List[bytes]]]: A list containing the following elements:

            - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent
              to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was
              scanned.
            - A list of the IDs for the claimed entries.
            - If you are using Valkey 7.0.0 or above, the response list will also include a list containing the
              message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are
              deleted from the Pending Entries List.

    Since: Valkey version 6.2.0.
    """
    args = [key, group_name, consumer_name, str(min_idle_time_ms), start]
    if count is not None:
        args.extend(["COUNT", str(count)])

    args.append("JUSTID")

    return self.append_command(RequestType.XAutoClaim, args)

xclaim(key, group, consumer, min_idle_time_ms, ids, options=None)

Changes the ownership of a pending message.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group TEncodable

The consumer group name.

required
consumer TEncodable

The group consumer.

required
min_idle_time_ms int

The minimum idle time for the message to be claimed.

required
ids List[TEncodable]

A array of entry ids.

required
options Optional[StreamClaimOptions]

Stream claim options.

None

Returns:

Type Description
TTransaction

A Mapping of message entries with the format::

{"entryId": [["entry", "data"], ...], ...}

TTransaction

that are claimed by the consumer.

Source code in glide/async_commands/transaction.py
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
def xclaim(
    self: TTransaction,
    key: TEncodable,
    group: TEncodable,
    consumer: TEncodable,
    min_idle_time_ms: int,
    ids: List[TEncodable],
    options: Optional[StreamClaimOptions] = None,
) -> TTransaction:
    """
    Changes the ownership of a pending message.

    See [valkey.io](https://valkey.io/commands/xclaim) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group (TEncodable): The consumer group name.
        consumer (TEncodable): The group consumer.
        min_idle_time_ms (int): The minimum idle time for the message to be claimed.
        ids (List[TEncodable]): A array of entry ids.
        options (Optional[StreamClaimOptions]): Stream claim options.

    Returns:
        A Mapping of message entries with the format::

            {"entryId": [["entry", "data"], ...], ...}

        that are claimed by the consumer.
    """

    args = [key, group, consumer, str(min_idle_time_ms), *ids]

    if options:
        args.extend(options.to_args())

    return self.append_command(RequestType.XClaim, args)

xclaim_just_id(key, group, consumer, min_idle_time_ms, ids, options=None)

Changes the ownership of a pending message. This function returns a List with only the message/entry IDs, and is equivalent to using JUSTID in the Valkey API.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group TEncodable

The consumer group name.

required
consumer TEncodable

The group consumer.

required
min_idle_time_ms int

The minimum idle time for the message to be claimed.

required
ids List[TEncodable]

A array of entry ids.

required
options Optional[StreamClaimOptions]

Stream claim options.

None

Returns:

Type Description
TTransaction

A List of message ids claimed by the consumer.

Source code in glide/async_commands/transaction.py
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
def xclaim_just_id(
    self: TTransaction,
    key: TEncodable,
    group: TEncodable,
    consumer: TEncodable,
    min_idle_time_ms: int,
    ids: List[TEncodable],
    options: Optional[StreamClaimOptions] = None,
) -> TTransaction:
    """
    Changes the ownership of a pending message. This function returns a List with
    only the message/entry IDs, and is equivalent to using JUSTID in the Valkey API.

    See [valkey.io](https://valkey.io/commands/xclaim) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group (TEncodable): The consumer group name.
        consumer (TEncodable): The group consumer.
        min_idle_time_ms (int): The minimum idle time for the message to be claimed.
        ids (List[TEncodable]): A array of entry ids.
        options (Optional[StreamClaimOptions]): Stream claim options.

    Returns:
        A List of message ids claimed by the consumer.
    """

    args = [
        key,
        group,
        consumer,
        str(min_idle_time_ms),
        *ids,
        StreamClaimOptions.JUST_ID_VALKEY_API,
    ]

    if options:
        args.extend(options.to_args())

    return self.append_command(RequestType.XClaim, args)

xdel(key, ids)

Removes the specified entries by id from a stream, and returns the number of entries deleted.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
ids List[TEncodable]

An array of entry ids.

required
Command response

int: The number of entries removed from the stream. This number may be less than the number of entries in ids, if the specified ids don't exist in the stream.

Source code in glide/async_commands/transaction.py
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
def xdel(
    self: TTransaction, key: TEncodable, ids: List[TEncodable]
) -> TTransaction:
    """
    Removes the specified entries by id from a stream, and returns the number of entries deleted.

    See [valkey.io](https://valkey.io/commands/xdel) for more details.

    Args:
        key (TEncodable): The key of the stream.
        ids (List[TEncodable]): An array of entry ids.

    Command response:
        int: The number of entries removed from the stream. This number may be less than the number of entries in
        `ids`, if the specified `ids` don't exist in the stream.
    """
    return self.append_command(RequestType.XDel, [key] + ids)

xgroup_create(key, group_name, group_id, options=None)

Creates a new consumer group uniquely identified by group_name for the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The newly created consumer group name.

required
group_id TEncodable

The stream entry ID that specifies the last delivered entry in the stream from the new group’s perspective. The special ID "$" can be used to specify the last entry in the stream.

required
options Optional[StreamGroupOptions]

Options for creating the stream group.

None
Command response

TOK: A simple "OK" response.

Source code in glide/async_commands/transaction.py
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
def xgroup_create(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    group_id: TEncodable,
    options: Optional[StreamGroupOptions] = None,
) -> TTransaction:
    """
    Creates a new consumer group uniquely identified by `group_name` for the stream stored at `key`.

    See [valkey.io](https://valkey.io/commands/xgroup-create) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The newly created consumer group name.
        group_id (TEncodable): The stream entry ID that specifies the last delivered entry in the stream from the new
            group’s perspective. The special ID "$" can be used to specify the last entry in the stream.
        options (Optional[StreamGroupOptions]): Options for creating the stream group.

    Command response:
        TOK: A simple "OK" response.
    """
    args = [key, group_name, group_id]
    if options is not None:
        args.extend(options.to_args())

    return self.append_command(RequestType.XGroupCreate, args)

xgroup_create_consumer(key, group_name, consumer_name)

Creates a consumer named consumer_name in the consumer group group_name for the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
consumer_name TEncodable

The newly created consumer.

required
Command response

bool: True if the consumer is created.

Otherwise, returns False.

Source code in glide/async_commands/transaction.py
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
def xgroup_create_consumer(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    consumer_name: TEncodable,
) -> TTransaction:
    """
    Creates a consumer named `consumer_name` in the consumer group `group_name` for the stream stored at `key`.

    See [valkey.io](https://valkey.io/commands/xgroup-createconsumer) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.
        consumer_name (TEncodable): The newly created consumer.

    Command response:
        bool: True if the consumer is created.

        Otherwise, returns False.
    """
    return self.append_command(
        RequestType.XGroupCreateConsumer, [key, group_name, consumer_name]
    )

xgroup_del_consumer(key, group_name, consumer_name)

Deletes a consumer named consumer_name in the consumer group group_name for the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
consumer_name TEncodable

The consumer to delete.

required
Command response

int: The number of pending messages the consumer had before it was deleted.

Source code in glide/async_commands/transaction.py
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
def xgroup_del_consumer(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    consumer_name: TEncodable,
) -> TTransaction:
    """
    Deletes a consumer named `consumer_name` in the consumer group `group_name` for the stream stored at `key`.

    See [valkey.io](https://valkey.io/commands/xgroup-delconsumer) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.
        consumer_name (TEncodable): The consumer to delete.

    Command response:
        int: The number of pending messages the `consumer` had before it was deleted.
    """
    return self.append_command(
        RequestType.XGroupDelConsumer, [key, group_name, consumer_name]
    )

xgroup_destroy(key, group_name)

Destroys the consumer group group_name for the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name to delete.

required
Command response

bool: True if the consumer group was destroyed.

Otherwise, returns False.

Source code in glide/async_commands/transaction.py
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
def xgroup_destroy(
    self: TTransaction, key: TEncodable, group_name: TEncodable
) -> TTransaction:
    """
    Destroys the consumer group `group_name` for the stream stored at `key`.

    See [valkey.io](https://valkey.io/commands/xgroup-destroy) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name to delete.

    Command response:
        bool: True if the consumer group was destroyed.

        Otherwise, returns False.
    """
    return self.append_command(RequestType.XGroupDestroy, [key, group_name])

xgroup_set_id(key, group_name, stream_id, entries_read_id=None)

Set the last delivered ID for a consumer group.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
stream_id TEncodable

The stream entry ID that should be set as the last delivered ID for the consumer group.

required
entries_read_id Optional[str]

An arbitrary ID (that isn't the first ID, last ID, or the zero ID ("0-0")) used to find out how many entries are between the arbitrary ID (excluding it) and the stream's last entry. This argument can only be specified if you are using Valkey version 7.0.0 or above.

None
Command response

TOK: A simple "OK" response.

Source code in glide/async_commands/transaction.py
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
def xgroup_set_id(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    stream_id: TEncodable,
    entries_read_id: Optional[str] = None,
) -> TTransaction:
    """
    Set the last delivered ID for a consumer group.

    See [valkey.io](https://valkey.io/commands/xgroup-setid) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.
        stream_id (TEncodable): The stream entry ID that should be set as the last delivered ID for the consumer group.
        entries_read_id (Optional[str]): An arbitrary ID (that isn't the first ID, last ID, or the zero ID ("0-0"))
            used to find out how many entries are between the arbitrary ID (excluding it) and the stream's last
            entry. This argument can only be specified if you are using Valkey version 7.0.0 or above.

    Command response:
        TOK: A simple "OK" response.
    """
    args = [key, group_name, stream_id]
    if entries_read_id is not None:
        args.extend(["ENTRIESREAD", entries_read_id])

    return self.append_command(RequestType.XGroupSetId, args)

xinfo_consumers(key, group_name)

Returns the list of all consumers and their attributes for the given consumer group of the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
Command response

List[Mapping[bytes, Union[bytes, int]]]: A list of mappings, where each mapping contains the attributes of a consumer for the given consumer group of the stream at key.

Source code in glide/async_commands/transaction.py
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
def xinfo_consumers(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
) -> TTransaction:
    """
    Returns the list of all consumers and their attributes for the given consumer group of the stream stored at
    `key`.

    See [valkey.io](https://valkey.io/commands/xinfo-consumers) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.

    Command response:
        List[Mapping[bytes, Union[bytes, int]]]: A list of mappings, where each mapping contains the attributes of a
        consumer for the given consumer group of the stream at `key`.
    """
    return self.append_command(RequestType.XInfoConsumers, [key, group_name])

xinfo_groups(key)

Returns the list of all consumer groups and their attributes for the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
Command response

List[Mapping[bytes, Union[bytes, int, None]]]: A list of mappings, where each mapping represents the attributes of a consumer group for the stream at key.

Source code in glide/async_commands/transaction.py
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
def xinfo_groups(
    self: TTransaction,
    key: TEncodable,
) -> TTransaction:
    """
    Returns the list of all consumer groups and their attributes for the stream stored at `key`.

    See [valkey.io](https://valkey.io/commands/xinfo-groups) for more details.

    Args:
        key (TEncodable): The key of the stream.

    Command response:
        List[Mapping[bytes, Union[bytes, int, None]]]: A list of mappings, where each mapping represents the
        attributes of a consumer group for the stream at `key`.
    """
    return self.append_command(RequestType.XInfoGroups, [key])

xinfo_stream(key)

Returns information about the stream stored at key. To get more detailed information, use xinfo_stream_full.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
Command response

TXInfoStreamResponse: A mapping of stream information for the given key.

Source code in glide/async_commands/transaction.py
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
def xinfo_stream(
    self: TTransaction,
    key: TEncodable,
) -> TTransaction:
    """
    Returns information about the stream stored at `key`. To get more detailed information, use `xinfo_stream_full`.

    See [valkey.io](https://valkey.io/commands/xinfo-stream) for more details.

    Args:
        key (TEncodable): The key of the stream.

    Command response:
        TXInfoStreamResponse: A mapping of stream information for the given `key`.
    """
    return self.append_command(RequestType.XInfoStream, [key])

xinfo_stream_full(key, count=None)

Returns verbose information about the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
count Optional[int]

The number of stream and PEL entries that are returned. A value of 0 means that all entries will be returned. If not provided, defaults to 10.

None
Command response

TXInfoStreamFullResponse: A mapping of detailed stream information for the given key.

Source code in glide/async_commands/transaction.py
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
def xinfo_stream_full(
    self: TTransaction,
    key: TEncodable,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Returns verbose information about the stream stored at `key`.

    See [valkey.io](https://valkey.io/commands/xinfo-stream) for more details.

    Args:
        key (TEncodable): The key of the stream.
        count (Optional[int]): The number of stream and PEL entries that are returned. A value of `0` means that all
            entries will be returned. If not provided, defaults to `10`.

    Command response:
        TXInfoStreamFullResponse: A mapping of detailed stream information for the given `key`.
    """
    args = [key, "FULL"]
    if count is not None:
        args.extend(["COUNT", str(count)])

    return self.append_command(RequestType.XInfoStream, args)

xlen(key)

Returns the number of entries in the stream stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
Command response

int: The number of entries in the stream.

If key does not exist, returns 0.

Source code in glide/async_commands/transaction.py
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
def xlen(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the number of entries in the stream stored at `key`.

    See [valkey.io](https://valkey.io/commands/xlen) for more details.

    Args:
        key (TEncodable): The key of the stream.

    Command response:
        int: The number of entries in the stream.

        If `key` does not exist, returns 0.
    """
    return self.append_command(RequestType.XLen, [key])

xpending(key, group_name)

Returns stream message summary information for pending messages for the given consumer group.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
Command response

List[Union[int, bytes, List[List[bytes]], None]]: A list that includes the summary of pending messages, with the format [num_group_messages, start_id, end_id, [[consumer_name, num_consumer_messages]]], where:

- `num_group_messages`: The total number of pending messages for this consumer group.
- `start_id`: The smallest ID among the pending messages.
- `end_id`: The greatest ID among the pending messages.
- `[[consumer_name, num_consumer_messages]]`: A 2D list of every consumer in the consumer group with at
  least one pending message, and the number of pending messages it has.

If there are no pending messages for the given consumer group, [0, None, None, None] will be returned.

Source code in glide/async_commands/transaction.py
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
def xpending(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
) -> TTransaction:
    """
    Returns stream message summary information for pending messages for the given consumer group.

    See [valkey.io](https://valkey.io/commands/xpending) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.

    Command response:
        List[Union[int, bytes, List[List[bytes]], None]]: A list that includes the summary of pending messages, with the
        format `[num_group_messages, start_id, end_id, [[consumer_name, num_consumer_messages]]]`, where:

            - `num_group_messages`: The total number of pending messages for this consumer group.
            - `start_id`: The smallest ID among the pending messages.
            - `end_id`: The greatest ID among the pending messages.
            - `[[consumer_name, num_consumer_messages]]`: A 2D list of every consumer in the consumer group with at
              least one pending message, and the number of pending messages it has.

        If there are no pending messages for the given consumer group, `[0, None, None, None]` will be returned.
    """
    return self.append_command(RequestType.XPending, [key, group_name])

xpending_range(key, group_name, start, end, count, options=None)

Returns an extended form of stream message information for pending messages matching a given range of IDs.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
group_name TEncodable

The consumer group name.

required
start StreamRangeBound

The starting stream ID bound for the range.

  • Use IdBound to specify a stream ID.
  • Use ExclusiveIdBound to specify an exclusive bounded stream ID.
  • Use MinId to start with the minimum available ID.
required
end StreamRangeBound

The ending stream ID bound for the range.

  • Use IdBound to specify a stream ID.
  • Use ExclusiveIdBound to specify an exclusive bounded stream ID.
  • Use MaxId to end with the maximum available ID.
required
count int

Limits the number of messages returned.

required
options Optional[StreamPendingOptions]

The stream pending options.

None
Command response

List[List[Union[bytes, int]]]: A list of lists, where each inner list is a length 4 list containing extended message information with the format [[id, consumer_name, time_elapsed, num_delivered]], where:

- `id`: The ID of the message.
- `consumer_name`: The name of the consumer that fetched the message and has still to acknowledge it. We
  call it the current owner of the message.
- `time_elapsed`: The number of milliseconds that elapsed since the last time this message was delivered
  to this consumer.
- `num_delivered`: The number of times this message was delivered.
Source code in glide/async_commands/transaction.py
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
def xpending_range(
    self: TTransaction,
    key: TEncodable,
    group_name: TEncodable,
    start: StreamRangeBound,
    end: StreamRangeBound,
    count: int,
    options: Optional[StreamPendingOptions] = None,
) -> TTransaction:
    """
    Returns an extended form of stream message information for pending messages matching a given range of IDs.

    See [valkey.io](https://valkey.io/commands/xpending) for more details.

    Args:
        key (TEncodable): The key of the stream.
        group_name (TEncodable): The consumer group name.
        start (StreamRangeBound): The starting stream ID bound for the range.

            - Use `IdBound` to specify a stream ID.
            - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
            - Use `MinId` to start with the minimum available ID.

        end (StreamRangeBound): The ending stream ID bound for the range.

            - Use `IdBound` to specify a stream ID.
            - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
            - Use `MaxId` to end with the maximum available ID.

        count (int): Limits the number of messages returned.
        options (Optional[StreamPendingOptions]): The stream pending options.

    Command response:
        List[List[Union[bytes, int]]]: A list of lists, where each inner list is a length 4 list containing extended
        message information with the format `[[id, consumer_name, time_elapsed, num_delivered]]`, where:

            - `id`: The ID of the message.
            - `consumer_name`: The name of the consumer that fetched the message and has still to acknowledge it. We
              call it the current owner of the message.
            - `time_elapsed`: The number of milliseconds that elapsed since the last time this message was delivered
              to this consumer.
            - `num_delivered`: The number of times this message was delivered.
    """
    args = _create_xpending_range_args(key, group_name, start, end, count, options)
    return self.append_command(RequestType.XPending, args)

xrange(key, start, end, count=None)

Returns stream entries matching a given range of IDs.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
start StreamRangeBound

The starting stream ID bound for the range.

  • Use IdBound to specify a stream ID.
  • Use ExclusiveIdBound to specify an exclusive bounded stream ID.
  • Use MinId to start with the minimum available ID.
required
end StreamRangeBound

The ending stream ID bound for the range.

  • Use IdBound to specify a stream ID.
  • Use ExclusiveIdBound to specify an exclusive bounded stream ID.
  • Use MaxId to end with the maximum available ID.
required
count Optional[int]

An optional argument specifying the maximum count of stream entries to return. If count is not provided, all stream entries in the range will be returned.

None
Command response

Optional[Mapping[bytes, List[List[bytes]]]]: A mapping of stream IDs to stream entry data, where entry data is a list of pairings with format [[field, entry], [field, entry], ...].

Returns None if the range arguments are not applicable.

Source code in glide/async_commands/transaction.py
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
def xrange(
    self: TTransaction,
    key: TEncodable,
    start: StreamRangeBound,
    end: StreamRangeBound,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Returns stream entries matching a given range of IDs.

    See [valkey.io](https://valkey.io/commands/xrange) for more details.

    Args:
        key (TEncodable): The key of the stream.
        start (StreamRangeBound): The starting stream ID bound for the range.

            - Use `IdBound` to specify a stream ID.
            - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
            - Use `MinId` to start with the minimum available ID.

        end (StreamRangeBound): The ending stream ID bound for the range.

            - Use `IdBound` to specify a stream ID.
            - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
            - Use `MaxId` to end with the maximum available ID.

        count (Optional[int]): An optional argument specifying the maximum count of stream entries to return.
            If `count` is not provided, all stream entries in the range will be returned.

    Command response:
        Optional[Mapping[bytes, List[List[bytes]]]]: A mapping of stream IDs to stream entry data, where entry data is a
        list of pairings with format `[[field, entry], [field, entry], ...]`.

        Returns None if the range arguments are not applicable.
    """
    args = [key, start.to_arg(), end.to_arg()]
    if count is not None:
        args.extend(["COUNT", str(count)])

    return self.append_command(RequestType.XRange, args)

xread(keys_and_ids, options=None)

Reads entries from the given streams.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys_and_ids Mapping[TEncodable, TEncodable]

A mapping of stream keys to stream entry IDs to read from.

required
options Optional[StreamReadOptions]

Options detailing how to read the stream.

None
Command response

Optional[Mapping[bytes, Mapping[bytes, List[List[bytes]]]]]: A mapping of stream keys, to a mapping of stream IDs, to a list of pairings with format [[field, entry], [field, entry], ...].

None will be returned under the following conditions:

- All key-ID pairs in `keys_and_ids` have either a non-existing key or a non-existing ID,
  or there are no entries after the given ID.
- The `BLOCK` option is specified and the timeout is hit.
Source code in glide/async_commands/transaction.py
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
def xread(
    self: TTransaction,
    keys_and_ids: Mapping[TEncodable, TEncodable],
    options: Optional[StreamReadOptions] = None,
) -> TTransaction:
    """
    Reads entries from the given streams.

    See [valkey.io](https://valkey.io/commands/xread) for more details.

    Args:
        keys_and_ids (Mapping[TEncodable, TEncodable]): A mapping of stream keys to stream entry IDs to read from.
        options (Optional[StreamReadOptions]): Options detailing how to read the stream.

    Command response:
        Optional[Mapping[bytes, Mapping[bytes, List[List[bytes]]]]]: A mapping of stream keys, to a mapping of stream IDs,
        to a list of pairings with format `[[field, entry], [field, entry], ...]`.

        None will be returned under the following conditions:

            - All key-ID pairs in `keys_and_ids` have either a non-existing key or a non-existing ID,
              or there are no entries after the given ID.
            - The `BLOCK` option is specified and the timeout is hit.
    """
    args: List[TEncodable] = [] if options is None else options.to_args()
    args.append("STREAMS")
    args.extend([key for key in keys_and_ids.keys()])
    args.extend([value for value in keys_and_ids.values()])

    return self.append_command(RequestType.XRead, args)

xreadgroup(keys_and_ids, group_name, consumer_name, options=None)

Reads entries from the given streams owned by a consumer group.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys_and_ids Mapping[TEncodable, TEncodable]

A mapping of stream keys to stream entry IDs to read from. Use the special entry ID of ">" to receive only new messages.

required
group_name TEncodable

The consumer group name.

required
consumer_name TEncodable

The consumer name. The consumer will be auto-created if it does not already exist.

required
options Optional[StreamReadGroupOptions]

Options detailing how to read the stream.

None
Command response

Optional[Mapping[bytes, Mapping[bytes, Optional[List[List[bytes]]]]]]: A mapping of stream keys, to a mapping of stream IDs, to a list of pairings with format [[field, entry], [field, entry], ...].

Returns None if the BLOCK option is given and a timeout occurs, or if there is no stream that can be served.

Source code in glide/async_commands/transaction.py
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
def xreadgroup(
    self: TTransaction,
    keys_and_ids: Mapping[TEncodable, TEncodable],
    group_name: TEncodable,
    consumer_name: TEncodable,
    options: Optional[StreamReadGroupOptions] = None,
) -> TTransaction:
    """
    Reads entries from the given streams owned by a consumer group.

    See [valkey.io](https://valkey.io/commands/xreadgroup) for more details.

    Args:
        keys_and_ids (Mapping[TEncodable, TEncodable]): A mapping of stream keys to stream entry IDs to read from.
            Use the special entry ID of `">"` to receive only new messages.
        group_name (TEncodable): The consumer group name.
        consumer_name (TEncodable): The consumer name. The consumer will be auto-created if it does not already exist.
        options (Optional[StreamReadGroupOptions]): Options detailing how to read the stream.

    Command response:
        Optional[Mapping[bytes, Mapping[bytes, Optional[List[List[bytes]]]]]]: A mapping of stream keys, to a mapping of
        stream IDs, to a list of pairings with format `[[field, entry], [field, entry], ...]`.

        Returns None if the BLOCK option is given and a timeout occurs, or if there is no stream that can be served.
    """
    args = ["GROUP", group_name, consumer_name]
    if options is not None:
        args.extend(options.to_args())

    args.append("STREAMS")
    args.extend([key for key in keys_and_ids.keys()])
    args.extend([value for value in keys_and_ids.values()])

    return self.append_command(RequestType.XReadGroup, args)

xrevrange(key, end, start, count=None)

Returns stream entries matching a given range of IDs in reverse order. Equivalent to XRANGE but returns the entries in reverse order.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
end StreamRangeBound

The ending stream ID bound for the range.

  • Use IdBound to specify a stream ID.
  • Use ExclusiveIdBound to specify an exclusive bounded stream ID.
  • Use MaxId to end with the maximum available ID.
required
start StreamRangeBound

The starting stream ID bound for the range.

  • Use IdBound to specify a stream ID.
  • Use ExclusiveIdBound to specify an exclusive bounded stream ID.
  • Use MinId to start with the minimum available ID.
required
count Optional[int]

An optional argument specifying the maximum count of stream entries to return. If count is not provided, all stream entries in the range will be returned.

None
Command response

Optional[Mapping[bytes, List[List[bytes]]]]: A mapping of stream IDs to stream entry data, where entry data is a list of pairings with format [[field, entry], [field, entry], ...].

Returns None if the range arguments are not applicable.

Source code in glide/async_commands/transaction.py
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
def xrevrange(
    self: TTransaction,
    key: TEncodable,
    end: StreamRangeBound,
    start: StreamRangeBound,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Returns stream entries matching a given range of IDs in reverse order. Equivalent to `XRANGE` but returns the
    entries in reverse order.

    See [valkey.io](https://valkey.io/commands/xrevrange) for more details.

    Args:
        key (TEncodable): The key of the stream.
        end (StreamRangeBound): The ending stream ID bound for the range.

            - Use `IdBound` to specify a stream ID.
            - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
            - Use `MaxId` to end with the maximum available ID.

        start (StreamRangeBound): The starting stream ID bound for the range.

            - Use `IdBound` to specify a stream ID.
            - Use `ExclusiveIdBound` to specify an exclusive bounded stream ID.
            - Use `MinId` to start with the minimum available ID.

        count (Optional[int]): An optional argument specifying the maximum count of stream entries to return.
            If `count` is not provided, all stream entries in the range will be returned.

    Command response:
        Optional[Mapping[bytes, List[List[bytes]]]]: A mapping of stream IDs to stream entry data, where entry data is a
        list of pairings with format `[[field, entry], [field, entry], ...]`.

        Returns None if the range arguments are not applicable.
    """
    args = [key, end.to_arg(), start.to_arg()]
    if count is not None:
        args.extend(["COUNT", str(count)])

    return self.append_command(RequestType.XRevRange, args)

xtrim(key, options)

Trims the stream stored at key by evicting older entries.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the stream.

required
options StreamTrimOptions

Options detailing how to trim the stream. See StreamTrimOptions.

required
Commands response

int: TThe number of entries deleted from the stream.

If key doesn't exist, 0 is returned.

Source code in glide/async_commands/transaction.py
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
def xtrim(
    self: TTransaction,
    key: TEncodable,
    options: StreamTrimOptions,
) -> TTransaction:
    """
    Trims the stream stored at `key` by evicting older entries.

    See [valkey.io](https://valkey.io/commands/xtrim) for more details.

    Args:
        key (TEncodable): The key of the stream.
        options (StreamTrimOptions): Options detailing how to trim the stream. See `StreamTrimOptions`.

    Commands response:
        int: TThe number of entries deleted from the stream.

        If `key` doesn't exist, 0 is returned.
    """
    args = [key]
    if options:
        args.extend(options.to_args())

    return self.append_command(RequestType.XTrim, args)

zadd(key, members_scores, existing_options=None, update_condition=None, changed=False)

Adds members with their scores to the sorted set stored at key. If a member is already a part of the sorted set, its score is updated.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
members_scores Mapping[TEncodable, float]

A mapping of members to their corresponding scores.

required
existing_options Optional[ConditionalChange]

Options for handling existing members.

  • NX: Only add new elements.
  • XX: Only update existing elements.
None
update_condition Optional[UpdateOptions]

Options for updating scores.

  • GT: Only update scores greater than the current values.
  • LT: Only update scores less than the current values.
None
changed bool

Modify the return value to return the number of changed elements, instead of the number of new elements added.

False
Commands response

int: The number of elements added to the sorted set.

If changed is set, returns the number of elements updated in the sorted set.

Source code in glide/async_commands/transaction.py
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
def zadd(
    self: TTransaction,
    key: TEncodable,
    members_scores: Mapping[TEncodable, float],
    existing_options: Optional[ConditionalChange] = None,
    update_condition: Optional[UpdateOptions] = None,
    changed: bool = False,
) -> TTransaction:
    """
    Adds members with their scores to the sorted set stored at `key`.
    If a member is already a part of the sorted set, its score is updated.

    See [valkey.io](https://valkey.io/commands/zadd/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        members_scores (Mapping[TEncodable, float]): A mapping of members to their corresponding scores.
        existing_options (Optional[ConditionalChange]): Options for handling existing members.

            - NX: Only add new elements.
            - XX: Only update existing elements.

        update_condition (Optional[UpdateOptions]): Options for updating scores.

            - GT: Only update scores greater than the current values.
            - LT: Only update scores less than the current values.

        changed (bool): Modify the return value to return the number of changed elements, instead of the number
            of new elements added.

    Commands response:
        int: The number of elements added to the sorted set.

        If `changed` is set, returns the number of elements updated in the sorted set.
    """
    args = [key]
    if existing_options:
        args.append(existing_options.value)

    if update_condition:
        args.append(update_condition.value)

    if changed:
        args.append("CH")

    if existing_options and update_condition:
        if existing_options == ConditionalChange.ONLY_IF_DOES_NOT_EXIST:
            raise ValueError(
                "The GT, LT and NX options are mutually exclusive. "
                f"Cannot choose both {update_condition.value} and NX."
            )

    members_scores_list = [
        str(item) for pair in members_scores.items() for item in pair[::-1]
    ]
    args += members_scores_list

    return self.append_command(RequestType.ZAdd, args)

zadd_incr(key, member, increment, existing_options=None, update_condition=None)

Increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
member TEncodable

A member in the sorted set to increment.

required
increment float

The score to increment the member.

required
existing_options Optional[ConditionalChange]

Options for handling the member's existence.

  • NX: Only increment a member that doesn't exist.
  • XX: Only increment an existing member.
None
update_condition Optional[UpdateOptions]

Options for updating the score.

  • GT: Only increment the score of the member if the new score will be greater than the current score.
  • LT: Only increment (decrement) the score of the member if the new score will be less than the current score.
None
Commands response

Optional[float]: The score of the member.

If there was a conflict with choosing the XX/NX/LT/GT options, the operation aborts and None is returned.

Source code in glide/async_commands/transaction.py
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
def zadd_incr(
    self: TTransaction,
    key: TEncodable,
    member: TEncodable,
    increment: float,
    existing_options: Optional[ConditionalChange] = None,
    update_condition: Optional[UpdateOptions] = None,
) -> TTransaction:
    """
    Increments the score of member in the sorted set stored at `key` by `increment`.
    If `member` does not exist in the sorted set, it is added with `increment` as its score (as if its
    previous score was 0.0).
    If `key` does not exist, a new sorted set with the specified member as its sole member is created.

    See [valkey.io](https://valkey.io/commands/zadd/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        member (TEncodable): A member in the sorted set to increment.
        increment (float): The score to increment the member.
        existing_options (Optional[ConditionalChange]): Options for handling the member's existence.

            - NX: Only increment a member that doesn't exist.
            - XX: Only increment an existing member.

        update_condition (Optional[UpdateOptions]): Options for updating the score.

            - GT: Only increment the score of the member if the new score will be greater than the current score.
            - LT: Only increment (decrement) the score of the member if the new score will be less than the current score.

    Commands response:
        Optional[float]: The score of the member.

        If there was a conflict with choosing the XX/NX/LT/GT options, the operation aborts and None is returned.
    """
    args = [key]
    if existing_options:
        args.append(existing_options.value)

    if update_condition:
        args.append(update_condition.value)

    args.append("INCR")

    if existing_options and update_condition:
        if existing_options == ConditionalChange.ONLY_IF_DOES_NOT_EXIST:
            raise ValueError(
                "The GT, LT and NX options are mutually exclusive. "
                f"Cannot choose both {update_condition.value} and NX."
            )

    args += [str(increment), member]
    return self.append_command(RequestType.ZAdd, args)

zcard(key)

Returns the cardinality (number of elements) of the sorted set stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
Commands response

int: The number of elements in the sorted set.

If key does not exist, it is treated as an empty sorted set, and the command returns 0.

Source code in glide/async_commands/transaction.py
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
def zcard(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns the cardinality (number of elements) of the sorted set stored at `key`.

    See [valkey.io](https://valkey.io/commands/zcard/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.

    Commands response:
        int: The number of elements in the sorted set.

        If `key` does not exist, it is treated as an empty sorted set, and the command returns 0.
    """
    return self.append_command(RequestType.ZCard, [key])

zcount(key, min_score, max_score)

Returns the number of members in the sorted set stored at key with scores between min_score and max_score.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
min_score Union[InfBound, ScoreBoundary]

The minimum score to count from. Can be an instance of InfBound representing positive/negative infinity, or ScoreBoundary representing a specific score and inclusivity.

required
max_score Union[InfBound, ScoreBoundary]

The maximum score to count up to. Can be an instance of InfBound representing positive/negative infinity, or ScoreBoundary representing a specific score and inclusivity.

required
Commands response

int: The number of members in the specified score range.

If key does not exist, 0 is returned.

If max_score < min_score, 0 is returned.

Source code in glide/async_commands/transaction.py
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
def zcount(
    self: TTransaction,
    key: TEncodable,
    min_score: Union[InfBound, ScoreBoundary],
    max_score: Union[InfBound, ScoreBoundary],
) -> TTransaction:
    """
    Returns the number of members in the sorted set stored at `key` with scores between `min_score` and `max_score`.

    See [valkey.io](https://valkey.io/commands/zcount/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        min_score (Union[InfBound, ScoreBoundary]): The minimum score to count from.
            Can be an instance of InfBound representing positive/negative infinity,
            or ScoreBoundary representing a specific score and inclusivity.
        max_score (Union[InfBound, ScoreBoundary]): The maximum score to count up to.
            Can be an instance of InfBound representing positive/negative infinity,
            or ScoreBoundary representing a specific score and inclusivity.

    Commands response:
        int: The number of members in the specified score range.

        If key does not exist, 0 is returned.

        If `max_score` < `min_score`, 0 is returned.
    """
    score_min = (
        min_score.value["score_arg"]
        if isinstance(min_score, InfBound)
        else min_score.value
    )
    score_max = (
        max_score.value["score_arg"]
        if isinstance(max_score, InfBound)
        else max_score.value
    )
    return self.append_command(RequestType.ZCount, [key, score_min, score_max])

zdiff(keys)

Returns the difference between the first sorted set and all the successive sorted sets. To get the elements with their scores, see zdiff_withscores.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
Command response

List[bytes]: A list of elements representing the difference between the sorted sets.

If the first key does not exist, it is treated as an empty sorted set, and the command returns an empty list.

Source code in glide/async_commands/transaction.py
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
def zdiff(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Returns the difference between the first sorted set and all the successive sorted sets.
    To get the elements with their scores, see `zdiff_withscores`.

    See [valkey.io](https://valkey.io/commands/zdiff) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.

    Command response:
        List[bytes]: A list of elements representing the difference between the sorted sets.

        If the first key does not exist, it is treated as an empty sorted set, and the command returns an
        empty list.
    """
    args: List[TEncodable] = [str(len(keys))]
    args.extend(keys)
    return self.append_command(RequestType.ZDiff, args)

zdiff_withscores(keys)

Returns the difference between the first sorted set and all the successive sorted sets, with the associated scores.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
Command response

Mapping[bytes, float]: A mapping of elements and their scores representing the difference between the sorted sets.

If the first key does not exist, it is treated as an empty sorted set, and the command returns an empty list.

Source code in glide/async_commands/transaction.py
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
def zdiff_withscores(self: TTransaction, keys: List[TEncodable]) -> TTransaction:
    """
    Returns the difference between the first sorted set and all the successive sorted sets, with the associated scores.

    See [valkey.io](https://valkey.io/commands/zdiff) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.

    Command response:
        Mapping[bytes, float]: A mapping of elements and their scores representing the difference between the sorted sets.

        If the first `key` does not exist, it is treated as an empty sorted set, and the command returns an
        empty list.
    """
    return self.append_command(
        RequestType.ZDiff, [str(len(keys))] + keys + ["WITHSCORES"]
    )

zdiffstore(destination, keys)

Calculates the difference between the first sorted set and all the successive sorted sets at keys and stores the difference as a sorted set to destination, overwriting it if it already exists. Non-existent keys are treated as empty sets.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key for the resulting sorted set.

required
keys List[TEncodable]

The keys of the sorted sets to compare.

required
Command response

int: The number of members in the resulting sorted set stored at destination.

Source code in glide/async_commands/transaction.py
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
def zdiffstore(
    self: TTransaction,
    destination: TEncodable,
    keys: List[TEncodable],
) -> TTransaction:
    """
    Calculates the difference between the first sorted set and all the successive sorted sets at `keys` and stores
    the difference as a sorted set to `destination`, overwriting it if it already exists. Non-existent keys are
    treated as empty sets.

    See [valkey.io](https://valkey.io/commands/zdiffstore) for more details.

    Args:
        destination (TEncodable): The key for the resulting sorted set.
        keys (List[TEncodable]): The keys of the sorted sets to compare.

    Command response:
        int: The number of members in the resulting sorted set stored at `destination`.
    """
    return self.append_command(
        RequestType.ZDiffStore, [destination, str(len(keys))] + keys
    )

zincrby(key, increment, member)

Increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score. If key does not exist, a new sorted set is created with the specified member as its sole member.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
increment float

The score increment.

required
member TEncodable

A member of the sorted set.

required
Commands response

float: The new score of member.

Source code in glide/async_commands/transaction.py
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
def zincrby(
    self: TTransaction,
    key: TEncodable,
    increment: float,
    member: TEncodable,
) -> TTransaction:
    """
    Increments the score of `member` in the sorted set stored at `key` by `increment`.
    If `member` does not exist in the sorted set, it is added with `increment` as its score.
    If `key` does not exist, a new sorted set is created with the specified member as its sole member.

    See [valkey.io](https://valkey.io/commands/zincrby/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        increment (float): The score increment.
        member (TEncodable): A member of the sorted set.

    Commands response:
        float: The new score of `member`.
    """
    return self.append_command(RequestType.ZIncrBy, [key, str(increment), member])

zinter(keys)

Computes the intersection of sorted sets given by the specified keys and returns a list of intersecting elements.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
Command response

List[bytes]: The resulting array of intersecting elements.

Source code in glide/async_commands/transaction.py
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
def zinter(
    self: TTransaction,
    keys: List[TEncodable],
) -> TTransaction:
    """
    Computes the intersection of sorted sets given by the specified `keys` and returns a list of intersecting elements.

    See [valkey.io](https://valkey.io/commands/zinter/) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.

    Command response:
        List[bytes]: The resulting array of intersecting elements.
    """
    args: List[TEncodable] = [str(len(keys))]
    args.extend(keys)
    return self.append_command(RequestType.ZInter, args)

zinter_withscores(keys, aggregation_type=None)

Computes the intersection of sorted sets given by the specified keys and returns a sorted set of intersecting elements with scores.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys Union[List[TEncodable], List[Tuple[TEncodable, float]]]

The keys of the sorted sets with possible formats:

  • List[TEncodable] - for keys only.
  • List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.
required
aggregation_type Optional[AggregationType]

Specifies the aggregation strategy to apply when combining the scores of elements. See AggregationType.

None
Command response

Mapping[bytes, float]: The resulting sorted set with scores.

Source code in glide/async_commands/transaction.py
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
def zinter_withscores(
    self: TTransaction,
    keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
    aggregation_type: Optional[AggregationType] = None,
) -> TTransaction:
    """
    Computes the intersection of sorted sets given by the specified `keys` and returns a sorted set of
    intersecting elements with scores.

    See [valkey.io](https://valkey.io/commands/zinter/) for more details.

    Args:
        keys (Union[List[TEncodable], List[Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

            - List[TEncodable] - for keys only.
            - List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.

        aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
            when combining the scores of elements. See `AggregationType`.

    Command response:
        Mapping[bytes, float]: The resulting sorted set with scores.
    """
    args = _create_zinter_zunion_cmd_args(keys, aggregation_type)
    args.append("WITHSCORES")
    return self.append_command(RequestType.ZInter, args)

zintercard(keys, limit=None)

Returns the cardinality of the intersection of the sorted sets specified by keys. When provided with the optional limit argument, if the intersection cardinality reaches limit partway through the computation, the algorithm will exit early and yield limit as the cardinality.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets to intersect.

required
limit Optional[int]

An optional argument that can be used to specify a maximum number for the intersection cardinality. If limit is not supplied, or if it is set to 0, there will be no limit.

None
Command response

int: The cardinality of the intersection of the given sorted sets, or the limit if reached.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
def zintercard(
    self: TTransaction, keys: List[TEncodable], limit: Optional[int] = None
) -> TTransaction:
    """
    Returns the cardinality of the intersection of the sorted sets specified by `keys`. When provided with the
    optional `limit` argument, if the intersection cardinality reaches `limit` partway through the computation, the
    algorithm will exit early and yield `limit` as the cardinality.

    See [valkey.io](https://valkey.io/commands/zintercard) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets to intersect.
        limit (Optional[int]): An optional argument that can be used to specify a maximum number for the
            intersection cardinality. If limit is not supplied, or if it is set to 0, there will be no limit.

    Command response:
        int: The cardinality of the intersection of the given sorted sets, or the `limit` if reached.

    Since: Valkey version 7.0.0.
    """
    args = [str(len(keys))] + keys
    if limit is not None:
        args.extend(["LIMIT", str(limit)])

    return self.append_command(RequestType.ZInterCard, args)

zinterstore(destination, keys, aggregation_type=None)

Computes the intersection of sorted sets given by the specified keys and stores the result in destination. If destination already exists, it is overwritten. Otherwise, a new sorted set will be created.

Note

When in cluster mode, destination and all keys in keys must map to the same hash slot.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key of the destination sorted set.

required
keys Union[List[TEncodable], Tuple[TEncodable, float]]]

The keys of the sorted sets with possible formats:

  • List[TEncodable] - for keys only.
  • List[Tuple[TEncodable, float]]] - for weighted keys with score multipliers.
required
aggregation_type Optional[AggregationType]

Specifies the aggregation strategy to apply when combining the scores of elements. See AggregationType.

None
Command response

int: The number of elements in the resulting sorted set stored at destination.

Source code in glide/async_commands/transaction.py
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
def zinterstore(
    self: TTransaction,
    destination: TEncodable,
    keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
    aggregation_type: Optional[AggregationType] = None,
) -> TTransaction:
    """
    Computes the intersection of sorted sets given by the specified `keys` and stores the result in `destination`.
    If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.

    Note:
        When in cluster mode, `destination` and all keys in `keys` must map to the same hash slot.

    See [valkey.io](https://valkey.io/commands/zinterstore/) for more details.

    Args:
        destination (TEncodable): The key of the destination sorted set.
        keys (Union[List[TEncodable], Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

            - List[TEncodable] - for keys only.
            - List[Tuple[TEncodable, float]]] - for weighted keys with score multipliers.

        aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
            when combining the scores of elements. See `AggregationType`.

    Command response:
        int: The number of elements in the resulting sorted set stored at `destination`.
    """
    args = _create_zinter_zunion_cmd_args(keys, aggregation_type, destination)
    return self.append_command(RequestType.ZInterStore, args)

zlexcount(key, min_lex, max_lex)

Returns the number of members in the sorted set stored at key with lexographical values between min_lex and max_lex.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
min_lex Union[InfBound, LexBoundary]

The minimum lexicographical value to count from. Can be an instance of InfBound representing positive/negative infinity, or LexBoundary representing a specific lexicographical value and inclusivity.

required
max_lex Union[InfBound, LexBoundary]

The maximum lexicographical value to count up to. Can be an instance of InfBound representing positive/negative infinity, or LexBoundary representing a specific lexicographical value and inclusivity.

required
Command response

int: The number of members in the specified lexicographical range.

If key does not exist, it is treated as an empty sorted set, and the command returns 0.

If max_lex < min_lex, 0 is returned.

Source code in glide/async_commands/transaction.py
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
def zlexcount(
    self: TTransaction,
    key: TEncodable,
    min_lex: Union[InfBound, LexBoundary],
    max_lex: Union[InfBound, LexBoundary],
) -> TTransaction:
    """
    Returns the number of members in the sorted set stored at `key` with lexographical values between
    `min_lex` and `max_lex`.

    See [valkey.io](https://valkey.io/commands/zlexcount/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        min_lex (Union[InfBound, LexBoundary]): The minimum lexicographical value to count from.
            Can be an instance of InfBound representing positive/negative infinity,
            or LexBoundary representing a specific lexicographical value and inclusivity.
        max_lex (Union[InfBound, LexBoundary]): The maximum lexicographical value to count up to.
            Can be an instance of InfBound representing positive/negative infinity,
            or LexBoundary representing a specific lexicographical value and inclusivity.

    Command response:
        int: The number of members in the specified lexicographical range.

        If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`.

        If `max_lex < min_lex`, `0` is returned.
    """
    min_lex_arg = (
        min_lex.value["lex_arg"] if isinstance(min_lex, InfBound) else min_lex.value
    )
    max_lex_arg = (
        max_lex.value["lex_arg"] if isinstance(max_lex, InfBound) else max_lex.value
    )

    return self.append_command(
        RequestType.ZLexCount, [key, min_lex_arg, max_lex_arg]
    )

zmpop(keys, filter, count=None)

Pops a member-score pair from the first non-empty sorted set, with the given keys being checked in the order that they are given. The optional count argument can be used to specify the number of elements to pop, and is set to 1 by default. The number of popped elements is the minimum from the sorted set's cardinality and count.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
modifier ScoreFilter

The element pop criteria - either ScoreFilter.MIN or ScoreFilter.MAX to pop members with the lowest/highest scores accordingly.

required
count Optional[int]

The number of elements to pop.

None
Command response

Optional[List[Union[bytes, Mapping[bytes, float]]]]: A two-element list containing the key name of the set from which elements were popped, and a member-score mapping of the popped elements.

If no members could be popped, returns None.

Since: Valkey version 7.0.0.

Source code in glide/async_commands/transaction.py
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
def zmpop(
    self: TTransaction,
    keys: List[TEncodable],
    filter: ScoreFilter,
    count: Optional[int] = None,
) -> TTransaction:
    """
    Pops a member-score pair from the first non-empty sorted set, with the given keys being checked in the order
    that they are given. The optional `count` argument can be used to specify the number of elements to pop, and is
    set to 1 by default. The number of popped elements is the minimum from the sorted set's cardinality and `count`.

    See [valkey.io](https://valkey.io/commands/zmpop) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.
        modifier (ScoreFilter): The element pop criteria - either ScoreFilter.MIN or ScoreFilter.MAX to pop
            members with the lowest/highest scores accordingly.
        count (Optional[int]): The number of elements to pop.

    Command response:
        Optional[List[Union[bytes, Mapping[bytes, float]]]]: A two-element list containing the key name of the set from
        which elements were popped, and a member-score mapping of the popped elements.

        If no members could be popped, returns None.

    Since: Valkey version 7.0.0.
    """
    args = [str(len(keys))] + keys + [filter.value]
    if count is not None:
        args = args + ["COUNT", str(count)]

    return self.append_command(RequestType.ZMPop, args)

zmscore(key, members)

Returns the scores associated with the specified members in the sorted set stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
members List[TEncodable]

A list of members in the sorted set.

required
Command response

List[Optional[float]]: A list of scores corresponding to members.

If a member does not exist in the sorted set, the corresponding value in the list will be None.

Source code in glide/async_commands/transaction.py
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
def zmscore(
    self: TTransaction, key: TEncodable, members: List[TEncodable]
) -> TTransaction:
    """
    Returns the scores associated with the specified `members` in the sorted set stored at `key`.

    See [valkey.io](https://valkey.io/commands/zmscore) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        members (List[TEncodable]): A list of members in the sorted set.

    Command response:
        List[Optional[float]]: A list of scores corresponding to `members`.

        If a member does not exist in the sorted set, the corresponding value in the list will be None.
    """
    return self.append_command(RequestType.ZMScore, [key] + members)

zpopmax(key, count=None)

Removes and returns the members with the highest scores from the sorted set stored at key. If count is provided, up to count members with the highest scores are removed and returned. Otherwise, only one member with the highest score is removed and returned.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
count Optional[int]

Specifies the quantity of members to pop. If not specified, pops one member. If count is higher than the sorted set's cardinality, returns all members and their scores, ordered from highest to lowest.

None
Commands response

Mapping[bytes, float]: A map of the removed members and their scores, ordered from the one with the highest score to the one with the lowest.

If key doesn't exist, it will be treated as an emtpy sorted set and the command returns an empty map.

Source code in glide/async_commands/transaction.py
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
def zpopmax(
    self: TTransaction, key: TEncodable, count: Optional[int] = None
) -> TTransaction:
    """
    Removes and returns the members with the highest scores from the sorted set stored at `key`.
    If `count` is provided, up to `count` members with the highest scores are removed and returned.
    Otherwise, only one member with the highest score is removed and returned.

    See [valkey.io](https://valkey.io/commands/zpopmax) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        count (Optional[int]): Specifies the quantity of members to pop. If not specified, pops one member.
            If `count` is higher than the sorted set's cardinality, returns all members and their scores,
            ordered from highest to lowest.

    Commands response:
        Mapping[bytes, float]: A map of the removed members and their scores, ordered from the one with the highest score
        to the one with the lowest.

        If `key` doesn't exist, it will be treated as an emtpy sorted set and the command returns an empty map.
    """
    return self.append_command(
        RequestType.ZPopMax, [key, str(count)] if count else [key]
    )

zpopmin(key, count=None)

Removes and returns the members with the lowest scores from the sorted set stored at key. If count is provided, up to count members with the lowest scores are removed and returned. Otherwise, only one member with the lowest score is removed and returned.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
count Optional[int]

Specifies the quantity of members to pop. If not specified, pops one member. If count is higher than the sorted set's cardinality, returns all members and their scores.

None
Commands response

Mapping[bytes, float]: A map of the removed members and their scores, ordered from the one with the lowest score to the one with the highest.

If key doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.

Source code in glide/async_commands/transaction.py
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
def zpopmin(
    self: TTransaction, key: TEncodable, count: Optional[int] = None
) -> TTransaction:
    """
    Removes and returns the members with the lowest scores from the sorted set stored at `key`.
    If `count` is provided, up to `count` members with the lowest scores are removed and returned.
    Otherwise, only one member with the lowest score is removed and returned.

    See [valkey.io](https://valkey.io/commands/zpopmin) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        count (Optional[int]): Specifies the quantity of members to pop. If not specified, pops one member.
            If `count` is higher than the sorted set's cardinality, returns all members and their scores.

    Commands response:
        Mapping[bytes, float]: A map of the removed members and their scores, ordered from the one with the lowest score
        to the one with the highest.

        If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
    """
    return self.append_command(
        RequestType.ZPopMin, [key, str(count)] if count else [key]
    )

zrandmember(key)

Returns a random member from the sorted set stored at 'key'.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
Command response

Optional[bytes]: A random member from the sorted set.

If the sorted set does not exist or is empty, the response will be None.

Source code in glide/async_commands/transaction.py
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
def zrandmember(self: TTransaction, key: TEncodable) -> TTransaction:
    """
    Returns a random member from the sorted set stored at 'key'.

    See [valkey.io](https://valkey.io/commands/zrandmember) for more details.

    Args:
        key (TEncodable): The key of the sorted set.

    Command response:
        Optional[bytes]: A random member from the sorted set.

        If the sorted set does not exist or is empty, the response will be None.
    """
    return self.append_command(RequestType.ZRandMember, [key])

zrandmember_count(key, count)

Retrieves up to the absolute value of count random members from the sorted set stored at 'key'.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
count int

The number of members to return.

  • If count is positive, returns unique members.
  • If count is negative, allows for duplicates members.
required
Command response

List[bytes]: A list of members from the sorted set.

If the sorted set does not exist or is empty, the response will be an empty list.

Source code in glide/async_commands/transaction.py
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
def zrandmember_count(
    self: TTransaction, key: TEncodable, count: int
) -> TTransaction:
    """
    Retrieves up to the absolute value of `count` random members from the sorted set stored at 'key'.

    See [valkey.io](https://valkey.io/commands/zrandmember) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        count (int): The number of members to return.

            - If `count` is positive, returns unique members.
            - If `count` is negative, allows for duplicates members.

    Command response:
        List[bytes]: A list of members from the sorted set.

        If the sorted set does not exist or is empty, the response will be an empty list.
    """
    return self.append_command(RequestType.ZRandMember, [key, str(count)])

zrandmember_withscores(key, count)

Retrieves up to the absolute value of count random members along with their scores from the sorted set stored at 'key'.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
count int

The number of members to return.

  • If count is positive, returns unique members.
  • If count is negative, allows for duplicates members.
required
Command response

List[List[Union[bytes, float]]]: A list of [member, score] lists, where member is a random member from the sorted set and score is the associated score.

If the sorted set does not exist or is empty, the response will be an empty list.

Source code in glide/async_commands/transaction.py
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
def zrandmember_withscores(
    self: TTransaction, key: TEncodable, count: int
) -> TTransaction:
    """
    Retrieves up to the absolute value of `count` random members along with their scores from the sorted set
    stored at 'key'.

    See [valkey.io](https://valkey.io/commands/zrandmember) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        count (int): The number of members to return.

            - If `count` is positive, returns unique members.
            - If `count` is negative, allows for duplicates members.

    Command response:
        List[List[Union[bytes, float]]]: A list of `[member, score]` lists, where `member` is a random member from
        the sorted set and `score` is the associated score.

        If the sorted set does not exist or is empty, the response will be an empty list.
    """
    return self.append_command(
        RequestType.ZRandMember, [key, str(count), "WITHSCORES"]
    )

zrange(key, range_query, reverse=False)

Returns the specified range of elements in the sorted set stored at key.

ZRANGE can perform different types of range queries: by index (rank), by the score, or by lexicographical order.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
range_query Union[RangeByIndex, RangeByLex, RangeByScore]

The range query object representing the type of range

required
reverse bool

If True, reverses the sorted set, with index 0 as the element with the highest score.

False
Commands response

List[bytes]: A list of elements within the specified range.

If key does not exist, it is treated as an empty sorted set, and the command returns an empty array.

Source code in glide/async_commands/transaction.py
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
def zrange(
    self: TTransaction,
    key: TEncodable,
    range_query: Union[RangeByIndex, RangeByLex, RangeByScore],
    reverse: bool = False,
) -> TTransaction:
    """
    Returns the specified range of elements in the sorted set stored at `key`.

    ZRANGE can perform different types of range queries: by index (rank), by the score, or by lexicographical order.

    See [valkey.io](https://valkey.io/commands/zrange/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        range_query (Union[RangeByIndex, RangeByLex, RangeByScore]): The range query object representing the type of range
        query to perform.

            - For range queries by index (rank), use RangeByIndex.
            - For range queries by lexicographical order, use RangeByLex.
            - For range queries by score, use RangeByScore.

        reverse (bool): If True, reverses the sorted set, with index 0 as the element with the highest score.

    Commands response:
        List[bytes]: A list of elements within the specified range.

        If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
    """
    args = _create_zrange_args(key, range_query, reverse, with_scores=False)

    return self.append_command(RequestType.ZRange, args)

zrange_withscores(key, range_query, reverse=False)

Returns the specified range of elements with their scores in the sorted set stored at key. Similar to ZRANGE but with a WITHSCORE flag.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
range_query Union[RangeByIndex, RangeByScore]

The range query object representing the type of range query

required
reverse bool

If True, reverses the sorted set, with index 0 as the element with the highest score.

False
Commands response

Mapping[bytes , float]: A map of elements and their scores within the specified range.

If key does not exist, it is treated as an empty sorted set, and the command returns an empty map.

Source code in glide/async_commands/transaction.py
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
def zrange_withscores(
    self: TTransaction,
    key: TEncodable,
    range_query: Union[RangeByIndex, RangeByScore],
    reverse: bool = False,
) -> TTransaction:
    """
    Returns the specified range of elements with their scores in the sorted set stored at `key`.
    Similar to ZRANGE but with a WITHSCORE flag.

    See [valkey.io](https://valkey.io/commands/zrange/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        range_query (Union[RangeByIndex, RangeByScore]): The range query object representing the type of range query
        to perform.

            - For range queries by index (rank), use RangeByIndex.
            - For range queries by score, use RangeByScore.

        reverse (bool): If True, reverses the sorted set, with index 0 as the element with the highest score.

    Commands response:
        Mapping[bytes , float]: A map of elements and their scores within the specified range.

        If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty map.
    """
    args = _create_zrange_args(key, range_query, reverse, with_scores=True)

    return self.append_command(RequestType.ZRange, args)

zrangestore(destination, source, range_query, reverse=False)

Stores a specified range of elements from the sorted set at source, into a new sorted set at destination. If destination doesn't exist, a new sorted set is created; if it exists, it's overwritten.

ZRANGESTORE can perform different types of range queries: by index (rank), by the score, or by lexicographical order.

See valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key for the destination sorted set.

required
source TEncodable

The key of the source sorted set.

required
range_query Union[RangeByIndex, RangeByLex, RangeByScore]

The range query object representing the type of

required
reverse bool

If True, reverses the sorted set, with index 0 as the element with the highest score.

False
Command response

int: The number of elements in the resulting sorted set.

Source code in glide/async_commands/transaction.py
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
def zrangestore(
    self: TTransaction,
    destination: TEncodable,
    source: TEncodable,
    range_query: Union[RangeByIndex, RangeByLex, RangeByScore],
    reverse: bool = False,
) -> TTransaction:
    """
    Stores a specified range of elements from the sorted set at `source`, into a new sorted set at `destination`. If
    `destination` doesn't exist, a new sorted set is created; if it exists, it's overwritten.

    ZRANGESTORE can perform different types of range queries: by index (rank), by the score, or by lexicographical
    order.

    See [valkey.io](https://valkey.io/commands/zrangestore) for more details.

    Args:
        destination (TEncodable): The key for the destination sorted set.
        source (TEncodable): The key of the source sorted set.
        range_query (Union[RangeByIndex, RangeByLex, RangeByScore]): The range query object representing the type of
        range query to perform.

            - For range queries by index (rank), use RangeByIndex.
            - For range queries by lexicographical order, use RangeByLex.
            - For range queries by score, use RangeByScore.

        reverse (bool): If True, reverses the sorted set, with index 0 as the element with the highest score.

    Command response:
        int: The number of elements in the resulting sorted set.
    """
    args = _create_zrange_args(source, range_query, reverse, False, destination)

    return self.append_command(RequestType.ZRangeStore, args)

zrank(key, member)

Returns the rank of member in the sorted set stored at key, with scores ordered from low to high.

See valkey.io for more details.

To get the rank of member with its score, see zrank_withscore.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
member TEncodable

The member whose rank is to be retrieved.

required
Commands response

Optional[int]: The rank of member in the sorted set.

If key doesn't exist, or if member is not present in the set, None will be returned.

Source code in glide/async_commands/transaction.py
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
def zrank(
    self: TTransaction,
    key: TEncodable,
    member: TEncodable,
) -> TTransaction:
    """
    Returns the rank of `member` in the sorted set stored at `key`, with scores ordered from low to high.

    See [valkey.io](https://valkey.io/commands/zrank) for more details.

    To get the rank of `member` with its score, see `zrank_withscore`.

    Args:
        key (TEncodable): The key of the sorted set.
        member (TEncodable): The member whose rank is to be retrieved.

    Commands response:
        Optional[int]: The rank of `member` in the sorted set.

        If `key` doesn't exist, or if `member` is not present in the set, None will be returned.
    """
    return self.append_command(RequestType.ZRank, [key, member])

zrank_withscore(key, member)

Returns the rank of member in the sorted set stored at key with its score, where scores are ordered from the lowest to highest.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
member TEncodable

The member whose rank is to be retrieved.

required
Commands response

Optional[List[Union[int, float]]]: A list containing the rank and score of member in the sorted set.

If key doesn't exist, or if member is not present in the set, None will be returned.

Since: Valkey version 7.2.0.

Source code in glide/async_commands/transaction.py
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
def zrank_withscore(
    self: TTransaction,
    key: TEncodable,
    member: TEncodable,
) -> TTransaction:
    """
    Returns the rank of `member` in the sorted set stored at `key` with its score, where scores are ordered from the
    lowest to highest.

    See [valkey.io](https://valkey.io/commands/zrank) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        member (TEncodable): The member whose rank is to be retrieved.

    Commands response:
        Optional[List[Union[int, float]]]: A list containing the rank and score of `member` in the sorted set.

        If `key` doesn't exist, or if `member` is not present in the set, None will be returned.

    Since: Valkey version 7.2.0.
    """
    return self.append_command(RequestType.ZRank, [key, member, "WITHSCORE"])

zrem(key, members)

Removes the specified members from the sorted set stored at key. Specified members that are not a member of this set are ignored.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
members List[TEncodable]

A list of members to remove from the sorted set.

required
Commands response

int: The number of members that were removed from the sorted set, not including non-existing members.

If key does not exist, it is treated as an empty sorted set, and the command returns 0.

Source code in glide/async_commands/transaction.py
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
def zrem(
    self: TTransaction,
    key: TEncodable,
    members: List[TEncodable],
) -> TTransaction:
    """
    Removes the specified members from the sorted set stored at `key`.
    Specified members that are not a member of this set are ignored.

    See [valkey.io](https://valkey.io/commands/zrem/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        members (List[TEncodable]): A list of members to remove from the sorted set.

    Commands response:
        int: The number of members that were removed from the sorted set, not including non-existing members.

        If `key` does not exist, it is treated as an empty sorted set, and the command returns 0.
    """
    return self.append_command(RequestType.ZRem, [key] + members)

zremrangebylex(key, min_lex, max_lex)

Removes all elements in the sorted set stored at key with a lexicographical order between min_lex and max_lex.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
min_lex Union[InfBound, LexBoundary]

The minimum bound of the lexicographical range. Can be an instance of InfBound representing positive/negative infinity, or LexBoundary representing a specific lex and inclusivity.

required
max_lex Union[InfBound, LexBoundary]

The maximum bound of the lexicographical range. Can be an instance of InfBound representing positive/negative infinity, or LexBoundary representing a specific lex and inclusivity.

required
Command response

int: The number of members that were removed from the sorted set.

If key does not exist, it is treated as an empty sorted set, and the command returns 0.

If min_lex is greater than max_lex, 0 is returned.

Source code in glide/async_commands/transaction.py
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
def zremrangebylex(
    self: TTransaction,
    key: TEncodable,
    min_lex: Union[InfBound, LexBoundary],
    max_lex: Union[InfBound, LexBoundary],
) -> TTransaction:
    """
    Removes all elements in the sorted set stored at `key` with a lexicographical order between `min_lex` and
    `max_lex`.

    See [valkey.io](https://valkey.io/commands/zremrangebylex/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        min_lex (Union[InfBound, LexBoundary]): The minimum bound of the lexicographical range.
            Can be an instance of `InfBound` representing positive/negative infinity, or `LexBoundary`
            representing a specific lex and inclusivity.
        max_lex (Union[InfBound, LexBoundary]): The maximum bound of the lexicographical range.
            Can be an instance of `InfBound` representing positive/negative infinity, or `LexBoundary`
            representing a specific lex and inclusivity.

    Command response:
        int: The number of members that were removed from the sorted set.

        If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`.

        If `min_lex` is greater than `max_lex`, `0` is returned.
    """
    min_lex_arg = (
        min_lex.value["lex_arg"] if isinstance(min_lex, InfBound) else min_lex.value
    )
    max_lex_arg = (
        max_lex.value["lex_arg"] if isinstance(max_lex, InfBound) else max_lex.value
    )

    return self.append_command(
        RequestType.ZRemRangeByLex, [key, min_lex_arg, max_lex_arg]
    )

zremrangebyrank(key, start, end)

Removes all elements in the sorted set stored at key with rank between start and end. Both start and end are zero-based indexes with 0 being the element with the lowest score. These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
start int

The starting point of the range.

required
end int

The end of the range.

required
Command response

int: The number of elements that were removed.

If start exceeds the end of the sorted set, or if start is greater than end, 0 is returned.

If end exceeds the actual end of the sorted set, the range will stop at the actual end of the sorted set.

If key does not exist, 0 is returned.

Source code in glide/async_commands/transaction.py
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
def zremrangebyrank(
    self: TTransaction,
    key: TEncodable,
    start: int,
    end: int,
) -> TTransaction:
    """
    Removes all elements in the sorted set stored at `key` with rank between `start` and `end`.
    Both `start` and `end` are zero-based indexes with 0 being the element with the lowest score.
    These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score.

    See [valkey.io](https://valkey.io/commands/zremrangebyrank/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        start (int): The starting point of the range.
        end (int): The end of the range.

    Command response:
        int: The number of elements that were removed.

        If `start` exceeds the end of the sorted set, or if `start` is greater than `end`, `0` is returned.

        If `end` exceeds the actual end of the sorted set, the range will stop at the actual end of the sorted set.

        If `key` does not exist, `0` is returned.
    """
    return self.append_command(
        RequestType.ZRemRangeByRank, [key, str(start), str(end)]
    )

zremrangebyscore(key, min_score, max_score)

Removes all elements in the sorted set stored at key with a score between min_score and max_score.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
min_score Union[InfBound, ScoreBoundary]

The minimum score to remove from. Can be an instance of InfBound representing positive/negative infinity, or ScoreBoundary representing a specific score and inclusivity.

required
max_score Union[InfBound, ScoreBoundary]

The maximum score to remove up to. Can be an instance of InfBound representing positive/negative infinity, or ScoreBoundary representing a specific score and inclusivity.

required
Commands response

int: The number of members that were removed from the sorted set.

If key does not exist, it is treated as an empty sorted set, and the command returns 0.

If min_score is greater than max_score, 0 is returned.

Source code in glide/async_commands/transaction.py
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
def zremrangebyscore(
    self: TTransaction,
    key: TEncodable,
    min_score: Union[InfBound, ScoreBoundary],
    max_score: Union[InfBound, ScoreBoundary],
) -> TTransaction:
    """
    Removes all elements in the sorted set stored at `key` with a score between `min_score` and `max_score`.

    See [valkey.io](https://valkey.io/commands/zremrangebyscore/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        min_score (Union[InfBound, ScoreBoundary]): The minimum score to remove from.
            Can be an instance of InfBound representing positive/negative infinity,
            or ScoreBoundary representing a specific score and inclusivity.
        max_score (Union[InfBound, ScoreBoundary]): The maximum score to remove up to.
            Can be an instance of InfBound representing positive/negative infinity,
            or ScoreBoundary representing a specific score and inclusivity.

    Commands response:
        int: The number of members that were removed from the sorted set.

        If `key` does not exist, it is treated as an empty sorted set, and the command returns 0.

        If `min_score` is greater than `max_score`, 0 is returned.
    """
    score_min = (
        min_score.value["score_arg"]
        if isinstance(min_score, InfBound)
        else min_score.value
    )
    score_max = (
        max_score.value["score_arg"]
        if isinstance(max_score, InfBound)
        else max_score.value
    )
    return self.append_command(
        RequestType.ZRemRangeByScore, [key, score_min, score_max]
    )

zrevrank(key, member)

Returns the rank of member in the sorted set stored at key, where scores are ordered from the highest to lowest, starting from 0.

To get the rank of member with its score, see zrevrank_withscore.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
member TEncodable

The member whose rank is to be retrieved.

required
Command response

Optional[int]: The rank of member in the sorted set, where ranks are ordered from high to low based on scores.

If key doesn't exist, or if member is not present in the set, None will be returned.

Source code in glide/async_commands/transaction.py
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
def zrevrank(
    self: TTransaction, key: TEncodable, member: TEncodable
) -> TTransaction:
    """
    Returns the rank of `member` in the sorted set stored at `key`, where scores are ordered from the highest to
    lowest, starting from `0`.

    To get the rank of `member` with its score, see `zrevrank_withscore`.

    See [valkey.io](https://valkey.io/commands/zrevrank) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        member (TEncodable): The member whose rank is to be retrieved.

    Command response:
        Optional[int]: The rank of `member` in the sorted set, where ranks are ordered from high to low based on scores.

        If `key` doesn't exist, or if `member` is not present in the set, `None` will be returned.
    """
    return self.append_command(RequestType.ZRevRank, [key, member])

zrevrank_withscore(key, member)

Returns the rank of member in the sorted set stored at key with its score, where scores are ordered from the highest to lowest, starting from 0.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
member TEncodable

The member whose rank is to be retrieved.

required
Command response

Optional[List[Union[int, float]]]: A list containing the rank (as int) and score (as float) of member in the sorted set, where ranks are ordered from high to low based on scores.

If key doesn't exist, or if member is not present in the set, None will be returned.

Since: Valkey version 7.2.0.

Source code in glide/async_commands/transaction.py
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
def zrevrank_withscore(
    self: TTransaction, key: TEncodable, member: TEncodable
) -> TTransaction:
    """
    Returns the rank of `member` in the sorted set stored at `key` with its score, where scores are ordered from the
    highest to lowest, starting from `0`.

    See [valkey.io](https://valkey.io/commands/zrevrank) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        member (TEncodable): The member whose rank is to be retrieved.

    Command response:
        Optional[List[Union[int, float]]]: A list containing the rank (as `int`) and score (as `float`) of `member`
        in the sorted set, where ranks are ordered from high to low based on scores.

        If `key` doesn't exist, or if `member` is not present in the set, `None` will be returned.

    Since: Valkey version 7.2.0.
    """
    return self.append_command(RequestType.ZRevRank, [key, member, "WITHSCORE"])

zscan(key, cursor, match=None, count=None, no_scores=False)

Iterates incrementally over a sorted set.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
cursor TEncodable

The cursor that points to the next iteration of results. A value of "0" indicates the start of the search.

required
match Optional[TEncodable]

The match filter is applied to the result of the command and will only include strings or byte strings that match the pattern specified. If the sorted set is large enough for scan commands to return only a subset of the sorted set then there could be a case where the result is empty although there are items that match the pattern specified. This is due to the default COUNT being 10 which indicates that it will only fetch and match 10 items from the list.

None
count Optional[int]

COUNT is a just a hint for the command for how many elements to fetch from the sorted set. COUNT could be ignored until the sorted set is large enough for the SCAN commands to represent the results as compact single-allocation packed encoding.

None
no_scores bool

If True, the command will not return scores associated with the members. Since Valkey "8.0.0".

False

Returns:

Type Description
TTransaction

List[Union[bytes, List[bytes]]]: An Array of the cursor and the subset of the sorted set held by key.

TTransaction

The first element is always the cursor for the next iteration of results. 0 will be the cursor

TTransaction

returned on the last iteration of the sorted set. The second element is always an Array of the subset

TTransaction

of the sorted set held in key. The Array in the second element is a flattened series of

TTransaction

String pairs, where the value is at even indices and the score is at odd indices.

TTransaction

If no_scores is set toTrue, the second element will only contain the members without scores.

Source code in glide/async_commands/transaction.py
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
def zscan(
    self: TTransaction,
    key: TEncodable,
    cursor: TEncodable,
    match: Optional[TEncodable] = None,
    count: Optional[int] = None,
    no_scores: bool = False,
) -> TTransaction:
    """
    Iterates incrementally over a sorted set.

    See [valkey.io](https://valkey.io/commands/zscan) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        cursor (TEncodable): The cursor that points to the next iteration of results. A value of "0" indicates the start of
            the search.
        match (Optional[TEncodable]): The match filter is applied to the result of the command and will only include
            strings or byte strings that match the pattern specified. If the sorted set is large enough for scan commands
            to return only a subset of the sorted set then there could be a case where the result is empty although there
            are items that match the pattern specified. This is due to the default `COUNT` being `10` which indicates
            that it will only fetch and match `10` items from the list.
        count (Optional[int]): `COUNT` is a just a hint for the command for how many elements to fetch from the
            sorted set. `COUNT` could be ignored until the sorted set is large enough for the `SCAN` commands to
            represent the results as compact single-allocation packed encoding.
        no_scores (bool): If `True`, the command will not return scores associated with the members. Since Valkey "8.0.0".

    Returns:
        List[Union[bytes, List[bytes]]]: An `Array` of the `cursor` and the subset of the sorted set held by `key`.
        The first element is always the `cursor` for the next iteration of results. `0` will be the `cursor`
        returned on the last iteration of the sorted set. The second element is always an `Array` of the subset
        of the sorted set held in `key`. The `Array` in the second element is a flattened series of
        `String` pairs, where the value is at even indices and the score is at odd indices.

        If `no_scores` is set to`True`, the second element will only contain the members without scores.
    """
    args = [key, cursor]
    if match is not None:
        args += ["MATCH", match]
    if count is not None:
        args += ["COUNT", str(count)]
    if no_scores:
        args.append("NOSCORES")

    return self.append_command(RequestType.ZScan, args)

zscore(key, member)

Returns the score of member in the sorted set stored at key.

See valkey.io for more details.

Parameters:

Name Type Description Default
key TEncodable

The key of the sorted set.

required
member TEncodable

The member whose score is to be retrieved.

required
Commands response

Optional[float]: The score of the member.

If member does not exist in the sorted set, None is returned.

If key does not exist, None is returned.

Source code in glide/async_commands/transaction.py
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
def zscore(self: TTransaction, key: TEncodable, member: TEncodable) -> TTransaction:
    """
    Returns the score of `member` in the sorted set stored at `key`.

    See [valkey.io](https://valkey.io/commands/zscore/) for more details.

    Args:
        key (TEncodable): The key of the sorted set.
        member (TEncodable): The member whose score is to be retrieved.

    Commands response:
        Optional[float]: The score of the member.

        If `member` does not exist in the sorted set, None is returned.

        If `key` does not exist,  None is returned.
    """
    return self.append_command(RequestType.ZScore, [key, member])

zunion(keys)

Computes the union of sorted sets given by the specified keys and returns a list of union elements.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys List[TEncodable]

The keys of the sorted sets.

required
Command response

List[bytes]: The resulting array of union elements.

Source code in glide/async_commands/transaction.py
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
def zunion(
    self: TTransaction,
    keys: List[TEncodable],
) -> TTransaction:
    """
    Computes the union of sorted sets given by the specified `keys` and returns a list of union elements.

    See [valkey.io](https://valkey.io/commands/zunion/) for more details.

    Args:
        keys (List[TEncodable]): The keys of the sorted sets.

    Command response:
        List[bytes]: The resulting array of union elements.
    """
    args: List[TEncodable] = [str(len(keys))]
    args.extend(keys)
    return self.append_command(RequestType.ZUnion, args)

zunion_withscores(keys, aggregation_type=None)

Computes the union of sorted sets given by the specified keys and returns a sorted set of union elements with scores.

See valkey.io for more details.

Parameters:

Name Type Description Default
keys Union[List[TEncodable], List[Tuple[TEncodable, float]]]

The keys of the sorted sets with possible formats:

  • List[TEncodable] - for keys only.
  • List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.
required
aggregation_type Optional[AggregationType]

Specifies the aggregation strategy to apply when combining the scores of elements. See AggregationType.

None
Command response

Mapping[bytes, float]: The resulting sorted set with scores.

Source code in glide/async_commands/transaction.py
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
def zunion_withscores(
    self: TTransaction,
    keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
    aggregation_type: Optional[AggregationType] = None,
) -> TTransaction:
    """
    Computes the union of sorted sets given by the specified `keys` and returns a sorted set of union elements with scores.

    See [valkey.io](https://valkey.io/commands/zunion/) for more details.

    Args:
        keys (Union[List[TEncodable], List[Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

            - List[TEncodable] - for keys only.
            - List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.

        aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
            when combining the scores of elements. See `AggregationType`.

    Command response:
        Mapping[bytes, float]: The resulting sorted set with scores.
    """
    args = _create_zinter_zunion_cmd_args(keys, aggregation_type)
    args.append("WITHSCORES")
    return self.append_command(RequestType.ZUnion, args)

zunionstore(destination, keys, aggregation_type=None)

Computes the union of sorted sets given by the specified keys and stores the result in destination. If destination already exists, it is overwritten. Otherwise, a new sorted set will be created.

Note

When in cluster mode, destination and all keys in keys must map to the same hash slot.

see valkey.io for more details.

Parameters:

Name Type Description Default
destination TEncodable

The key of the destination sorted set.

required
keys Union[List[TEncodable], List[Tuple[TEncodable, float]]]

The keys of the sorted sets with possible formats:

  • List[TEncodable] - for keys only.
  • List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.
required
aggregation_type Optional[AggregationType]

Specifies the aggregation strategy to apply when combining the scores of elements. See AggregationType.

None
Command response

int: The number of elements in the resulting sorted set stored at destination.

Source code in glide/async_commands/transaction.py
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
def zunionstore(
    self: TTransaction,
    destination: TEncodable,
    keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
    aggregation_type: Optional[Optional[AggregationType]] = None,
) -> TTransaction:
    """
    Computes the union of sorted sets given by the specified `keys` and stores the result in `destination`.
    If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.

    Note:
        When in cluster mode, `destination` and all keys in `keys` must map to the same hash slot.

    see [valkey.io](https://valkey.io/commands/zunionstore/) for more details.

    Args:
        destination (TEncodable): The key of the destination sorted set.
        keys (Union[List[TEncodable], List[Tuple[TEncodable, float]]]): The keys of the sorted sets with possible formats:

            - List[TEncodable] - for keys only.
            - List[Tuple[TEncodable, float]] - for weighted keys with score multipliers.

        aggregation_type (Optional[AggregationType]): Specifies the aggregation strategy to apply
            when combining the scores of elements. See `AggregationType`.

    Command response:
        int: The number of elements in the resulting sorted set stored at `destination`.
    """
    args = _create_zinter_zunion_cmd_args(keys, aggregation_type, destination)
    return self.append_command(RequestType.ZUnionStore, args)