syntax = "proto3";
package command_request;

enum SimpleRoutes {
    AllNodes=0;
    AllPrimaries=1;
    Random=2;
}

enum SlotTypes {
    Primary=0;
    Replica=1;
}

message SlotIdRoute {
    SlotTypes slot_type = 1;
    int32 slot_id = 2;
}

message SlotKeyRoute {
    SlotTypes slot_type = 1;
    string slot_key = 2;
}

message ByAddressRoute {
    string host = 1;
    int32 port = 2;
}

message Routes {
    oneof value {
        SimpleRoutes simple_routes = 1;
        SlotKeyRoute slot_key_route = 2;
        SlotIdRoute slot_id_route = 3;
        ByAddressRoute by_address_route = 4;
    }
}

enum RequestType {
    /// Invalid request type
    InvalidRequest                 = 0;
    /// An unknown command, where all arguments are defined by the user.
    CustomCommand                  = 1;

    //// Bitmap commands

    BitCount                       = 101;
    BitField                       = 102;
    BitFieldReadOnly               = 103;
    BitOp                          = 104;
    BitPos                         = 105;
    GetBit                         = 106;
    SetBit                         = 107;

    //// Cluster commands

    Asking                         = 201;
    ClusterAddSlots                = 202;
    ClusterAddSlotsRange           = 203;
    ClusterBumpEpoch               = 204;
    ClusterCountFailureReports     = 205;
    ClusterCountKeysInSlot         = 206;
    ClusterDelSlots                = 207;
    ClusterDelSlotsRange           = 208;
    ClusterFailover                = 209;
    ClusterFlushSlots              = 210;
    ClusterForget                  = 211;
    ClusterGetKeysInSlot           = 212;
    ClusterInfo                    = 213;
    ClusterKeySlot                 = 214;
    ClusterLinks                   = 215;
    ClusterMeet                    = 216;
    ClusterMyId                    = 217;
    ClusterMyShardId               = 218;
    ClusterNodes                   = 219;
    ClusterReplicas                = 220;
    ClusterReplicate               = 221;
    ClusterReset                   = 222;
    ClusterSaveConfig              = 223;
    ClusterSetConfigEpoch          = 224;
    ClusterSetslot                 = 225;
    ClusterShards                  = 226;
    ClusterSlaves                  = 227;
    ClusterSlots                   = 228;
    ReadOnly                       = 229;
    ReadWrite                      = 230;

    //// Connection Management commands

    Auth                           = 301;
    ClientCaching                  = 302;
    ClientGetName                  = 303;
    ClientGetRedir                 = 304;
    ClientId                       = 305;
    ClientInfo                     = 306;
    ClientKillSimple               = 307;
    ClientKill                     = 308;
    ClientList                     = 309;
    ClientNoEvict                  = 310;
    ClientNoTouch                  = 311;
    ClientPause                    = 312;
    ClientReply                    = 313;
    ClientSetInfo                  = 314;
    ClientSetName                  = 315;
    ClientTracking                 = 316;
    ClientTrackingInfo             = 317;
    ClientUnblock                  = 318;
    ClientUnpause                  = 319;
    Echo                           = 320;
    Hello                          = 321;
    Ping                           = 322;
    Quit                           = 323; // deprecated in 7.2.0
    Reset                          = 324;
    Select                         = 325;

    //// Generic commands

    Copy                           = 401;
    Del                            = 402;
    Dump                           = 403;
    Exists                         = 404;
    Expire                         = 405;
    ExpireAt                       = 406;
    ExpireTime                     = 407;
    Keys                           = 408;
    Migrate                        = 409;
    Move                           = 410;
    ObjectEncoding                 = 411;
    ObjectFreq                     = 412;
    ObjectIdleTime                 = 413;
    ObjectRefCount                 = 414;
    Persist                        = 415;
    PExpire                        = 416;
    PExpireAt                      = 417;
    PExpireTime                    = 418;
    PTTL                           = 419;
    RandomKey                      = 420;
    Rename                         = 421;
    RenameNX                       = 422;
    Restore                        = 423;
    Scan                           = 424;
    Sort                           = 425;
    SortReadOnly                   = 426;
    Touch                          = 427;
    TTL                            = 428;
    Type                           = 429;
    Unlink                         = 430;
    Wait                           = 431;
    WaitAof                        = 432;

    //// Geospatial indices commands

