| | |
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | public Jedis getJedis() {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | return jedis;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 缓存字符串
|
| | | *
|
| | |
| | | * @param value
|
| | | */
|
| | | private void setString(String key, String value) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | SetParams params=new SetParams().nx().ex(60);
|
| | | jedis.set(key, value, params);
|
| | | try {
|
| | |
| | | * @param value
|
| | | */
|
| | | private void removeKey(String key) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | try {
|
| | | jedis.del(key);
|
| | | } finally {
|
| | |
| | | *
|
| | | * @param key
|
| | | * @param value
|
| | | * @param seconds
|
| | | * -缓存时间(s)
|
| | | * @param seconds -缓存时间(s)
|
| | | */
|
| | | private void setString(String key, String value, int seconds) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | try {
|
| | | jedis.setex(key, seconds, value);
|
| | | } finally {
|
| | |
| | | }
|
| | |
|
| | | private String getString(String key) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | try {
|
| | | return jedis.get(key);
|
| | | } finally {
|
| | |
| | | }
|
| | |
|
| | | public void increase(String key) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | try {
|
| | | jedis.incr(key);
|
| | | } finally {
|
| | |
| | | }
|
| | |
|
| | | public void expire(String key, int seconds) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | try {
|
| | | jedis.expire(key, seconds);
|
| | | } finally {
|
| | |
| | | */
|
| | | public boolean ipFrequencyLimit(String ip, String apiName) {
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, ip + "-" + StringUtil.Md5(apiName));
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | try {
|
| | | long count = jedis.incr(key);
|
| | | if (count == 1)
|
| | |
| | |
|
| | | public boolean frequencyLimit(String key, int timeS, int num) {
|
| | | key = RedisKeyEnum.getRedisKey(RedisKeyEnum.frequencyLimit, key);
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = getJedis();
|
| | | try {
|
| | | long count = jedis.incr(key);
|
| | | if (count == 1)
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * |
| | | * @param phone
|
| | | * @param type
|
| | | * @return
|