当前位置: 首页>>代码示例>>Java>>正文


Java Jedis.keys方法代码示例

本文整理汇总了Java中redis.clients.jedis.Jedis.keys方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.keys方法的具体用法?Java Jedis.keys怎么用?Java Jedis.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.keys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getActiveSessions

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 获取当前所有活跃用户
 */
@Override
public Collection<Session> getActiveSessions(){
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        Set<String> keys = jedis.keys(prefix + "*");
        if(CollectionUtils.isEmpty(keys)){
            return null;
        }
        List<String> values = jedis.mget(keys.toArray(new String[keys.size()]));
        return SerializeUtils.deserializeFromStrings(values);
    } catch (Exception e){
        logger.warn("统计Session信息失败", e);
    } finally {
        jedis.close();
    }
    return null;
}
 
开发者ID:ZhuXS,项目名称:Spring-Shiro-Spark,代码行数:22,代码来源:ShiroSessionDao.java

示例2: testDrop

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void testDrop() throws Exception {
    Client cl = new Client("testung", "localhost", 6379);
    cl._conn().flushDB();

    Schema sc = new Schema().addTextField("title", 1.0);

    assertTrue(cl.createIndex(sc, Client.IndexOptions.Default()));
    Map<String, Object> fields = new HashMap<>();
    fields.put("title", "hello world");
    for (int i = 0; i < 100; i++) {
        assertTrue(cl.addDocument(String.format("doc%d", i), fields));
    }

    SearchResult res = cl.search(new Query("hello world"));
    assertEquals(100, res.totalResults);

    assertTrue(cl.dropIndex());

    Jedis conn = cl._conn();

    Set<String> keys = conn.keys("*");
    assertTrue(keys.isEmpty());
}
 
开发者ID:RedisLabs,项目名称:JRediSearch,代码行数:25,代码来源:ClientTest.java

示例3: deleteRegEx

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 删除redis中key对应数据
 *
 * @param key key
 * @return 删除的条数
 */
public long deleteRegEx(String key) {
    Jedis jedis = null;
    long count = 0;

    try {
        jedis = getConnect();
        Set<String> keys = jedis.keys(key);

        if (keys == null || keys.isEmpty()) {
            return 0;
        }

        for (String sigleKey : keys) {
            jedis.del(sigleKey);
            count++;
        }
        return count;

    } catch (Exception e) {
        return -1;
    } finally {
        close(jedis);
    }
}
 
开发者ID:TwoDragonLake,项目名称:tdl-seckill,代码行数:31,代码来源:RedisUtil.java

示例4: gets

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 获取单个值
 *
 * @param likeKey 键
 * @return 结果
 */
public List<String> gets(String likeKey) {
    List<String> result = new ArrayList<>();
    ShardedJedis shardedJedis = shardedJedisPool.getResource();
    if (shardedJedis == null) {
        return null;
    }

    try {
        Collection<Jedis> jedisC = shardedJedis.getAllShards();
        Iterator<Jedis> iter = jedisC.iterator();
        while (iter.hasNext()) {
            Jedis _jedis = iter.next();
            Set<String> keys = _jedis.keys(likeKey + "*");
            keys.forEach(s -> result.add(_jedis.get(s)));
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        shardedJedis.close();
    }
    return result;
}
 
开发者ID:peng9627,项目名称:hall,代码行数:30,代码来源:RedisClientTemplate.java

示例5: delPre

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public Long delPre(String key) {
    Jedis jedis = null;
    try {
        jedis = pool.getResource();
        Set<String> set = jedis.keys(key + "*");
        int result = set.size();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String keyStr = it.next();
            jedis.del(keyStr);
        }
        return new Long(result);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        return 0L;
    } finally {
        returnResource(pool, jedis);
    }
}
 
开发者ID:wxiaoqi,项目名称:ace-cache,代码行数:21,代码来源:RedisServiceImpl.java

示例6: keys

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public String[] keys() throws IOException {
	Jedis jedis = null;
	Boolean error = true;
	try {
		jedis = acquireConnection();
		Set<String> keySet = jedis.keys("*");
		error = false;
		return keySet.toArray(new String[keySet.size()]);
	} finally {
		if (jedis != null) {
			returnConnection(jedis, error);
		}
	}
}
 
开发者ID:appNG,项目名称:appng-tomcat-session,代码行数:15,代码来源:RedisSessionManager.java

示例7: testGetRedisPool

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void testGetRedisPool() throws Exception {
    RedisPools result = poolManagement.getRedisPool();

    System.out.println(result.getDatabaseNum());
    Jedis jedis = result.getJedis();
    jedis.keys("");
    jedis.set("names","testGetRedisPool");
    Assert.assertEquals("testGetRedisPool",jedis.get("names"));
}
 
开发者ID:Kuangcp,项目名称:MythRedisClient,代码行数:11,代码来源:PoolManagementTest.java

示例8: keys

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 向redis中存入数据
 */
public Set<String> keys(String keyPattern) {
    Jedis jedis = null;
    try {
        jedis = getConnect();
        return jedis.keys(keyPattern);
    } catch (Exception e) {
        logger.error("redis keys failed!", e);
        return new HashSet<>();
    } finally {
        close(jedis);
    }
}
 
开发者ID:TwoDragonLake,项目名称:tdl-seckill,代码行数:16,代码来源:RedisUtil.java