    GeoAdd                         = 501;
    GeoDist                        = 502;
    GeoHash                        = 503;
    GeoPos                         = 504;
    GeoRadius                      = 505;
    GeoRadiusReadOnly              = 506; // deprecated in 6.2.0
    GeoRadiusByMember              = 507;
    GeoRadiusByMemberReadOnly      = 508; // deprecated in 6.2.0
    GeoSearch                      = 509;
    GeoSearchStore                 = 510;

    //// Hash commands

    HDel                           = 601;
    HExists                        = 602;
    HGet                           = 603;
    HGetAll                        = 604;
    HIncrBy                        = 605;
    HIncrByFloat                   = 606;
    HKeys                          = 607;
    HLen                           = 608;
    HMGet                          = 609;
    HMSet                          = 610;
    HRandField                     = 611;
    HScan                          = 612;
    HSet                           = 613;
    HSetNX                         = 614;
    HStrlen                        = 615;
    HVals                          = 616;
    HSetEx                         = 617;
    HGetEx                         = 618;
    HExpire                        = 619;
    HExpireAt                      = 620;
    HPExpire                       = 621;
    HPExpireAt                     = 622;
    HPersist                       = 623;
    HTtl                           = 624;
    HPTtl                          = 625;
    HExpireTime                    = 626;
    HPExpireTime                   = 627;

    //// HyperLogLog commands

    PfAdd                          = 701;
    PfCount                        = 702;
    PfMerge                        = 703;

    //// List commands

    BLMove                         = 801;
    BLMPop                         = 802;
    BLPop                          = 803;
    BRPop                          = 804;
    BRPopLPush                     = 805; // deprecated in 6.2.0
    LIndex                         = 806;
    LInsert                        = 807;
    LLen                           = 808;
    LMove                          = 809;
    LMPop                          = 810;
    LPop                           = 811;
    LPos                           = 812;
    LPush                          = 813;
    LPushX                         = 814;
    LRange                         = 815;
    LRem                           = 816;
    LSet                           = 817;
    LTrim                          = 818;
    RPop                           = 819;
    RPopLPush                      = 820; // deprecated in 6.2.0
    RPush                          = 821;
    RPushX                         = 822;

    //// Pub/Sub commands (subscription commands are lazy variants)

    PSubscribe                     = 901;
    Publish                        = 902;
    PubSubChannels                 = 903;
    PubSubNumPat                   = 904;
    PubSubNumSub                   = 905;
    PubSubShardChannels            = 906;
    PubSubShardNumSub              = 907;
    PUnsubscribe                   = 908;
    SPublish                       = 909;
    SSubscribe                     = 910;
    Subscribe                      = 911;
    SUnsubscribe                   = 912;
    Unsubscribe                    = 913;

    // Dynamic Pub/Sub commands (Blocking variants)
    SubscribeBlocking              = 914;
    UnsubscribeBlocking            = 915;
    PSubscribeBlocking             = 916;
    PUnsubscribeBlocking           = 917;
    SSubscribeBlocking             = 918;
    SUnsubscribeBlocking           = 919;
    GetSubscriptions               = 920;

    //// Scripting and Functions commands

    Eval                           = 1001;
    EvalReadOnly                   = 1002;
    EvalSha                        = 1003;
    EvalShaReadOnly                = 1004;
    FCall                          = 1005;
    FCallReadOnly                  = 1006;
    FunctionDelete                 = 1007;
    FunctionDump                   = 1008;
    FunctionFlush                  = 1009;
    FunctionKill                   = 1010;
    FunctionList                   = 1011;
    FunctionLoad                   = 1012;
    FunctionRestore                = 1013;
    FunctionStats                  = 1014;
    ScriptDebug                    = 1015;
    ScriptExists                   = 1016;
    ScriptFlush                    = 1017;
    ScriptKill                     = 1018;
    ScriptLoad                     = 1019;
    ScriptShow                     = 1020;

    //// Server management commands

