Java Code Examples for redis.clients.jedis.Jedis#del()

The following examples show how to use redis.clients.jedis.Jedis#del() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisTest.java    From gameserver with Apache License 2.0 6 votes vote down vote up
@Test
public void testJedisPool() {
	JedisPool pool = new JedisPool(config, host);
	Jedis jedis = pool.getResource();
	byte[] key = "hello ".getBytes();
	byte[] value = "world".getBytes();
	long startM = 0l, endM = 0l;
	
	startM = System.currentTimeMillis();
	for ( int i=0; i<max; i++ ) {
		key[key.length-1] = (byte)(i&0xFF);
		jedis.set(key, value);
		jedis.del(key);
	}
	endM = System.currentTimeMillis();
	System.out.println("Original Jedis loop " + max + " perform: " + (endM-startM));
}
 
Example 2
Source File: JedisUtil.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 删除缓存
 *
 * @param key 键
 * @return
 */
public static long delObject(String key) {
    long result = 0;
    Jedis jedis = null;
    try {
        jedis = getResource();
        if (jedis.exists(getBytesKey(key))) {
            result = jedis.del(getBytesKey(key));
        } else {
            logger.debug("delObject {} not exists", key);
        }
    } catch (Exception e) {
        logger.warn("delObject {}", key, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 3
Source File: JedisUtils.java    From easyweb with Apache License 2.0 6 votes vote down vote up
/**
 * 设置Set缓存
 * @param key 键
 * @param value 值
 * @param cacheSeconds 超时时间,0为不超时
 * @return
 */
public static long setObjectSet(String key, Set<Object> value, int cacheSeconds) {
	long result = 0;
	Jedis jedis = null;
	try {
		jedis = getResource();
		if (jedis.exists(getBytesKey(key))) {
			jedis.del(key);
		}
		Set<byte[]> set = Sets.newHashSet();
		for (Object o : value){
			set.add(toBytes(o));
		}
		result = jedis.sadd(getBytesKey(key), (byte[][])set.toArray());
		if (cacheSeconds != 0) {
			jedis.expire(key, cacheSeconds);
		}
		logger.debug("setObjectSet {} = {}", key, value);
	} catch (Exception e) {
		logger.warn("setObjectSet {} = {}", key, value, e);
	} finally {
		returnResource(jedis);
	}
	return result;
}
 
Example 4
Source File: JedisUtils.java    From easyweb with Apache License 2.0 6 votes vote down vote up
/**
 * 删除缓存
 * @param key 键
 * @return
 */
public static long delObject(String key) {
	long result = 0;
	Jedis jedis = null;
	try {
		jedis = getResource();
		if (jedis.exists(getBytesKey(key))){
			result = jedis.del(getBytesKey(key));
			logger.debug("delObject {}", key);
		}else{
			logger.debug("delObject {} not exists", key);
		}
	} catch (Exception e) {
		logger.warn("delObject {}", key, e);
	} finally {
		returnResource(jedis);
	}
	return result;
}
 
Example 5
Source File: JedisUtil.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 设置Map缓存
 *
 * @param key          键
 * @param value        值
 * @param cacheSeconds 超时时间,0为不超时
 * @return
 */
public static String setObjectMap(String key, Map<String, Object> value, int cacheSeconds) {
    String result = null;
    Jedis jedis = null;
    try {
        jedis = getResource();
        if (jedis.exists(getBytesKey(key))) {
            jedis.del(key);
        }
        result = hmSetAndGetStr(key, value, jedis);
        if (cacheSeconds != 0) {
            jedis.expire(key, cacheSeconds);
        }
    } catch (Exception e) {
        logger.warn("setObjectMap {} = {}", key, value, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 6
Source File: RedisClient.java    From apollo with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Remove the specified keys.
 *
 * @param key
 *
 * @return false if redis did not execute the option
 */
public boolean delete(String key) {
    Jedis jedis = null;
    try {
        jedis = this.jedisPool.getResource();
        jedis.del(SafeEncoder.encode(key));
        logger.info("delete key:" + key);

        return true;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        this.jedisPool.returnBrokenResource(jedis);
    } finally {
        if (jedis != null) {
            this.jedisPool.returnResource(jedis);
        }
    }
    return false;
}
 
Example 7
Source File: JedisUtil.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 设置Set缓存
 *
 * @param key          键
 * @param value        值
 * @param cacheSeconds 超时时间,0为不超时
 * @return
 */
public static long setSet(String key, Set<String> value, int cacheSeconds) {
    long result = 0;
    Jedis jedis = null;
    try {
        jedis = getResource();
        if (jedis.exists(key)) {
            jedis.del(key);
        }
        result = jedis.sadd(key, value.toArray(new String[value.size()]));
        if (cacheSeconds != 0) {
            jedis.expire(key, cacheSeconds);
        }
    } catch (Exception e) {
        logger.warn("setSet {} = {}", key, value, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 8
Source File: JedisUtil.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 设置List缓存
 *
 * @param <T>
 * @param key          键
 * @param value        值
 * @param cacheSeconds 超时时间,0为不超时
 * @return
 */
public static <T> long setObjectList(String key, List<T> value, int cacheSeconds) {
    long result = 0;
    Jedis jedis = null;
    try {
        jedis = getResource();
        if (jedis.exists(getBytesKey(key))) {
            jedis.del(key);
        }
        for (Object o : value) {
            result += jedis.rpush(getBytesKey(key), toBytes(o));
        }
        if (cacheSeconds != 0) {
            jedis.expire(key, cacheSeconds);
        }
    } catch (Exception e) {
        logger.warn("setObjectList {} = {}", key, value, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 9
Source File: SimpleTest.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
private void delete(Jedis[] jedises, int round) {

        logger.info("delete");

        for (Jedis jedis : jedises) {
            jedis.del(getkey(round));
        }
    }
 
Example 10
Source File: RedisTest.java    From khan-session with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDelKey() {
    Jedis jedis = new Jedis("localhost");
    jedis.select(1);
    jedis.del("test");
    jedis.del("foo");
}
 
Example 11
Source File: RedisCacheProvider.java    From xiaoyaoji with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void remove(String token) {
    Jedis jedis = null;
    try {
        jedis = pool.getResource();
        jedis.del(token);
    } finally {
        if (jedis != null)
            jedis.close();
    }
}
 
Example 12
Source File: RedisManager.java    From jee-universal-bms with Apache License 2.0 5 votes vote down vote up
/**
 * del
 * @param key
 */
public void del(byte[] key){
    Jedis jedis = pool.getResource();
    try{
        jedis.del(key);
    } catch (Exception e) {
        pool.returnBrokenResource(jedis);
        e.printStackTrace();
    } finally{
        pool.returnResource(jedis);
    }
}
 
Example 13
Source File: JedisClient.java    From dlock with Apache License 2.0 5 votes vote down vote up
/**
 * String delete command
 *
 * @param key
 * @return
 */
public Long del(String key) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        return jedis.del(key);

    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
}
 
Example 14
Source File: RedisPoolUtil.java    From mmall-kay-Java with Apache License 2.0 5 votes vote down vote up
public static Long del(String key){
    Jedis jedis = null;
    Long result=null;
    try {
        jedis = RedisPool.getJedis();
        result = jedis.del(key);
    } catch (Exception e) {
        log.error("del key:{} error",key,e);
        RedisPool.returnBrokenResource(jedis);
        return result;
    }
    RedisPool.returnResource(jedis);
    return result;
}
 
Example 15
Source File: LogDB.java    From VileBot with MIT License 5 votes vote down vote up
public static void deleteLog()
{
    Jedis jedis = pool.getResource();
    try
    {
        jedis.del( logKey );
    }
    finally
    {
        pool.returnResource( jedis );
    }
}
 
Example 16
Source File: RoleServiceImpl.java    From permission with Apache License 2.0 5 votes vote down vote up
@Override
public GlobalResult updateRoleMenu(Integer roleuuid, String checkedIds) {
	Jedis jedis = jedisPool.getResource();
	try {
		// 清空角色下的权限菜单
		roleMapper.deleteMenuidByRoleid(roleuuid);
		// 权限角色id
		if (checkedIds != null) {
			String[] ids = checkedIds.split(",");
			for (String menuUuid : ids) {
				roleMapper.insertRolemenu(menuUuid, roleuuid);
			}
		}
		List<Integer> userIdList = roleMapper.selectUseridByRoleuuid(roleuuid);
		for (Integer userId : userIdList) {
			
			jedis.del("menusEasyui_" + userId);
			jedis.del("menusList_" + userId);
		}
		System.out.println("更新角色对应的对应的权限菜单 ,清除缓存");
	} catch (Exception e) {
		e.printStackTrace();
	}finally {
		if(jedis!=null)jedis.close();
	}
	return GlobalResult.build(200, "权限设置成功");
}
 
Example 17
Source File: RedisPoolUtil.java    From redis-distributed-lock with Apache License 2.0 5 votes vote down vote up
public static Long del(String key){
    Jedis jedis = null;
    Long result = null;
    try {
        jedis = RedisPool.getJedis();
        result = jedis.del(key);
    } catch (Exception e){
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
        return result;
    }
}
 
Example 18
Source File: JedisTest.java    From springbootexamples with Apache License 2.0 5 votes vote down vote up
@Test
public void del(){
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        long count = jedis.del("a");
        log.info("删除 key 为 a 的值");
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        if(jedis != null){
            jedis.close();
        }
    }
}
 
Example 19
Source File: RedisManager.java    From jee-universal-bms with Apache License 2.0 5 votes vote down vote up
public  Long del(String key){
    Long length=null;
    Jedis jedis = pool.getResource();
    try {
        length=jedis.del(key);
    } finally {
        pool.returnResource(jedis);
    }
    return length;
}
 
Example 20
Source File: ObjectCacheOperate.java    From xian with Apache License 2.0 4 votes vote down vote up
public static long del(Jedis jedis, String key) {
    return jedis.del(key);
}