当前位置: 首页>>代码示例>>Java>>正文


Java TransactionResult类代码示例

本文整理汇总了Java中io.lettuce.core.TransactionResult的典型用法代码示例。如果您正苦于以下问题:Java TransactionResult类的具体用法?Java TransactionResult怎么用?Java TransactionResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TransactionResult类属于io.lettuce.core包,在下文中一共展示了TransactionResult类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exec

import io.lettuce.core.TransactionResult; //导入依赖的package包/类
@Override
public TransactionResult exec() {
  Span span = helper.buildSpan("exec");
  try {
    return commands.exec();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-redis-client,代码行数:13,代码来源:TracingRedisCommands.java

示例2: deleteAll

import io.lettuce.core.TransactionResult; //导入依赖的package包/类
/**
 * Delete all the keys in the region data store, and its respective TTLs.
 * 
 * Time Complexity is O(2N), where N is the number of keys in the region.
 * This N is multiplied by 2 since there are N ttls for N keys.
 */
@Override
public void deleteAll() {

	RedisFuture<TransactionResult> future = null;
	try {

		/*
		 * Atomic transaction (MULTI/EXEC) to delete the data store for the region,
		 * and the respective ttls data store.
		 * 
		 * (see https://redis.io/commands/multi)
		 */
		asyncCommands.multi();
		asyncCommands.del( region );
		asyncCommands.del( ttls );
		future = asyncCommands.exec();
		future.get( waitTimeSeconds, TimeUnit.SECONDS );


	} catch ( Exception e ) {
		if ( cfEngine.thisPlatform != null ) {
			cfEngine.log( getName() + " deleteAllFailed: " + e.getMessage() );
		}
		if ( future != null ) {
			future.cancel( false );
		}
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:35,代码来源:RedisCacheImpl.java

示例3: deleteExactTrue

import io.lettuce.core.TransactionResult; //导入依赖的package包/类
private void deleteExactTrue( String key ) {

		RedisFuture<TransactionResult> futureDel = null;

		try {

			/*
			 * Atomic transaction (MULTI/EXEC) to delete the key from the region data store,
			 * and the respective ttl from the ttls data store for this region.
			 * 
			 * (see https://redis.io/commands/multi)
			 */
			asyncCommands.multi();
			asyncCommands.zrem( ttls, key );
			asyncCommands.hdel( region, key );
			futureDel = asyncCommands.exec();
			futureDel.get( waitTimeSeconds, TimeUnit.SECONDS );

		} catch ( Exception e ) {
			if ( cfEngine.thisPlatform != null ) {
				cfEngine.log( getName() + " deleteExactFalse: " + e.getMessage() );
			}
			if ( futureDel != null ) {
				futureDel.cancel( false );
			}
		}

	}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:29,代码来源:RedisCacheImpl.java

示例4: exec

import io.lettuce.core.TransactionResult; //导入依赖的package包/类
@Override
public RedisFuture<TransactionResult> exec() {
  Span span = helper.buildSpan("exec");
  return setCompleteAction(commands.exec(), span);
}
 
开发者ID:opentracing-contrib,项目名称:java-redis-client,代码行数:6,代码来源:TracingRedisAsyncCommands.java

示例5: 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;
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:52,代码来源:RedisCacheImpl.java

示例6: set

import io.lettuce.core.TransactionResult; //导入依赖的package包/类
/**
 * Set the given key and value in the region for this cache instance,
 * with the given time-to-live, i.e. ageMS.
 * 
 * Time Complexity is O(1) to set the key-value pair and O(log(N) to set the tll for the key,
 * where N is the number of the keys in this region.
 * 
 * @param key
 *          the given key.
 * @param data
 *          the value for this key.
 * @param ageMS
 *          the ttl for this key-value pair. If ageMS < 1 || ageMs > dayMs, then ageMS = dayMs.
 * @param idleTime
 *          not used in this implementation.
 */
@Override
public void set( String key, cfData data, long ageMS, long idleTime ) {

	// Convert the ageMs, tll in milliseconds, to ageSecs, ttl in seconds.
	long ageSecs;
	if ( ageMS < 1 || ageMS > DAY_MS ) {
		ageSecs = DAY_MS / 1000;
	} else {
		ageSecs = ageMS / 1000;
	}

	// Get the time now in seconds plus the ageSecs in seconds
	long nowSecs = Instant.now().getMillis() / 1000 + ageSecs;

	// Convert the time now in seconds to a decimal
	double ttl = getDecimalTtl( nowSecs );

	RedisFuture<TransactionResult> future = null;
	RedisFuture<Boolean> futureHset = null;
	RedisFuture<Long> futureZadd = null;

	try {
		if ( key == null ) {
			throw new Exception( "'key' cannot be null" );
		}

		if ( data == null ) {
			throw new Exception( "'data' cannot be null" );
		}

		String base64value = Transcoder.toString( data );

		/*
		 * Atomic transaction (MULTI/EXEC) to set the key and its ttl.
		 * 
		 * (see https://redis.io/commands/multi)
		 */
		asyncCommands.multi();
		futureHset = asyncCommands.hset( region, key, base64value ); // Time complexity: O(1)
		futureZadd = asyncCommands.zadd( ttls, ttl, key ); // O(log(N)) for each key added, where N is the number of keys in the sorted set.
		future = asyncCommands.exec();
		future.get( waitTimeSeconds, TimeUnit.SECONDS );

	} catch ( Exception e ) {
		if ( cfEngine.thisPlatform != null ) {
			cfEngine.log( getName() + " set Failed: " + e.getMessage() );
		}
		if ( futureHset != null ) {
			futureHset.cancel( true );
		}
		if ( futureZadd != null ) {
			futureZadd.cancel( true );
		}
		if ( future != null ) {
			future.cancel( true );
		}
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:75,代码来源:RedisCacheImpl.java


注:本文中的io.lettuce.core.TransactionResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。