本文整理汇总了Java中io.lettuce.core.TransactionResult.get方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionResult.get方法的具体用法?Java TransactionResult.get怎么用?Java TransactionResult.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.lettuce.core.TransactionResult
的用法示例。
在下文中一共展示了TransactionResult.get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import io.lettuce.core.TransactionResult; //导入方法依赖的package包/类
/**
* Return the given key, if it is not expired.
*
* Time Complexity is 2*O(1).
*/
@Override
public cfData get( String key ) {
// Calculate the time now, represented as a decimal
long nowSecs = Instant.now().getMillis() / 1000;
double nowTtl = getDecimalTtl( nowSecs );
RedisFuture<TransactionResult> future = null;
TransactionResult transactionResult = null;
try {
if ( key == null ) {
throw new Exception( "'key' cannot be null" );
}
/*
* Atomic transaction (MULTI/EXEC) to check get the key and its ttl in one round.
*
* (see https://redis.io/commands/multi)
*/
asyncCommands.multi();
asyncCommands.zscore( ttls, key ); // Time complexity: O(1)
asyncCommands.hget( region, key ); // Time complexity: O(1)
future = asyncCommands.exec();
transactionResult = future.get( waitTimeSeconds, TimeUnit.SECONDS );
// Get the result of the 'ZSCORE' command, the TTL for the given key
Double keyTtl = transactionResult.get( 0 );
String base64value = null;
if ( keyTtl > nowTtl ) {
// Set the value to be returned, when the TTL is not expired
base64value = transactionResult.get( 1 );
}
return base64value == null ? null : (cfData) Transcoder.fromString( base64value );
} catch ( Exception e ) {
if ( cfEngine.thisPlatform != null ) {
cfEngine.log( getName() + " get Failed: " + e.getMessage() );
}
if ( future != null ) {
future.cancel( true );
}
}
return null;
}