[TDR Generic Table][Go SDK] Set TTL of Records

1. Interface Description

Set TTL of records

2. Version Requirements

SDK above 3.55.0

3. Preparations

Refer to Preparation document to complete the preparation before using this interface and create the following TDR Generic table. service_info table service_info.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<metalib name="service_info" tagsetversion="1" version="1">
  <struct name="service_info" version="1" primarykey="gameid,envdata,name,expansion" splittablekey="gameid" >
    <entry name="gameid"               type="string"     size="128" desc="gameapp id"/>
    <entry name="envdata"            type="string"     size="1024" desc="environment information"/>
    <entry name="name"            type="string"     size="1024" desc="name"/>
    <entry name="expansion"            type="string"   size="1024"           desc="expansion field"/>
    <entry name="filterdata"            type="string"     size="1024" desc="filter condition"/>
    <entry name="updatetime"           type="uint64"                  desc="latest update time, unit: ms"/>
    <entry name="inst_max_num"           type="uint64"                  desc="maximum number of instances"/>
    <entry name="inst_min_num"           type="uint64"                  desc="minimum number of instances"/>
    <entry name="routeinfo_len"      type="uint"     defaultvalue="0" desc="route information length" />
    <entry name="routeinfo"      type="char"     count="1024" refer="routeinfo_len" desc="route information length" />
    <index name="index_gameid_envdata_name" column="gameid,envdata,name" />
    <index name="index_gameid_envdata" column="gameid,envdata" />
    <index name="index_gameid_name" column="gameid,name" />
    <index name="index_gameid" column="gameid" />
  </struct>
</metalib>

Get the following information after the preparation. These details will be used by the SDK:

  1. Directory server address list
  2. App ID
  3. App access password
  4. Game zone ID
  5. Table name

4. Example Code

Basic execution process of example code:

  1. Define table configuration parameters
  2. Set log configuration;
  3. Create a client;
  4. Send a request and process the response;
  5. Destroy the client.

Example of client initialization:

package main

import (
  "fmt"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api"
)

// Define table configuration parameters
const (
  AppId                = uint64(2)
  ZoneId               = uint32(3)
  DirUrl               = "tcp://x.x.x.x:xxxx"
  Signature            = "xxxxxxxxxxxxx"
  TableName            = "service_info"
)

var client *tcaplus.Client

func main() {
  // Create a client
  client = tcaplus.NewClient()
  // Set log configuration and the log level in the logconf.xml file
  if err := client.SetLogCfg("./logconf.xml"); err != nil {
    fmt.Println(err.Error())
    return
  }

  // Connect to the TcaplusDB backend
  err := client.Dial(AppId, []uint32{ZoneId}, DirUrl, Signature, 60)
  if err != nil {
    fmt.Printf("init failed %v\n", err.Error())
    return
  }
  fmt.Printf("Dial finish\n")
  ttlExample()

  // Call Close to destroy the client when the program exits
  client.Close()
}

The synchronous call coding is the simplest, and it can be implemented through multiple concurrent processes. Example Directory

package main

import (
  "fmt"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/example/TDR/async/service_info"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/protocol/option"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/record"
)

func ttlExample() {
  //Apply for a tdr structure and assign the Key value. It is preferable to use the NewXXX function of the tdr pkg, which sets the members to the tdr default value defined by tdr.
  // Do not create new structures by yourself; otherwise, there is a risk of panic if some structures are not initialized
  data := service_info.NewService_Info()
  data.Gameid = "dev"
  data.Envdata = "oa"
  data.Name = "com"

  ////2 set ttl, that is, it expires in 5 seconds
  opt := &option.TDROpt{
    BatchTTL: []option.TTLInfo{{TTL: 5000}},
  }
  dataSlice := []record.TdrTableSt{data}
  err := client.DoSetTTLBatch(TableName, dataSlice, nil, opt)
  if err != nil {
    fmt.Println(err.Error())
    return
  }
  fmt.Println("ttl success")
}

