/**
* @author zhangshuo
*/
@Slf4j
public class JedisClusterPipeLine extends PipelineBase implements Closeable {
......
......
private final Queue orderedClients = new LinkedList();
/** 一次pipeline过程中使用到的jedis缓存 */
private final Map poolToJedisMap = new HashMap();
private final JedisSlotBasedConnectionHandler connectionHandler;
private final JedisClusterInfoCache clusterInfoCache;
public JedisClusterPipeLine(JedisCluster jedisCluster) {
this.connectionHandler = ClassUtils.getValue(jedisCluster, SLOT_BASED__CONNECTION_HANDLER_FIELD);
this.clusterInfoCache = ClassUtils.getValue(connectionHandler, CLUSTER_INFO_CACHE_FIELD);
}
@Override
protected Client getClient(String key) {
return getClient(SafeEncoder.encode(key));
}
@Override
protected Client getClient(byte[] key) {
Client client;
log.debug("size of orderedClients : {} , size of poolToJedis : {} ", orderedClients.size(),
poolToJedisMap.size());
int slot = JedisClusterCRC16.getSlot(key);
JedisPool pool = clusterInfoCache.getSlotPool(slot);
Jedis borrowedJedis = poolToJedisMap.get(pool);
if (null == borrowedJedis) {
borrowedJedis = pool.getResource();
poolToJedisMap.put(pool, borrowedJedis);
}
client = borrowedJedis.getClient();
orderedClients.add(client);
return client;
}
@Override
public void close() {
for (Jedis jedis : poolToJedisMap.values()) {
jedis.close();
}
clean();
orderedClients.clear();
poolToJedisMap.clear();
}
public void sync() {
for (Client client : orderedClients) {
generateResponse(client.getOne());
}
}
/**
* go through all the responses and generate the right response type (warning :
* usually it is a waste of time).
*
* @return A list of all the responses in the order
*/
public List
性能对比(提升10倍以上):
@Test
public void jedisTest() throws UnsupportedEncodingException {
long start2 = System.currentTimeMillis();
try (JedisClusterClient jc = jedisClusterClient) {
for (int i = 0; i < 100; i++) {
jc.set("NO." + i, "value" + i);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(System.currentTimeMillis() - start2);// 5688ms
}
/**
*
*/
@Test
public void clusterPipeline() {
long start = System.currentTimeMillis();
try (JedisClusterPipeLine pipeline = jedisClusterClient.pipelined()) {
for (int i = 0; i < 100; i++) {
pipeline.set("NO." + i, "value" + i);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(System.currentTimeMillis() - start);// 174ms
}
}
今天eclipse突然报了com/genuitec/eclipse/j2eedt/core/J2EEProjectUtil 错误,并且工程文件打不开了,在网上找了一下资料,然后按照方法操作了一遍,好了,解决方法如下:
错误提示信息:
An error has occurred.See error log for more details.
Reason:
com/genuitec/
Java使用按值传递的函数调用方式,这往往使我感到迷惑。因为在基础数据类型和对象的传递上,我就会纠结于到底是按值传递,还是按引用传递。其实经过学习,Java在任何地方,都一直发挥着按值传递的本色。
首先,让我们看一看基础数据类型是如何按值传递的。
public static void main(String[] args) {
int a = 2;
Implicits work like this: if you call a method on a Scala object, and the Scala compiler does not see a definition for that method in the class definition for that object, the compiler will try to con
工作与生产效率:
A. 背景声音
Noisli:背景噪音与颜色生成器。
Noizio:环境声均衡器。
Defonic:世界上任何的声响都可混合成美丽的旋律。
Designers.mx:设计者为设计者所准备的播放列表。
Coffitivity:这里的声音就像咖啡馆里放的一样。
B. 避免注意力分散
Self Co