@RequestMapping("/login")
 @ResponseBody
 public Response login(@RequestBody Map<String, Object> map) {
   Response res = new Response();
   List<User> users = userService.login(map);
   if (users == null || users.size() == 0) {
     return res.failure("登陆失败");
   }
   ShardedJedis shardedJedis = shardedJedisPool.getResource();
   try {
     String skey = "session:" + users.get(0).getId();
     String token = UUID.randomUUID().toString();
     if (shardedJedis.exists(skey)) {
       String oldtoken = shardedJedis.get(skey);
       shardedJedis.del(skey);
       shardedJedis.del("token:" + oldtoken);
     }
     if (shardedJedis.setnx(skey, token) == 1) {
       shardedJedis.expire(skey, 3600 * 24);
       shardedJedis.hset("token:" + token, "name", users.get(0).getName());
       shardedJedis.expire("token:" + token, 3600 * 24);
     } else {
       token = shardedJedis.get(skey);
     }
     Map<String, Object> data = new HashMap<>();
     data.put("token", token);
     return new Response().success(data);
   } finally {
     shardedJedis.close();
   }
 }
Example #2
0
 public void delAuthCode(String key) {
   ShardedJedis shardedJedis = shardedJedisPool.getResource();
   try {
     shardedJedis.del(key);
   } catch (Throwable e) {
     throw new RuntimeException(e);
   } finally {
     shardedJedis.close();
   }
 }
 @Override
 public Long del(String key) {
   ShardedJedis jedis = shardedJedisPool.getResource();
   try {
     return jedis.del(key);
   } catch (Exception e) {
     logger.error("Execute redis command failure", e);
   } finally {
     jedis.close();
   }
   return null;
 }
Example #4
0
 /**
  * Description: <br>
  *
  * @author 王伟<br>
  * @taskId <br>
  * @param nodeName
  * @return
  * @throws CacheException <br>
  */
 @Override
 public boolean removeNode(String nodeName) throws CacheException {
   ShardedJedis shardedJedis = null;
   try {
     shardedJedis = shardedPool.getResource();
     shardedJedis.del(nodeName.getBytes());
   } catch (Exception e) {
     throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
   } finally {
     shardedPool.returnResourceObject(shardedJedis);
   }
   return true;
 }
 /**
  * 删除指定的key,也可以传入一个包含key的数组
  *
  * @param keys 一个key 也可以使 string 数组
  * @return 返回删除成功的个数
  */
 public Long del(String key) {
   ShardedJedis jedis = null;
   try {
     jedis = pool.getResource();
     return jedis.del(key);
   } catch (Exception e) {
     pool.returnBrokenResource(jedis);
     e.printStackTrace();
     return 0L;
   } finally {
     returnResource(pool, jedis);
   }
 }
Example #6
0
  public boolean del(String key) {
    ShardedJedis shardedJedis = null;
    try {
      shardedJedis = masterShardedJedisPool.getResource();
      shardedJedis.del(key);
      return true;
    } catch (Exception ex) {
      logger.error("del error.", ex);

    } finally {
      returnResource(shardedJedis);
    }
    return false;
  }
 public Long removeKey(String key) {
   ShardedJedis jedis = null;
   boolean success = true;
   try {
     pool = getPool();
     jedis = pool.getResource();
     return jedis.del(key);
   } catch (JedisException e) {
     success = false;
     if (jedis != null) {
       pool.close();
     }
     throw e;
   } finally {
     if (success && jedis != null) {
       pool.close();
     }
   }
 }
Example #8
0
  /**
   * 删除数据
   *
   * @param keys
   */
  public void delValue(String keys) {

    jedis.del(keys);
  }