读书人

cassandra内部API应用三2010-07-07

发布时间: 2012-10-08 19:54:56 作者: rapoo

cassandra内部API使用三2010-07-07
/** 根据Key从缓存删除缓存数据.
*
* @param aKeyArea Key
*/
public void remove(String aKeyArea)
{
CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
// 取得客户端(群集服务器)
CassandraClient client = null;
try
{
// 从群集服务器获得一个客户端
client = pool.borrowClient(mCassandraClient);

// Keyspace
Keyspace keyspace =
client.getKeyspace(mDefaultKeyspace);
// ColumnPath
ColumnPath columnPath = new ColumnPath(mDefaultColumnFamily);

// 从缓存中清除
keyspace.remove(aKeyArea, columnPath);

// 为确保finally中能正确释放client,此处需重获取一次
client = keyspace.getClient();
}
catch (Exception e)
{
sLog.error("根据Key从缓存删除缓存数据时出错。");
sLog.error(e);
}
finally
{
// finally中释放client
releaseClient(pool, client);
}
}

/**根据Key和column从缓存删除缓存数据.
* @param aKeyArea Key
* @param aName column
*/
public void remove(String aKeyArea, String aName)
{
CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
// 取得客户端(群集服务器)
CassandraClient client = null;
try
{
// 从群集服务器获得一个客户端
client = pool.borrowClient(mCassandraClient);

// Keyspace
Keyspace keyspace =
client.getKeyspace(mDefaultKeyspace);
// ColumnPath
ColumnPath columnPath = new ColumnPath(mDefaultColumnFamily);
columnPath.setColumn(bytes(aName));

// 从缓存中清除
keyspace.remove(aKeyArea, columnPath);

// 为确保finally中能正确释放client,此处需重获取一次
client = keyspace.getClient();
}
catch (Exception e)
{
sLog.error("根据Key和column从缓存删除缓存数据时出错。");
sLog.error(e);
}
finally
{
// finally中释放client
releaseClient(pool, client);
}
}

读书人网 >软件架构设计

热点推荐