The synchronous call mode of this example is similar to that of the C++ interface, and the request needs to be created and the response needs to be parsed. Example Directory

package main

import (
  "fmt"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/example/TDR/async/service_info"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/protocol/cmd"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/terror"
  "strconv"
  "time"
)

func setTtlExample() {
  //Create a request
  req, err := client.NewRequest(ZoneId, TableName, cmd.TcaplusApiSetTtlReq)
  if err != nil {
    fmt.Printf("NewRequest  failed %v\n", err.Error())
    return
  }

  for i:=0; i < 10; i++ {
    //Add a record for the request, up to 1024
    rec, err := req.AddRecord(0)
    if err != nil {
      fmt.Printf("AddRecord failed %v\n", err.Error())
      return
    }
    //Apply for a tdr structure and assign the Key value. It is preferable to use the NewXXX function of the tdr pkg, which sets the members to the tdr default value defined by tdr.
    // Do not create new structures by yourself; otherwise, there is a risk of panic if some structures are not initialized
    data := service_info.NewService_Info()
    data.Gameid = "dev"
    data.Envdata = fmt.Sprintf("%d", i)
    data.Name = "com"
    if err := rec.SetData(data); err != nil {
      fmt.Printf("SetData failed %v\n", err.Error())
      return
    }
    // Expires in 5 seconds
    rec.SetTTL(5000, false)
  }
  req.SetResultFlagForSuccess(2)

  respList, err := client.DoMore(req, time.Duration(10*time.Second))
  if err != nil {
    fmt.Printf("recv err %s\n", err.Error())

  }
  var totalCnt int = 0
  for _, resp := range respList {
    tcapluserr := resp.GetResult()
    if tcapluserr != 0 {
      fmt.Printf("response ret %s\n",
        "errCode: "+strconv.Itoa(tcapluserr)+", errMsg: "+terror.ErrorCodes[tcapluserr])
      break
    }
    totalCnt += resp.GetRecordCount()
    record, err := resp.FetchRecord()
    if err != nil {
      fmt.Printf("FetchRecord failed %s\n", err.Error())
      return
    }
    //Get records through GetData
    data := service_info.NewService_Info()
    if err := record.GetData(data); err != nil {
      fmt.Printf("record.GetData failed %s\n", err.Error())
      return
    }
    fmt.Printf("response record data %+v, route: %s\n",
      data, string(data.Routeinfo[0:data.Routeinfo_Len]))
  }
  fmt.Printf("total count %d,\n", totalCnt)
}

Asynchronous sending can use fewer processes to achieve greater concurrency. The coding is relatively complex. Example Directory

package main

import (
  "fmt"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/example/TDR/async/service_info"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/logger"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/protocol/cmd"
  "git.woa.com/gcloud_storage_group/tcaplus-go-api/terror"
  "strconv"
  "sync"
  "time"
)