    AclCat                         = 1101;
    AclDelUser                     = 1102;
    AclDryRun                      = 1103;
    AclGenPass                     = 1104;
    AclGetUser                     = 1105;
    AclList                        = 1106;
    AclLoad                        = 1107;
    AclLog                         = 1108;
    AclSave                        = 1109;
    AclSetUser                     = 1110;
    AclUsers                       = 1111;
    AclWhoami                      = 1112;
    BgRewriteAof                   = 1113;
    BgSave                         = 1114;
    Command_                       = 1115; // Command - renamed to avoid collisions
    CommandCount                   = 1116;
    CommandDocs                    = 1117;
    CommandGetKeys                 = 1118;
    CommandGetKeysAndFlags         = 1119;
    CommandInfo                    = 1120;
    CommandList                    = 1121;
    ConfigGet                      = 1122;
    ConfigResetStat                = 1123;
    ConfigRewrite                  = 1124;
    ConfigSet                      = 1125;
    DBSize                         = 1126;
    FailOver                       = 1127;
    FlushAll                       = 1128;
    FlushDB                        = 1129;
    Info                           = 1130;
    LastSave                       = 1131;
    LatencyDoctor                  = 1132;
    LatencyGraph                   = 1133;
    LatencyHistogram               = 1134;
    LatencyHistory                 = 1135;
    LatencyLatest                  = 1136;
    LatencyReset                   = 1137;
    Lolwut                         = 1138;
    MemoryDoctor                   = 1139;
    MemoryMallocStats              = 1140;
    MemoryPurge                    = 1141;
    MemoryStats                    = 1142;
    MemoryUsage                    = 1143;
    ModuleList                     = 1144;
    ModuleLoad                     = 1145;
    ModuleLoadEx                   = 1146;
    ModuleUnload                   = 1147;
    Monitor                        = 1148;
    PSync                          = 1149;
    ReplConf                       = 1150;
    ReplicaOf                      = 1151;
    RestoreAsking                  = 1152;
    Role                           = 1153;
    Save                           = 1154;
    ShutDown                       = 1155;
    SlaveOf                        = 1156;
    SlowLogGet                     = 1157;
    SlowLogLen                     = 1158;
    SlowLogReset                   = 1159;
    SwapDb                         = 1160;
    Sync                           = 1161;
    Time                           = 1162;

    //// Set commands

    SAdd                           = 1201;
    SCard                          = 1202;
    SDiff                          = 1203;
    SDiffStore                     = 1204;
    SInter                         = 1205;
    SInterCard                     = 1206;
    SInterStore                    = 1207;
    SIsMember                      = 1208;
    SMembers                       = 1209;
    SMIsMember                     = 1210;
    SMove                          = 1211;
    SPop                           = 1212;
    SRandMember                    = 1213;
    SRem                           = 1214;
    SScan                          = 1215;
    SUnion                         = 1216;
    SUnionStore                    = 1217;

    //// Sorted set commands

    BZMPop                         = 1301;
    BZPopMax                       = 1302;
    BZPopMin                       = 1303;
    ZAdd                           = 1304;
    ZCard                          = 1305;
    ZCount                         = 1306;
    ZDiff                          = 1307;
    ZDiffStore                     = 1308;
    ZIncrBy                        = 1309;
    ZInter                         = 1310;
    ZInterCard                     = 1311;
    ZInterStore                    = 1312;
    ZLexCount                      = 1313;
    ZMPop                          = 1314;
    ZMScore                        = 1315;
    ZPopMax                        = 1316;
    ZPopMin                        = 1317;
    ZRandMember                    = 1318;
    ZRange                         = 1319;
    ZRangeByLex                    = 1320;
    ZRangeByScore                  = 1321;
    ZRangeStore                    = 1322;
    ZRank                          = 1323;
    ZRem                           = 1324;
    ZRemRangeByLex                 = 1325;
    ZRemRangeByRank                = 1326;
    ZRemRangeByScore               = 1327;
    ZRevRange                      = 1328;
    ZRevRangeByLex                 = 1329;
    ZRevRangeByScore               = 1330;
    ZRevRank                       = 1331;
    ZScan                          = 1332;
    ZScore                         = 1333;
    ZUnion                         = 1334;
    ZUnionStore                    = 1335;

    //// Stream commands

    XAck                           = 1401;
    XAdd                           = 1402;
    XAutoClaim                     = 1403;
    XClaim                         = 1404;
    XDel                           = 1405;
    XGroupCreate                   = 1406;
    XGroupCreateConsumer           = 1407;
    XGroupDelConsumer              = 1408;
    XGroupDestroy                  = 1409;
    XGroupSetId                    = 1410;
    XInfoConsumers                 = 1411;
    XInfoGroups                    = 1412;
    XInfoStream                    = 1413;
    XLen                           = 1414;
    XPending                       = 1415;
    XRange                         = 1416;
    XRead                          = 1417;
    XReadGroup                     = 1418;
    XRevRange                      = 1419;
    XSetId                         = 1420;
    XTrim                          = 1421;

