admin
2019-11-20 92218d10ca3192e5ca53ff26d74b29a992d48962
redis整改
15个文件已修改
125 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/manager/util/AtomMethodCallManager.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/msg/MsgOrderDetailServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-dev/redis.properties 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-pro-by/redis.properties 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-pro-job/redis.properties 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-pro/redis.properties 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/spring.xml 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java
@@ -28,6 +28,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;
/**
 * 活跃用户处理
@@ -86,8 +87,7 @@
                            String key = "useractive-" + uidStr;
                            Jedis jedis = jedisPool.getResource();
                            try {
                                if (jedis.setnx(key, "1") > 0) {
                                    jedis.expire(key, 60 * 5);// 5分钟内不处理
                                if (!StringUtil.isNullOrEmpty(jedis.set(key, "1", new SetParams().nx().ex(300)))) {
                                    try {
                                        // TODO 用户活跃处理
                                        Long uid = Long.parseLong(uidStr);
@@ -99,7 +99,7 @@
                                    }
                                }
                            } finally {
                                jedisPool.returnResource(jedis);
                                jedis.close();
                            }
                        }
                    });
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java
@@ -30,6 +30,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;
@Component
@Aspect
@@ -100,14 +101,15 @@
                        LogHelper.test("进入拦截:"+cacheKey+"-"+threadId);
                        try {
                            Constant.waitingThreadSet.add(threadId);
                            long result = 0;
                            String result = null;
                            long startTime = System.currentTimeMillis();
                            // 等待响应
                            while (result <= 0) {
                                result = jedis.setnx(cacheKey, "1");
                            while (StringUtil.isNullOrEmpty(result)) {
                                result = jedis.set(cacheKey, "1", new SetParams().nx().ex(30));
                                LogHelper.error("触发并发锁:" + cacheAlias);
                                LogHelper.error("redis键:" + cacheKey);
                                if (result <= 0) {
                                if (StringUtil.isNullOrEmpty(result)) {
                                    LogHelper.test("等待:"+threadId);
                                    try {
                                        Thread.sleep(50);
@@ -120,14 +122,12 @@
                                        return null;
                                    }
                                } else {
                                    // 设置30秒处理时间
                                    jedis.expire(cacheKey, 30);
                                    LogHelper.test("获取到锁:"+threadId);
                                    break;
                                }
                            }
                            if (result > 0) {
                            if (!StringUtil.isNullOrEmpty(result)) {
                                try {
                                    return joinPoint.proceed();
                                } catch (Throwable e) {
@@ -141,7 +141,7 @@
                                }
                            }
                        } finally {
                            jedisPool.returnResource(jedis);
                            jedis.close();
                        }
                    }
                } catch (Exception e) {// 原子性保护出错
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java
@@ -24,6 +24,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;
@Component
@Aspect
@@ -70,12 +71,12 @@
                        Jedis jedis = jedisPool.getResource();
                        try {
                            Constant.waitingThreadSet.add(Thread.currentThread().getId());
                            long result = 0;
                            String result = null;
                            long startTime = System.currentTimeMillis();
                            // 等待响应
                            while (result <= 0) {
                                result = jedis.setnx(cacheKey, "1");
                                if (result <= 0) {
                            while (StringUtil.isNullOrEmpty(result)) {
                                result = jedis.set(cacheKey, "1", new SetParams().nx().ex(30));
                                if (StringUtil.isNullOrEmpty(result)) {
                                    try {
                                        Thread.sleep(50);
                                    } catch (InterruptedException e) {
@@ -85,13 +86,10 @@
                                        Constant.waitingThreadSet.remove(Thread.currentThread().getId());
                                        return null;
                                    }
                                } else {
                                    // 设置30秒处理时间
                                    jedis.expire(cacheKey, 30);
                                }
                            }
                            if (result > 0) {
                            if (!StringUtil.isNullOrEmpty(result)) {
                                try {
                                    return joinPoint.proceed();
                                } catch (Throwable e) {
@@ -103,7 +101,7 @@
                                }
                            }
                        } finally {
                            jedisPool.returnResource(jedis);
                            jedis.close();
                        }
                    }
                } catch (Exception e) {// 原子性保护出错
fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java
@@ -79,7 +79,7 @@
                    } finally {
                    }
                } finally {
                    jedisPool.returnResource(jedis);
                    jedis.close();
                }
            }
        } catch (NoSuchMethodException e) {
fanli/src/main/java/com/yeshi/fanli/manager/util/AtomMethodCallManager.java
@@ -8,6 +8,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;
@Component
public class AtomMethodCallManager {
@@ -26,14 +27,14 @@
        String redisKey = "atom-" + StringUtil.Md5(key);
        Jedis jedis = jedisPool.getResource();
        try {
            if (jedis.setnx(redisKey, "1") <= 0) {
            if (StringUtil.isNullOrEmpty(jedis.set(redisKey, "1", new SetParams().nx().ex(60)))) {
                System.out.println("请稍后再试");
                return;
            }
            jedis.expire(redisKey, 60);
            call.excute();
        } finally {
            jedis.del(redisKey);
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java
@@ -285,8 +285,7 @@
        if (oldHongBao == null)
            throw new HongBaoException(10, "红包对象不存在");
        // 已经失效,已经领取,新老状态一致的红包不做处理
        // 测试 oldHongBao.getState() == HongBaoV2.STATE_YILINGQU
        if (oldHongBao.getState() == HongBaoV2.STATE_SHIXIAO)
        if (oldHongBao.getState() == HongBaoV2.STATE_SHIXIAO||oldHongBao.getState() == HongBaoV2.STATE_YILINGQU)
            return false;
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
fanli/src/main/java/com/yeshi/fanli/service/impl/order/msg/MsgOrderDetailServiceImpl.java
@@ -67,7 +67,7 @@
            }
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -1069,7 +1069,7 @@
        } finally {
            jedis.del(watchKey);
            jedis.unwatch();
            jedisPool.returnResource(jedis);
            jedis.close();
        }
        throw new UserAccountException(10, "请稍后再试");
    }
@@ -1174,7 +1174,7 @@
        } finally {
            jedis.del(watchKey);
            jedis.unwatch();
            jedisPool.returnResource(jedis);
            jedis.close();
        }
        throw new UserAccountException(10, "请稍后再试");
    }
fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
@@ -31,6 +31,7 @@
import net.sf.json.JSONArray;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;
//抢红包采用的redis
@Component
@@ -56,10 +57,12 @@
     */
    private void setString(String key, String value) {
        Jedis jedis = jedisPool.getResource();
        SetParams params=new SetParams().nx().ex(60);
        jedis.set(key, value, params);
        try {
            jedis.set(key, value);
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
@@ -75,7 +78,7 @@
        try {
            jedis.del(key);
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
@@ -93,7 +96,7 @@
        try {
            jedis.setex(key, seconds, value);
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
@@ -102,7 +105,7 @@
        try {
            return jedis.get(key);
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
@@ -111,7 +114,7 @@
        try {
            jedis.incr(key);
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
@@ -120,7 +123,7 @@
        try {
            jedis.expire(key, seconds);
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
@@ -262,7 +265,7 @@
            else
                return false;
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
@@ -278,7 +281,7 @@
            else
                return false;
        } finally {
            jedisPool.returnResource(jedis);
            jedis.close();
        }
    }
fanli/src/main/resource/env-dev/redis.properties
@@ -1,7 +1,7 @@
redis.addr=192.168.1.253
redis.port=6379
redis.auth=123456
redis.max_active=1024
redis.max_total=1024
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
fanli/src/main/resource/env-pro-by/redis.properties
@@ -1,7 +1,7 @@
redis.addr=127.0.0.1
redis.port=6379
redis.auth=Yeshi2016@
redis.max_active=1024
redis.max_total=1024
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
fanli/src/main/resource/env-pro-job/redis.properties
@@ -1,7 +1,7 @@
redis.addr=172.16.16.15
redis.port=6379
redis.auth=crs-43yhgz0i:Yeshi2016@
redis.max_active=1024
redis.max_total=1024
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
fanli/src/main/resource/env-pro/redis.properties
@@ -1,7 +1,7 @@
redis.addr=172.16.16.15
redis.port=6379
redis.auth=crs-43yhgz0i:Yeshi2016@
redis.max_active=1024
redis.max_total=1024
redis.max_idle=200
redis.max_wait=10000
redis.timeout=5000
fanli/src/main/resource/spring.xml
@@ -226,41 +226,18 @@
    <!-- redis连接池 -->
    <bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxActive" value="${redis.max_active}"></property>
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="${redis.max_total}"></property>
        <property name="maxIdle" value="${redis.max_idle}"></property>
        <property name="maxWait" value="${redis.max_wait}"></property>
        <property name="testOnBorrow" value="${redis.test_on_borrow}"></property>
    </bean>
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg name="poolConfig" ref="jedisConfig"></constructor-arg>
        <constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
        <constructor-arg name="host" value="${redis.addr}"></constructor-arg>
        <constructor-arg name="port" value="${redis.port}"></constructor-arg>
        <constructor-arg name="timeout" value="${redis.timeout}"></constructor-arg>
        <constructor-arg name="password" value="${redis.auth}"></constructor-arg>
    </bean>
    <!-- redis连接工厂 -->
    <bean id="connectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="${redis.addr}"></property>
        <property name="port" value="${redis.port}"></property>
        <property name="password" value="${redis.auth}"></property>
        <property name="poolConfig" ref="jedisConfig"></property>
    </bean>
    <!-- redis操作模板,这里采用尽量面向对象的模板 -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="keySerializer">
            <bean
                class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
        <property name="valueSerializer">
            <bean
                class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        </property>
    </bean>
pom.xml
@@ -432,7 +432,7 @@
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.1.0</version>
            <version>3.1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
@@ -538,17 +538,6 @@
            <groupId>com.aliyun.openservices</groupId>
            <artifactId>ons-client</artifactId>
            <version>1.8.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.rocketmq</groupId>
            <artifactId>rocketmq-client</artifactId>
            <version>4.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.rocketmq</groupId>
            <artifactId>rocketmq-acl</artifactId>
            <version>4.5.1</version>
        </dependency>
        <!-- 分步式任务 -->