func setttlExample() {
  wg := sync.WaitGroup{}
  wg.Add(1)
  // Process the response message in another coroutine
  go func() {
    defer wg.Done()
    for {
      // If resp and err are both nil, there is no response in the response pool
      resp, err := client.RecvResponse()
      if err != nil {
        logger.ERR("RecvResponse error:%s", err)
        continue
      } else if resp == nil {
        time.Sleep(time.Microsecond * 5)
        continue
      }

      //Bring back the asynchronous ID of the request
      fmt.Printf("resp success, AsyncId:%d\n", resp.GetAsyncId())
      tcapluserr := resp.GetResult()
      if tcapluserr != 0 {
        fmt.Printf("response ret %s\n",
          "errCode: "+strconv.Itoa(tcapluserr)+", errMsg: "+terror.ErrorCodes[tcapluserr])
        return
      }
      //The response contains the obtained record
      fmt.Printf("response success record count %d\n", resp.GetRecordCount())
      for i := 0; i < resp.GetRecordCount(); i++ {
        record, err := resp.FetchRecord()
        if err != nil {
          fmt.Printf("FetchRecord failed %s\n", err.Error())
          return
        }
        //Get records through GetData
        data := service_info.NewService_Info()
        if err := record.GetData(data); err != nil {
          fmt.Printf("record.GetData failed %s\n", err.Error())
          return
        }
        fmt.Printf("response record data %+v, route: %s\n",
          data, string(data.Routeinfo[0:data.Routeinfo_Len]))
      }
      //Judge whether there are split packages
      if 1 == resp.HaveMoreResPkgs() {
        continue
      }
      return
    }
  }()
  //Create a request
  req, err := client.NewRequest(ZoneId, TableName, cmd.TcaplusApiSetTtlReq)
  if err != nil {
    fmt.Printf(" NewRequest failed %v\n", err.Error())
    return
  }
  //Allow package splitting
  req.SetMultiResponseFlag(1)
  req.SetResultFlagForSuccess(2)

  for i:=0; i < 10; i++ {
    //Add a record for the request, up to 1024
    rec, err := req.AddRecord(0)
    if err != nil {
      fmt.Printf(" AddRecord failed %v\n", err.Error())
      return
    }
    //Apply for a tdr structure and assign the Key value. It is preferable to use the NewXXX function of the tdr pkg, which sets the members to the tdr default value defined by tdr.
    // Do not create new structures by yourself; otherwise, there is a risk of panic if some structures are not initialized
    data := service_info.NewService_Info()
    data.Gameid = "dev"
    data.Envdata = fmt.Sprintf("%d", i)
    data.Name = "com"
    if err := rec.SetData(data); err != nil {
      fmt.Printf("SetData failed %v\n", err.Error())
      return
    }
    rec.SetTTL(5000, false)
  }

  //Send a request
  if err := client.SendRequest(req); err != nil {
    fmt.Printf("SendRequest failed %v\n", err.Error())
    return
  }
  wg.Wait()
}

5. Method Description in Request Object

Note: Other methods of the request object are not listed here, which means that this method is not required in the scenario of querying data. Misuse may result in errors.

/**
  @brief: add a record to the request.
  @param [IN] index: used for List operations, and it is usually >=0, indicating the Index of the Record in the List.
                            For Generic operations, the index is meaningless, just set 0
  @retval record.Record: return the record pointer
  @retval error: error code
**/
AddRecord(index int32) (*record.Record, error)

/**
@brief: set the asynchronous transaction ID of the request, and the API will bring its value back through the response message unchanged
@param  [IN] asyncId: asynchronous transaction ID of the request
**/
SetAsyncId(id uint64)