    //// String commands

    Append                         = 1501;
    Decr                           = 1502;
    DecrBy                         = 1503;
    Get                            = 1504;
    GetDel                         = 1505;
    GetEx                          = 1506;
    GetRange                       = 1507;
    GetSet                         = 1508; // deprecated in 6.2.0
    Incr                           = 1509;
    IncrBy                         = 1510;
    IncrByFloat                    = 1511;
    LCS                            = 1512;
    MGet                           = 1513;
    MSet                           = 1514;
    MSetNX                         = 1515;
    PSetEx                         = 1516; // deprecated in 2.6.12
    Set                            = 1517;
    SetEx                          = 1518; // deprecated in 2.6.12
    SetNX                          = 1519; // deprecated in 2.6.12
    SetRange                       = 1520;
    Strlen                         = 1521;
    Substr                         = 1522;

    //// Transaction commands

    Discard                        = 1601;
    Exec                           = 1602;
    Multi                          = 1603;
    UnWatch                        = 1604;
    Watch                          = 1605;

    //// JSON commands

    JsonArrAppend                  = 2001;
    JsonArrIndex                   = 2002;
    JsonArrInsert                  = 2003;
    JsonArrLen                     = 2004;
    JsonArrPop                     = 2005;
    JsonArrTrim                    = 2006;
    JsonClear                      = 2007;
    JsonDebug                      = 2008;
    JsonDel                        = 2009;
    JsonForget                     = 2010;
    JsonGet                        = 2011;
    JsonMGet                       = 2012;
    JsonNumIncrBy                  = 2013;
    JsonNumMultBy                  = 2014;
    JsonObjKeys                    = 2015;
    JsonObjLen                     = 2016;
    JsonResp                       = 2017;
    JsonSet                        = 2018;
    JsonStrAppend                  = 2019;
    JsonStrLen                     = 2020;
    JsonToggle                     = 2021;
    JsonType                       = 2022;

    //// Vector Search commands

    FtList                         = 2101;
    FtAggregate                    = 2102;
    FtAliasAdd                     = 2103;
    FtAliasDel                     = 2104;
    FtAliasList                    = 2105;
    FtAliasUpdate                  = 2106;
    FtCreate                       = 2107;
    FtDropIndex                    = 2108;
    FtExplain                      = 2109;
    FtExplainCli                   = 2110;
    FtInfo                         = 2111;
    FtProfile                      = 2112;
    FtSearch                       = 2113;
}

message Command {
    message ArgsArray {
        repeated bytes args = 1;
    }

    RequestType request_type = 1;
    oneof args {
        ArgsArray args_array = 2;
        uint64 args_vec_pointer = 3;
    }
}

// Used for script requests with large keys or args vectors
message ScriptInvocationPointers {
    string hash = 1;
    optional uint64 keys_pointer = 2;
    optional uint64 args_pointer = 3;
}

message ScriptInvocation {
    string hash = 1;
    repeated bytes keys = 2;
    repeated bytes args = 3;
}

message Batch {
    bool is_atomic = 1;
    repeated Command commands = 2;
    optional bool raise_on_error = 3;
    optional uint32 timeout = 4;
    optional bool retry_server_error = 5;
    optional bool retry_connection_error = 6;
}

message ClusterScan {
    string cursor = 1;
    optional bytes match_pattern = 2;
    optional int64 count = 3;
    optional string object_type = 4;
    bool allow_non_covered_slots = 5;
}

message UpdateConnectionPassword {
    optional string password = 1;
    bool immediate_auth = 2;
}

message RefreshIamToken {
}

message CommandRequest {
    uint32 callback_idx = 1;

    oneof command {
        Command single_command = 2;
        Batch batch = 3;
        ScriptInvocation script_invocation = 4;
        ScriptInvocationPointers script_invocation_pointers = 5;
        ClusterScan cluster_scan = 6;
        UpdateConnectionPassword update_connection_password = 7;
        RefreshIamToken refresh_iam_token = 8;
    }
    Routes route = 9;
    optional uint64 root_span_ptr = 10;
}
