Skip to content

Commit

Permalink
jedis pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesonchen committed May 15, 2019
1 parent 9d7e6eb commit 399ade4
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void main(String[] args) {

JedisCluster jc = null;
try {
jc = JedisClusterFactory.instance().getJedisCluster(CLUSTER_NODES);
jc = JedisClusterFactory.getInstance().getJedisCluster(CLUSTER_NODES);
System.out.println(jc.get("10001"));
} finally {
IOUtils.closeQuietly(jc);
Expand Down
File renamed without changes
Binary file added src/main/java/com/asiainfo/redis/jedispool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion src/main/java/com/asiainfo/redis/usage/DistributeLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void main(String[] args) {
DistributeLock dl = new DistributeLock();
JedisCluster jc = null;
try {
jc = JedisClusterFactory.instance().getJedisCluster(CLUSTER_NODES);
jc = JedisClusterFactory.getInstance().getJedisCluster(CLUSTER_NODES);
// acquireLock
String lock = dl.acquireLock(jc, LOCK_KEY);
dl.acquireLock(jc, LOCK_KEY);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/asiainfo/redis/usage/IdGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import redis.clients.jedis.JedisCluster;

/**
* IdGenerator 分布式id生成器,jedis.incr(key)
* IdGenerator 分布式id生成器,jedis.incr(key) / jedis.incrBy(key, long)
*
* @author chenzq
* @date 2019年4月27日 下午5:47:34
Expand All @@ -21,7 +21,7 @@ public class IdGenerator {
public static void main(String[] args) {
JedisCluster jc = null;
try {
jc = JedisClusterFactory.instance().getJedisCluster(CLUSTER_NODES);
jc = JedisClusterFactory.getInstance().getJedisCluster(CLUSTER_NODES);
// incr
for (int i = 0; i < 100; i++) {
jc.incr(KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void main(String[] args) throws Exception {

JedisCluster jc = null;
try {
jc = JedisClusterFactory.instance().getJedisCluster(CLUSTER_NODES);
jc = JedisClusterFactory.getInstance().getJedisCluster(CLUSTER_NODES);
JedisSlotBasedConnectionHandler handler = getFieldValue(jc, FIELD_CONNECTION_HANDLER);
JedisClusterInfoCache cache = getFieldValue(handler, FIELD_INFO_CACHE);
Jedis jedis = cache.getSlotPool(JedisClusterCRC16.getSlot(WATCH_KEY)).getResource();
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/asiainfo/redis/util/JedisClusterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ private static class JedisClusterFactoryHolder {
private static JedisClusterFactory instance = new JedisClusterFactory();
}

public static JedisClusterFactory instance() {
public static JedisClusterFactory getInstance() {
return JedisClusterFactoryHolder.instance;
}

// 获取JedisCluster连接
/**
* @Description: 获取JedisCluster连接
* @author chenzq
* @date 2019年5月9日 下午2:47:40
* @param clusterNodes
* @return
*/
public JedisCluster getJedisCluster(String clusterNodes) {

JedisCluster jc = null;
try {
// Jedis连接池配置,基于common-pool2
Expand Down
17 changes: 6 additions & 11 deletions src/main/resources/application-redis-configure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd ">

<!-- 引入配置文件 -->
<bean id="redis_propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<value>classpath:redis.properties</value>
</property>
</bean>

<!-- 启用组件注解扫描 -->
<context:component-scan base-package="com.asiainfo.redis.service" />

<!-- 启用组件注解扫描 -->
<context:component-scan base-package="com.asiainfo.redis.service" />

<!-- 配置redis相关参数properties的属性:${} -->
<context:property-placeholder location="classpath:redis.properties" />

<!-- redisCluster 配置文件加载 -->
<bean id="resourcePropertySource" class="org.springframework.core.io.support.ResourcePropertySource">
Expand Down

0 comments on commit 399ade4

Please sign in to comment.