/**
@brief: set the general flag bit of the request. Multiple values can be set at the same time through the "bit or" operation
@param  [IN]  flag: value of the request flag bit
@retval 0: setting successful
@retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
@note: valid flag bits include:
*  TCAPLUS_FLAG_FETCH_ONLY_IF_MODIFIED:
*      "Fetch only if modified" flag bit: Before starting a read operation, the user code carries the version number of the locally buffered data through TcaplusServiceRecord::SetVersion()
*      and sets this flag. When the storage end detects that the current data is consistent with the API buffered data version,
*      it indicates that the record has not been modified and that the API buffered data is the latest. As a result, it will not return the actual data,
*      but only the error code of TcapErrCode::COMMON_INFO_DATA_NOT_MODIFIED
*
*      After this flag bit is set in the request, the response should first be received through TcaplusServiceResponse::GetFlags() to find out
*      whether the TCAPLUS_FLAG_FETCH_ONLY_IF_MODIFIED flag was set when sending the request.
*
*      Only the following requests support setting this flag:
*           TCAPLUS_API_GET_REQ,
*           TCAPLUS_API_LIST_GET_REQ,
*           TCAPLUS_API_LIST_GETALL_REQ
*
*  TCAPLUS_FLAG_FETCH_ONLY_IF_EXPIRED:
*      "Fetch only if expired" flag bit: Before starting a read operation, the user code sets the data expiration time through SetExpireTime(),
*      and set this flag. When the storage end detects that the record has been updated within the specified time, it will return the data.
*      Otherwise, it will not return the actual data, but only the error code of TcapErrCode::COMMON_INFO_DATA_NOT_MODIFIED.
*
*      After this flag bit is set in the request, the response should first be received through TcaplusServiceResponse::GetFlags() to find out
*      whether the TCAPLUS_FLAG_FETCH_ONLY_IF_EXPIRED flag was set when sending the request.
*
*      Only the following requests support setting this flag:
*           TCAPLUS_API_BATCH_GET_REQ
*
*  TCAPLUS_FLAG_ONLY_READ_FROM_SLAVE
*      After setting this flag, the read request will be directly sent to the Tcapsvr Slave node.
*      Tcapsvr Slave is usually relatively idle. Setting this flag helps to fully utilize Tcapsvr Slave resources.
*
*      Applicable scenarios:
*                              read requests that do not require high data timeliness,
*                              including all read requests for the generic table and list table, as well as batch get and traversal requests
*
*  TCAPLUS_FLAG_LIST_RESERVE_INDEX_HAVING_NO_ELEMENTS
*       After setting this flag, the index and version need to be retained when deleting the last element in the List table.
*       The ListDelete, ListDeleteBatch and ListDeleteAll operations set this flag when deleting the last element of the list table.
*       When writing a new List record, the version number will increase and not be reset to 1.
*
*      Applicable scenarios:
*                              app that needs to determine whether a table needs to retain index and version when deleting the last element.
*                              Mainly involves the use experience of the List table
*
*/
SetFlags(flag int32) int

/**
  @brief: clear the general flag bit of the request. Multiple values can be set at the same time through the "bit or" operation
  @param  [IN]  flag: value of the request flag bit
  @retval 0: setting successful
  @retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.
  @note: for a list of valid flag bits and a detailed explanation, please refer to SetFlags()
*/
ClearFlags(flag int32) int

/**
  @brief: get the general flag bit of the request
  @return: return the general flag bit of the request
  @note: for a list of valid flag bits and a detailed explanation, please refer to SetFlags()
*/
GetFlags() int32

/**
  @brief: set the name list of the Value fields for getting or updating, that is, getting and updating part Value fields, which can be used for get, replace, and update operations.
  @param [IN] valueNameList: list of field names that need to be queried or updated
  @retval error: error code
  @note: when using this function to set a field name, the field name can only contain the value field name the key field name, not
              The refer field and array field should be set at the same time or not at the same time, otherwise there may be data confusion
**/
SetFieldNames(valueNameList []string) error

/**
@brief: set the user buffer, which is carried back by the response
@param [IN] userBuffer: user buffer
@retval error: error code
**/
SetUserBuff(userBuffer []byte) error

/**
@brief: set the check type of record version for optimistic locking
@param [IN] type: version detection type, values can be:
                    CheckDataVersionAutoIncrease: it means that the record version number is to be checked, only when the parameter passed into the record.SetVersion function
                        Only when the value of version passed by the record.SetVersion function is > 0, and its version number is the same as that of the server side, the request succeeds and the version number of the server will increase by 1.
                        If the version of record.SetVersion is <= 0, it still means that the version number is not important
                    NoCheckDataVersionOverwrite: it means that the record version number is not checked.
                        When the value of version passed by the record.SetVersion function is > 0, overwrite the version number of the server;
                        If the version of record.SetVersion is <= 0, it still means that the version number is not important
                     NoCheckDataVersionAutoIncrease: It means that the record version number is not checked, and the version number on the server side will increase by 1.
                        If the server side newly writes a data record, the newly written data record version number is 1.
@retval error: error code
@note: this function is suitable for Replace, Update operations
**/
SetVersionPolicy(p uint8) error

