Tüm Ürünler
Search
Belge Merkezi

Tablestore:Use the atomic counter feature

Son Güncelleme:Oct 02, 2026

Çevrimiçi uygulamanız için bir sayaç uygulamak istiyorsanız atomik sayaç özelliğini kullanabilirsiniz. Bu özelliği kullanmak için bir sütunu atomik sayaç olarak ayarlayın ve bu sütunda atomik sayaç işlemleri gerçekleştirin.

Ön koşullar

Kullanım notları

  • Atomik sayaçları yalnızca INTEGER sütunlarında uygulayabilirsiniz.

  • Veri yazmadan önce atomik sayaç olarak belirtilen bir sütun yoksa sütunun varsayılan değeri 0 olur. Atomik sayaç olarak belirtilen sütun bir INTEGER sütunu değilse OTSParameterInvalid hatası oluşur.

  • Atomik sayacı pozitif veya negatif bir sayı kullanarak güncelleyebilirsiniz ancak tamsayı taşmasını önlemeniz gerekir. Tamsayı taşması meydana gelirse OTSParameterInvalid hatası döndürülür.

  • Varsayılan olarak bir satır güncelleme isteğine yanıtta atomik sayacın değeri döndürülmez. Atomik sayacın güncellenmiş değerinin döndürülmesini belirtebilirsiniz.

  • Tek bir güncelleme isteğinde bir sütunu hem atomik sayaç olarak belirtip hem de aynı sütunu güncelleyemezsiniz. Örneğin, A Sütunu'nu atomik sayaç olarak ayarlarsanız aynı anda üzerine yazma ve silme gibi diğer işlemleri gerçekleştiremezsiniz.

  • BatchWriteRow isteği göndererek aynı satırda birden çok güncelleme işlemi gerçekleştirebilirsiniz. Ancak bir satırda atomik sayaç işlemi gerçekleştiriyorsanız BatchWriteRow isteğinde o satır için yalnızca bir güncelleme işlemi yapabilirsiniz.

  • Yalnızca atomik sayacın en son sürümünün değeri güncellenebilir. Belirli bir sürümün değerini güncelleyemezsiniz. Güncelleme işlemi tamamlandığında satırdaki atomik sayaca yeni bir veri sürümü eklenir.

Sözdizimi

/**
 * Update a row of data. 
 * @api
 * @param [] $request The request parameters. 
 * @return [] The response. 
 * @throws OTSClientException The exception that is thrown if a parameter error occurs or the Tablestore server returns a verification error. 
 * @throws OTSServerException The exception that is thrown if the Tablestore server returns an error. 
 */
public function updateRow(array $request);         

Atomik sayaç işlemlerini gerçekleştirmek için updateRow yöntemini çağırın. Aşağıdaki tabloda desteklenen işlemler listelenmiştir.

İşlem

Açıklama

update_of_attribute_columns

Güncelleme türünü INCREMENT olarak ayarlayarak bir sütun değerini belirli bir tamsayı kadar artırın veya azaltın. Yapılandırma biçimi:

'update_of_attribute_columns'=> array(
    'INCREMENT' => array (     
        array('<column_name>', <value>, ColumnTypeConst::CONST_INTEGER), 
    ),
)

return_content

Güncellenen sütun değerini döndürür. Sütun adını belirtin ve return_type değerini ReturnTypeConst::CONST_AFTER_MODIFY olarak ayarlayın. Yapılandırma biçimi:

'return_content' => array(
            'return_type' => ReturnTypeConst::CONST_AFTER_MODIFY,
            'return_column_names' => array('<column_name>')
         )

Parametreler

Parametre

Açıklama

table_name

Tablonun adı.

column_name

Atomik sayaç işleminin uygulanacağı sütunun adı. Yalnızca INTEGER sütunları desteklenir.

value

Sütun değerinin artırılacağı veya azaltılacağı miktar.

return_content

Atomik sayaç işleminden sonra döndürülecek sütun bilgileri. Aşağıdaki parametreleri içerir:

  • return_type: Güncellenen sütun değerini döndürmek için ReturnTypeConst::CONST_AFTER_MODIFY olarak ayarlayın.

  • return_column_names: Güncellenmiş değeri döndürülecek sütunun adı.

Örnek

Aşağıdaki örnekte veri yazılırken bir INTEGER sütun değeri artırılır ve güncellenen değer döndürülür.

$request = array (
    // Specify the name of the table. 
    'table_name' => 'MyTable',
    // Set the row existence condition to RowExistenceExpectationConst::CONST_IGNORE, which specifies that the existence of rows is not checked. 
    'condition' => RowExistenceExpectationConst::CONST_IGNORE,
    // Specify the primary key. The number and types of primary key columns that you specify must be the same as the actual number and types of primary key columns in the table. 
    'primary_key' => array ( 
        // The name of the first primary key column is PK0, the data type is INTEGER, and the column value is 123. 
        array('PK0', 123),
        // The name of the second primary key column is PK1, the data type is STRING, and the column value is 'inc'. 
        array('PK1', 'inc')
    ),
    // The attribute column whose value is to be updated. Three operation types are supported: PUT, DELETE, and DELETE_ALL. 
    'update_of_attribute_columns'=> array(
        'INCREMENT' => array (     
            // Specify the column on which the atomic counter operation is to be performed. The column name is attr0, the increment in the column value is 1, and the data type is INTEGER. 
            array('attr0', 1, ColumnTypeConst::CONST_INTEGER), 
        ),
        'PUT' => array(
            array('attr1', 1, ColumnTypeConst::CONST_INTEGER),
        )
    ),
    // Return the column information after the atomic counter operation is performed. 
    'return_content' => array(
        'return_type' => ReturnTypeConst::CONST_AFTER_MODIFY,
        'return_column_names' => array('attr0')
    )
);
$response = $otsClient->updateRow ($request);
print json_encode ($response);