1,redis 报异常
redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
@Test
public void test_faildTime(){
String identify="13718486139";
int failedTime=WapController.getFailedCount(identify);
System.out.println(failedTime);
}
/**
* Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1
* GB).
* @param key
* @param value
* @param nxxx NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the key
* if it already exist.
* @param expx EX|PX, expire time units: EX = seconds; PX = milliseconds
* @param time expire time in the units of {@param #expx}
* @return Status code reply
*/
public String set(final String key, final String value, final String nxxx, final String expx,
final long time) {
checkIsInMulti();
client.set(key, value, nxxx, expx, time);
return client.getStatusCodeReply();
}
封装之后:
/***
* Only set the key if it does not already exist
*
* @param k
* @param v
* @param time : second
*/
public void saveExpxKeyCache(String k, String v, long time) {
saveExpxKeyCache(k, v, "NX", time);
}
/***
* @param k
* @param v
* @param nxxx : NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the key
* if it already exist.
* @param time : second
*/
public void saveExpxKeyCache(String k, String v, String nxxx, long time) {
Jedis jedis = Const.pool.getResource();
try {
jedis.set(k, v, nxxx, "EX"/*seconds*/, time);
} catch (Exception e) {
e.printStackTrace();
logger.error("saveKeyCache", e);
Const.pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
Const.pool.returnResource(jedis);
}
}
}
3,应用
登录或者发送短信验证码,连续失败三次则弹出图形验证码
如何记录失败次数呢?