/**
@brief:  set the result flag. It is mainly used for inserting, increasing, replacing, updating, deleting Generic tables.
@param  [IN]  flag: request flag:
                        0 means: return whether the operation was successfully executed
                        1 means: operation successful and return the data same with the request
                        2 means: operation successful and return the latest data for all fields in the modified record
                        3 means: operation successful and return the old data for all fields in the modified record
@retval error: error code
NOTE: SetResultFlag is not accurate for some scenarios due to historical reasons. It is recommended to use SetResultFlagForSuccess
**/
SetResultFlag(flag int) error

/**
    @brief: set the result flag. It mainly refers to the data returned to the front-end after the successful execution of this request

    The value range of result_flag is as follows:

 TCaplusValueFlag_NOVALUE = 0,              // Do not return any return value
 TCaplusValueFlag_SAMEWITHREQUEST = 1,      // Return the value consistent with the request
 TCaplusValueFlag_ALLVALUE = 2,           // Return the value of all fields after the tcapsvr operation
 TCaplusValueFlag_ALLOLDVALUE = 3,          // Return the value of all fields before the tcapsvr operation


The following are the details of the data returned to the API side after successful execution of each supported command word with different results set:

 1. TCAPLUS_API_INSERT_REQ TCAPLUS_API_BATCH_INSERT_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
     If TCaplusValueFlag_ALLVALUE is set, return the data after this insert operation after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return null data after successful operation

 2. TCAPLUS_API_REPLACE_REQ TCAPLUS_API_BATCH_REPLACE_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
     If TCaplusValueFlag_ALLVALUE is set, return the data after this replace operation after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. If there is no data on tcapsvr, return null data

 3. TCAPLUS_API_UPDATE_REQ TCAPLUS_API_BATCH_UPDATE_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
     If TCaplusValueFlag_ALLVALUE is set, return the data after this update operation after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation

 4. TCAPLUS_API_INCREASE_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
     If TCaplusValueFlag_ALLVALUE is set, return the data after this increase operation after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. If there is no data on tcapsvr, return null data

 5. TCAPLUS_API_DELETE_REQ TCAPLUS_API_BATCH_DELETE_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
     If TCaplusValueFlag_ALLVALUE is set, return null data after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation

 6. TCAPLUS_API_LIST_DELETE_BATCH_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
     If TCaplusValueFlag_ALLVALUE is set, return no data after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. All data corresponding to the index successfully deleted this time will be returned

 7. TCAPLUS_API_LIST_ADDAFTER_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
     If TCaplusValueFlag_ALLVALUE is set, return the records inserted this time and the records expired this time after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return no value after successful operation

 8. TCAPLUS_API_LIST_DELETE_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
     If TCaplusValueFlag_ALLVALUE is set, return null data after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the listdelete operation on tcapsvr after successful operation

 9. TCAPLUS_API_LIST_REPLACE_REQ
     If TCaplusValueFlag_NOVALUE is set, return no value after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation, but has not yet been realized.
     If TCaplusValueFlag_ALLVALUE is set, return the data after the listreplace operation on tcapsvr after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the listreplace operation on tcapsvr after successful operation
10. TCAPLUS_API_LIST_REPLACE_BATCH_REQ
     If TCaplusValueFlag_NOVALUE is set, return the data same with the request after successful operation
     If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after successful operation
     If TCaplusValueFlag_ALLVALUE is set, return the data after the listreplace operation on tcapsvr after successful operation
     If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the listreplace operation on tcapsvr after successful operation

 @param  [IN] result_flag request flag:
                             0 means: return whether the operation was successfully executed
                             1 means: return the data same with the request
                             2 means: return the latest data for all fields in the modified record
                             3 means: return the old data for all fields in the modified record

                             For batch_get requests, when this field is set to greater than 0, the corresponding key will be returned when a key query record does not exist or there are other errors generated by the svr side,
                             so as to know which key corresponding record failed
 @retval 0: setting successful
 @retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.

*/
SetResultFlagForSuccess(result_flag byte) int