示例9: processExpires

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public void processExpires() {
	long timeStart = System.currentTimeMillis();
	int expired = 0;
	Jedis jedis = null;
	boolean error = true;
	try {
		// retrieve all session IDs from redis without changing their lastAccessedTime
		jedis = acquireConnection();
		Set<String> sessionIds = jedis.keys("*");
		if (log.isDebugEnabled()) {
			log.debug(String.format("Starting to expire sessions, checking %s", sessionIds.size()));
		}
		for (String sessionId : sessionIds) {
			try {
				byte[] data = jedis.get(sessionId.getBytes());
				RedisSession session = createEmptySession();
				serializer.deserializeInto(data, session, new SessionSerializationMetadata());
				if (null != session && !session.isValid()) {
					expired++;
				}
			} catch (IOException | ReflectiveOperationException e) {
				log.error(String.format("error reading session %s", sessionId));
				jedis.del(sessionId.getBytes());
			}
		}
		error = false;
	} finally {
		if (jedis != null) {
			returnConnection(jedis, error);
		}
	}

	long duration = System.currentTimeMillis() - timeStart;
	if (log.isDebugEnabled()) {
		log.debug(String.format("Expired %s sessions in %sms", expired, duration));
	}
	processingTime += duration;
}
 
开发者ID:appNG,项目名称:appng-tomcat-session,代码行数:40,代码来源:RedisSessionManager.java

示例10: flushConfig

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 清空配置.
 * @param name 应用opkind
 * @throws Exception Exception
 */
public void flushConfig(final String name) throws Exception{
    Jedis configJedis = o2iJedisPool.getResource();
    Set<String> configSet = configJedis.keys(name+"*");
    if(!CollectionUtils.isEmpty(configSet)){
        configJedis.del(configSet.toArray(new String[0]));
    }
    configJedis.close();
}
 
开发者ID:Zigin,项目名称:MonitorPlatform,代码行数:14,代码来源:O2iMonitorService.java

示例11: clean

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void clean(Jedis jedis) {
    Set<String> keys = jedis.keys(root + Constants.ANY_VALUE);
    if (keys != null && keys.size() > 0) {
        for (String key : keys) {
            Map<String, String> values = jedis.hgetAll(key);
            if (values != null && values.size() > 0) {
                boolean delete = false;
                long now = System.currentTimeMillis();
                for (Map.Entry<String, String> entry : values.entrySet()) {
                    URL url = URL.valueOf(entry.getKey());
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        long expire = Long.parseLong(entry.getValue());
                        if (expire < now) {
                            jedis.hdel(key, entry.getKey());
                            delete = true;
                            if (logger.isWarnEnabled()) {
                                logger.warn("Delete expired key: " + key + " -> value: " + entry.getKey() + ", expire: " + new Date(expire) + ", now: " + new Date(now));
                            }
                        }
                    }
                }
                if (delete) {
                    jedis.publish(key, Constants.UNREGISTER);
                }
            }
        }
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:29,代码来源:RedisRegistry.java

示例12: getPlayerCraftingPearls

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public List<CraftingPearl> getPlayerCraftingPearls(UUID player)
{
    List<CraftingPearl> craftingPearls = new ArrayList<>();
    Jedis jedis = SamaGamesAPI.get().getBungeeResource();

    if (jedis == null)
        return craftingPearls;

    for (String key : jedis.keys("crafting-pearls:" + player.toString() + ":*"))
        craftingPearls.add(new Gson().fromJson(jedis.get(key), CraftingPearl.class));

    jedis.close();

    return craftingPearls;
}
 
开发者ID:SamaGames,项目名称:Hub,代码行数:16,代码来源:WellManager.java

示例13: AllSession

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 获取所有Session
 * @param dbIndex
 * @param redisShiroSession
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public Collection<Session> AllSession(int dbIndex, String redisShiroSession) throws Exception {
	Jedis jedis = null;
       Set<Session> sessions = new HashSet<Session>();
	try {
           jedis = getJedis();
           jedis.select(dbIndex);
           Set<byte[]> byteKeys = jedis.keys(redisShiroSession.getBytes());  
           if (byteKeys != null && byteKeys.size() > 0) {  
               for (byte[] bs : byteKeys) {  
               	Session obj = SerializeUtil.deserialize(jedis.get(bs),  
                   		 Session.class);  
                    if(obj instanceof Session){
                   	 sessions.add(obj);  
                    }
               }  
           }  
       } catch (Exception e) {
           throw e;
       } finally {
       	if(null != jedis)
       	{
       		jedis.close();
       	}
       }
       return sessions;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:35,代码来源:RedisManager.java

示例14: getAllKeys

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public Set<String> getAllKeys() {
    Jedis jedis = null;

    Set var2;
    try {
        jedis = pool.getResource();
        var2 = jedis.keys("*");
    } catch (Exception var6) {
        throw new RuntimeException(var6);
    } finally {
        pool.returnResourceObject(jedis);
    }

    return var2;
}
 
开发者ID:bitstd,项目名称:bitstd,代码行数:16,代码来源:RedisCacheWithoutCluster.java

示例15: keys

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public Set<String> keys(String pattern) {
    Jedis jedis = null;
    Set<String> res = null;
    try {
        jedis = pool.getResource();
        res = jedis.keys(pattern);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
开发者ID:wxiaoqi,项目名称:ace-cache,代码行数:16,代码来源:RedisServiceImpl.java


注:本文中的redis.clients.jedis.Jedis.keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。