up
This commit is contained in:
parent
333ca283b3
commit
64c95c2903
@ -17,7 +17,7 @@ public interface CacheStorager<T> {
|
|||||||
*
|
*
|
||||||
* @param cacheKey
|
* @param cacheKey
|
||||||
* 缓存key
|
* 缓存key
|
||||||
* @return
|
* @return 缓存对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
T lookup(String cacheKey) throws WeixinException;
|
T lookup(String cacheKey) throws WeixinException;
|
||||||
|
|||||||
@ -2,10 +2,12 @@ package com.foxinmy.weixin4j.token;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.JedisPoolConfig;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
@ -104,12 +106,7 @@ public class RedisTokenStorager implements TokenStorager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token evict(String cacheKey) throws WeixinException {
|
public Token evict(String cacheKey) throws WeixinException {
|
||||||
Token token = null;
|
Token token = lookup(cacheKey);
|
||||||
try {
|
|
||||||
token = lookup(cacheKey);
|
|
||||||
} catch (WeixinException e) {
|
|
||||||
; // never
|
|
||||||
}
|
|
||||||
Jedis jedis = null;
|
Jedis jedis = null;
|
||||||
try {
|
try {
|
||||||
jedis = jedisPool.getResource();
|
jedis = jedisPool.getResource();
|
||||||
@ -124,6 +121,21 @@ public class RedisTokenStorager implements TokenStorager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() throws WeixinException {
|
public void clear() throws WeixinException {
|
||||||
// en....
|
Jedis jedis = null;
|
||||||
|
try {
|
||||||
|
jedis = jedisPool.getResource();
|
||||||
|
Set<String> cacheKeys = jedis.keys("weixin4j_*");
|
||||||
|
if (!cacheKeys.isEmpty()) {
|
||||||
|
Pipeline pipeline = jedis.pipelined();
|
||||||
|
for (String cacheKey : cacheKeys) {
|
||||||
|
pipeline.del(cacheKey);
|
||||||
|
}
|
||||||
|
pipeline.sync();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (jedis != null) {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user