syntax = "proto2";
option go_package = "memcache";

package appengine;

message MemcacheServiceError {
  enum ErrorCode {
    OK = 0;
    UNSPECIFIED_ERROR = 1;
    NAMESPACE_NOT_SET = 2;
    PERMISSION_DENIED = 3;
    INVALID_VALUE = 6;
  }
}

message AppOverride {
  required string app_id = 1;

  optional int32 num_memcacheg_backends = 2 [deprecated=true];
  optional bool ignore_shardlock = 3 [deprecated=true];
  optional string memcache_pool_hint = 4 [deprecated=true];
  optional bytes memcache_sharding_strategy = 5 [deprecated=true];
}

message MemcacheGetRequest {
  repeated bytes key = 1;
  optional string name_space = 2 [default = ""];
  optional bool for_cas = 4;
  optional AppOverride override = 5;
}

message MemcacheGetResponse {
  repeated group Item = 1 {
    required bytes key = 2;
    required bytes value = 3;
    optional fixed32 flags = 4;
    optional fixed64 cas_id = 5;
    optional int32 expires_in_seconds = 6;
  }
}

message MemcacheSetRequest {
  enum SetPolicy {
    SET = 1;
    ADD = 2;
    REPLACE = 3;
    CAS = 4;
  }
  repeated group Item = 1 {
    required bytes key = 2;
    required bytes value = 3;

    optional fixed32 flags = 4;
    optional SetPolicy set_policy = 5 [default = SET];
    optional fixed32 expiration_time = 6 [default = 0];

    optional fixed64 cas_id = 8;
    optional bool for_cas = 9;
  }
  optional string name_space = 7 [default = ""];
  optional AppOverride override = 10;
}

message MemcacheSetResponse {
  enum SetStatusCode {
    STORED = 1;
    NOT_STORED = 2;
    ERROR = 3;
    EXISTS = 4;
  }
  repeated SetStatusCode set_status = 1;
}

message MemcacheDeleteRequest {
  repeated group Item = 1 {
    required bytes key = 2;
    optional fixed32 delete_time = 3 [default = 0];
  }
  optional string name_space = 4 [default = ""];
  optional AppOverride override = 5;
}

message MemcacheDeleteResponse {
  enum DeleteStatusCode {
    DELETED = 1;
    NOT_FOUND = 2;
  }
  repeated DeleteStatusCode delete_status = 1;
}

message MemcacheIncrementRequest {
  enum Direction {
    INCREMENT = 1;
    DECREMENT = 2;
  }
  required bytes key = 1;
  optional string name_space = 4 [default = ""];

  optional uint64 delta = 2 [default = 1];
  optional Direction direction = 3 [default = INCREMENT];

  optional uint64 initial_value = 5;
  optional fixed32 initial_flags = 6;
  optional AppOverride override = 7;
}

message MemcacheIncrementResponse {
  enum IncrementStatusCode {
    OK = 1;
    NOT_CHANGED = 2;
    ERROR = 3;
  }

  optional uint64 new_value = 1;
  optional IncrementStatusCode increment_status = 2;
}

message MemcacheBatchIncrementRequest {
  optional string name_space = 1 [default = ""];
  repeated MemcacheIncrementRequest item = 2;
  optional AppOverride override = 3;
}

message MemcacheBatchIncrementResponse {
  repeated MemcacheIncrementResponse item = 1;
}

message MemcacheFlushRequest {
  optional AppOverride override = 1;
}

message MemcacheFlushResponse {
}

message MemcacheStatsRequest {
  optional AppOverride override = 1;
}

message MergedNamespaceStats {
  required uint64 hits = 1;
  required uint64 misses = 2;
  required uint64 byte_hits = 3;

  required uint64 items = 4;
  required uint64 bytes = 5;

  required fixed32 oldest_item_age = 6;
}

message MemcacheStatsResponse {
  optional MergedNamespaceStats stats = 1;
}

message MemcacheGrabTailRequest {
  required int32 item_count = 1;
  optional string name_space = 2 [default = ""];
  optional AppOverride override = 3;
}

message MemcacheGrabTailResponse {
  repeated group Item = 1 {
    required bytes value = 2;
    optional fixed32 flags = 3;
  }
}