/**
    @brief: set the result flag. It mainly refers to the data returned to the front-end after the failed execution of this request

    The value range of result_flag is as follows:

    TCaplusValueFlag_NOVALUE = 0,             // Do not return any return value
    TCaplusValueFlag_SAMEWITHREQUEST = 1,     // Return the value consistent with the request
    TCaplusValueFlag_ALLVALUE = 2,             // Return the value of all fields after the tcapsvr operation
    TCaplusValueFlag_ALLOLDVALUE = 3,         // Return the value of all fields before the tcapsvr operation


   The following are the details of the data returned to the API side after the failed execution of each supported command word with different results set:

    1. TCAPLUS_API_INSERT_REQ  TCAPLUS_API_BATCH_INSERT_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side

    2. TCAPLUS_API_REPLACE_REQ  TCAPLUS_API_BATCH_REPLACE_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side

    3. TCAPLUS_API_UPDATE_REQ  TCAPLUS_API_BATCH_UPDATE_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side

    4. TCAPLUS_API_INCREASE_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side

    5. TCAPLUS_API_DELETE_REQ TCAPLUS_API_BATCH_DELETE_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side

    6. TCAPLUS_API_LIST_DELETE_BATCH_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data before the operation on tcapsvr after successful operation. All data corresponding to the index successfully deleted this time will be returned

    7. TCAPLUS_API_LIST_ADDAFTER_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return no value

    8. TCAPLUS_API_LIST_DELETE_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side

    9. TCAPLUS_API_LIST_REPLACE_REQ
        If TCaplusValueFlag_NOVALUE is set, return no value after failed operation
        If TCaplusValueFlag_SAMEWITHREQUEST is set, return the data same with the request after failed operation, but has not yet been realized.
        If TCaplusValueFlag_ALLVALUE is set, it is an unreasonable scenario
        If TCaplusValueFlag_ALLOLDVALUE is set, return the data if getting data from the tcapsvr side, and return the null data if not getting data from the tcapsvr side

    @param  [IN] result_flag request flag:
                                0 means: return whether the operation was successfully executed
                                1 means: return the data same with the request
                                2 means: return the latest data for all fields in the modified record
                                3 means: return the old data for all fields in the modified record

                                For batch_get requests, when this field is set to greater than 0, the corresponding key will be returned when a key query record does not exist or there are other errors generated by the svr side,
                                so as to know which key corresponding record failed
    @retval 0: setting successful
    @retval < 0 failed and returned the corresponding error code. Usually because it is not initialized.

*/
SetResultFlagForFail(result_flag byte) int

6. Method Description in Response Object

Note: Other methods of response object are not listed here, which means that this method is not required in the scenario of querying data. Misuse may result in errors.

/*
    @brief: get the result
    @retval int tcaplus api: user-defined error code 0 means the request was successful; non-0 means error codes, which can be got from terror.GetErrMsg(int)
*/
GetResult() int

/*
    @brief: get the result table Name
    @retval string: table name of the result message
*/
GetTableName() string

/*
    @brief: get the result appId
    @retval uint64: appId of the result message
*/
GetAppId() uint64

/*
    @brief: get the result zoneId
    @retval uint32: zoneId of the result message
*/
GetZoneId() uint32

/*
    @brief: get the result command word
    @retval int: result message command word, the response command word in the cmd package
*/
GetCmd() int

/*
    @brief: get the result asynchronous ID corresponding to the request
    @retval uint64: asynchronous ID of the result message, corresponding to the request
*/
GetAsyncId() uint64

/*
    @brief: get the number of result records in this response
    @retval int: the number of result records in this response
*/
GetRecordCount() int

/*
    @brief: get a record from the result
    @retval * record.Record: record pointer
    @retval error: error code
*/
FetchRecord() (*record.Record, error)

