#221 加入对Jedis的封装,修改注释,增加jedisTemplate函数,加入描述故事的jsp
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
<div class="submenu">
|
||||
<a id="persistence-tab" href="${ctx}/story/persistence">持久化高级演示</a>
|
||||
<a id="jms-tab" href="${ctx}/story/jms">JMS演示</a>
|
||||
<a id="reids-tab" href="${ctx}/story/redis">Redis演示</a>
|
||||
<a id="cache-tab" href="${ctx}/story/cache">Cache演示</a>
|
||||
<a id="schedule-tab" href="${ctx}/story/schedule">定时任务演示</a>
|
||||
<a id="security-tab" href="${ctx}/story/security">安全高级演示</a>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8"%>
|
||||
<html>
|
||||
<head>
|
||||
<title>JMS演示</title>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#redis-tab").addClass("active");
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Redis演示</h1>
|
||||
|
||||
<h2>用户故事:</h2>
|
||||
所有演示在src/**/demo/redis/ 目录中独立运行main函数.
|
||||
<ul>
|
||||
<li>高性能Counter的benchmark测试用例</li>
|
||||
<li>高性能Session的benchmark测试用例</li>
|
||||
<li>高性能Scheduler的benchmark测试用例</li>
|
||||
<li>集群内master选举功能演示</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@@ -119,6 +119,9 @@ public class JedisTemplate {
|
||||
}
|
||||
|
||||
// ////////////// 关于String ///////////////////////////
|
||||
/**
|
||||
* 如果key不存在, 返回null.
|
||||
*/
|
||||
public String get(final String key) {
|
||||
return execute(new JedisAction<String>() {
|
||||
|
||||
@@ -129,6 +132,22 @@ public class JedisTemplate {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果key不存在, 返回0.
|
||||
*/
|
||||
public Long getAsLong(final String key) {
|
||||
String result = get(key);
|
||||
return result != null ? Long.valueOf(result) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果key不存在, 返回0.
|
||||
*/
|
||||
public Integer getAsInt(final String key) {
|
||||
String result = get(key);
|
||||
return result != null ? Integer.valueOf(result) : 0;
|
||||
}
|
||||
|
||||
public void set(final String key, final String value) {
|
||||
execute(new JedisActionNoResult() {
|
||||
|
||||
|
||||
+4
-4
@@ -30,9 +30,9 @@ import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
/**
|
||||
* Master选举实现, 基于setNx()与expire()两大API
|
||||
*
|
||||
* The purpose of this class is define a MasterElector to select a server is a master. The client can invoke the
|
||||
* function isMaster().
|
||||
* @author calvin
|
||||
*/
|
||||
public class MasterElector implements Runnable {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class MasterElector implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动分发线程, 自行创建scheduler线程池.
|
||||
* 启动抢注线程, 自行创建scheduler线程池.
|
||||
*/
|
||||
public void start() {
|
||||
internalScheduledThreadPool = Executors.newScheduledThreadPool(1,
|
||||
@@ -75,7 +75,7 @@ public class MasterElector implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动分发线程, 使用传入的scheduler线程池.
|
||||
* 启动抢注线程, 使用传入的scheduler线程池.
|
||||
*/
|
||||
public void start(ScheduledExecutorService scheduledThreadPool) {
|
||||
if (intervalSeconds >= expireSeconds) {
|
||||
|
||||
+1
-2
@@ -131,8 +131,7 @@ public class JobDispatcher implements Runnable {
|
||||
* 获取已分发的Job数量。
|
||||
*/
|
||||
public long getDispatchNumber() {
|
||||
String result = jedisTemplate.get(dispatchCounterKey);
|
||||
return result != null ? Long.valueOf(result) : 0;
|
||||
return jedisTemplate.getAsLong(dispatchCounterKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user