/*
    @brief: get the user buffer information in the response
    @retval []byte: user buffer binary, consistent with the buffer value in the request message
*/
GetUserBuffer() []byte

7. Method Description in Record Object

Note: Other methods of response object are not listed here, which means that this method is not required in the scenario of querying data. Misuse may result in errors.

  • Common method of record:
/**
    @brief: get the record version number
    @retval: record version number
    @note: For the Generic operation, it means getting the version of the Record; whereas for the List operation, it means getting the version of the List in which the Record is located.
**/
func (r *Record) GetVersion() int32   

/**
      @brief: set the version number of the record
      @param [IN] v: version number of the record  <=0: it means that the version number is not important. The specific meaning is as follows.
                  When it is CHECKDATAVERSION_AUTOINCREASE: it means that the record version number is to be checked.
                      If the Version value is <= 0, it still means that the version number is not important;
                      if the Version value is > 0, only when its version number is the same as that of the server side,
                      the Replace, Update, Increase, ListAddAfter, ListDelete, ListReplace, ListDeleteBatch operations succeed and the version number of the server will increase by 1.
                  When it is NOCHECKDATAVERSION_OVERWRITE: it means that the record version number is not checked.
                      If the Version value is <=0, write the version number 1 to the data record version number on the server side (the version number of the data record successfully written on the server side is at least 1);
                      if the Version value is > 0, write the version number to the data record version number on the server side.
                  When it is NOCHECKDATAVERSION_AUTOINCREASE: It means that the record version number is not checked, and the version number on the server side will increase by 1. If the server side newly writes a data record, the newly written data record version number is 1.
  **/
func (r *Record) SetVersion(v int32)

/**
  @brief: set the record TTL, or expiration time, that is, how long after the record expires. Expired records will not be accessed
  @param [IN] ttl: time to live (expiration time), in milliseconds. If it is a relative time, for example, if the parameter value is 10, it means that the record will expire after 10ms. And if the parameter value is 0, it means that the record will never expire
                                                     If it is an absolute time, for example, 1599105600000, it means that the record will expire after 20200903 12:00:00. If the value is 0, it means that the record will never expire
  @param [IN] is_absolute_time: whether the time type is absolute time. True means absolute time, while false means relative time. The default is false, which means relative time
  @retval 0: setting successful
  @retval non-0: setting failed. For specific errors, see \link ErrorCode \endlink
  @note: this function currently only supports the TCAPLUS_API_SET_TTL_REQ response
  @note: the ttl value set cannot exceed half of the maximum value of uint64_t, that is, the maximum value of ttl is ULONG_MAX/2. If it exceeds this value, the interface will be forced to set it to this value
  @note   The request to set the ttl will not increase the record version number on the server side
  @note: for a list table, when all records of a key are deleted due to expiration, the index records will be directly deleted as well
  @note: for a record with TTL set, if it is a getbypartkey query and only needs to return the key field (that is, it does not need to return the value field), it will not check whether the record is expired.
  @note: for delete operations (generic and list table deletions), records are not checked for expiration
*/
func (r *Record) SetTTL(ttl uint64, isAbsoluteTime bool) int

/**
    @brief: getttl method that get the expiration time
    @param [IN] ttl: in ms
    @retval error: error code
**/
func (r *Record) GetTTL(ttl *uint64) int
  • Record can be set and extracted based on TDR structure
 /**
@brief: set the record data based on the TDR description
@param [IN] data: record interface data based on the TDR description. The xml of tdr is a go structure generated by the tool, including a series of methods of the TdrTableSt interface
@retval error: error code
*/
func (r *Record) SetData(data TdrTableSt) error

/**
    @brief: get the record data based on the TDR description
    @param [IN] data: record interface data based on the TDR description. The xml of tdr is a go structure generated by the tool, including a series of methods of the TdrTableSt interface
    @retval error: error code
**/
func (r *Record) GetData(data TdrTableSt) error
  • Record also supports the SetKey and SetValue interfaces for setting record fields and the GetKey and GetValue interfaces for fetching record fields. However, SetKey, SetValue, GetKey, and GetValue cannot be used with the SetData and GetData interfaces
    1. The data set by the SetKey SetValue interface can only be read through the GetKey and GetValue interfaces,When using the batch command for the SetKey SetValue interface, you should pay attention to that after the record setting is completed, you can call Pack () to package the records; SetData is one-time, and function calls will be automatically packaged. SetKey SetValue is not sure when the user has set the last field, so the user needs to call Pack () to package the records after setting kv
    2. The data set by the SetData interface can only be read through GetData
/**
  @brief: key field value setting
  @param  [in] name: field name, the maximum length of each field name is 32
  @param  [in] data: field value
  @retval error: error code
*/
func (r *Record) SetKeyInt8(name string, data int8) error
func (r *Record) SetKeyInt16(name string, data int16) error
func (r *Record) SetKeyInt32(name string, data int32) error
func (r *Record) SetKeyInt64(name string, data int64) error
func (r *Record) SetKeyFloat32(name string, data float32) error
func (r *Record) SetKeyFloat64(name string, data float64) error
func (r *Record) SetKeyStr(name string, data string) error
func (r *Record) SetKeyBlob(name string, data []byte) error

/**
  @brief: value field value setting
  @param  [in] name: field name, the maximum length of each field name is 32
  @param  [in] data: field value
  @retval error: error code
*/
func (r *Record) SetValueInt8(name string, data int8) error
func (r *Record) SetValueInt16(name string, data int16) error
func (r *Record) SetValueInt32(name string, data int32) error
func (r *Record) SetValueInt64(name string, data int64) error
func (r *Record) SetValueFloat32(name string, data float32) error
func (r *Record) SetValueFloat64(name string, data float64) error
func (r *Record) SetValueStr(name string, data string) error
func (r *Record) SetValueBlob(name string, data []byte) error

/**
  @brief: key field value getting
  @param  [in] name: field name, the maximum length of each field name is 32
  @retval data: field value
  @retval error: error code
*/
func (r *Record) GetKeyInt8(name string) (int8, error)
func (r *Record) GetKeyInt16(name string) (int16, error)
func (r *Record) GetKeyInt32(name string) (int32, error)
func (r *Record) GetKeyInt64(name string) (int64, error)
func (r *Record) GetKeyFloat32(name string) (float32, error)
func (r *Record) GetKeyFloat64(name string) (float64, error)
func (r *Record) GetKeyStr(name string) (string, error)
func (r *Record) GetKeyBlob(name string) ([]byte, error)

/**
  @brief: value field value getting
  @param  [in] name: field name, the maximum length of each field name is 32
  @retval data: field value
  @retval error: error code
*/
func (r *Record) GetValueInt8(name string) (int8, error)
func (r *Record) GetValueInt16(name string) (int16, error)
func (r *Record) GetValueInt32(name string) (int32, error)
func (r *Record) GetValueInt64(name string) (int64, error)
func (r *Record) GetValueFloat32(name string) (float32, error)
func (r *Record) GetValueFloat64(name string) (float64, error)
func (r *Record) GetValueStr(name string) (string, error)
func (r *Record) GetValueBlob(name string) ([]byte, error)

8. FAQ

For details, see Meaning and Handling of Error Codes.

8. Other Reference Documents

[[TDR Generic Table] [C++ SDK] Interface Description for Setting Record Expiration](../../01C++_SDK/02Interface_Documents/15[Generic_Table]Set_Record_Expiration.md

[[TDR Generic Table] [MySQL Protocol Compatibility Interface] TTL Interface Description](../../04MySQL_Protocol_Compatibility_Interface/02Syntax_Description/08[Generic_Table]TTL.md

results matching ""

    No results matching ""