Java Code Examples for redis.clients.jedis.Jedis#select()
The following examples show how to use
redis.clients.jedis.Jedis#select() .
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: JedisUtils.java From fw-spring-cloud with Apache License 2.0 | 6 votes |
/** * <p> * 通过key获取list指定下标位置的value * </p> * <p> * 如果start 为 0 end 为 -1 则返回全部的list中的value * </p> * * @param key * @param start * @param end * @return */ public List<String> lrange(String key, long start, long end, int indexdb) { Jedis jedis = null; List<String> res = null; try { jedis = jedisPool.getResource(); jedis.select(indexdb); res = jedis.lrange(key, start, end); } catch (Exception e) { log.error(e.getMessage()); } finally { returnResource(jedisPool, jedis); } return res; }
Example 2
Source File: RedisHttpClient.java From slime with MIT License | 6 votes |
public static void pingDaemonServer() { Jedis jedis = null; try { jedis = JedisConnectionPool.getJedisConnection(); jedis.select(10); JsonObject status = new JsonObject(); status.put("status", true); status.put("time", System.currentTimeMillis()); jedis.hset(RedisKeyStore.HTTP.getMaster(), serverKey, status.toString()); jedis.zadd(RedisKeyStore.HTTP + ":STATUS", 0, serverKey); } catch (Exception e) { e.printStackTrace(); } finally { if (jedis != null) JedisConnectionPool.close(jedis); } }
Example 3
Source File: LockServiceRedisImpl.java From redis_util with Apache License 2.0 | 6 votes |
public boolean unLock(String key, String value) { Long RELEASE_SUCCESS = 1L; Jedis jedis = null; try { jedis = redisConnection.getJedis(); jedis.select(dbIndex); key = KEY_PRE + key; String command = "if redis.call('get',KEYS[1])==ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end"; if (RELEASE_SUCCESS.equals(jedis.eval(command, Collections.singletonList(key), Collections.singletonList(value)))) { return true; } } catch (Exception e) { e.printStackTrace(); } finally { if (jedis != null) { jedis.close(); } } return false; }
Example 4
Source File: JedisCache.java From charging_pile_cloud with MIT License | 6 votes |
/** * 设置超时时间 * * @param dbIndex * @param key * @param unixTime * @return */ public static String expireAt(int dbIndex, String key, int unixTime) { String result = null; Jedis jedis = null; try { jedis = jedisManager.getJedis(); jedis.select(dbIndex); result = String.valueOf(jedis.expireAt(key, unixTime)); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { jedis.close(); } return result; }
Example 5
Source File: JedisCache.java From charging_pile_cloud with MIT License | 6 votes |
public static String deleteHashValue(int dbIndex, String key, String field) { String result = null; Jedis jedis = null; try { jedis = jedisManager.getJedis(); jedis.select(dbIndex); result = jedis.hdel(key, field).toString(); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { jedis.close(); } return result; }
Example 6
Source File: CacheServiceRedisImpl.java From redis_util with Apache License 2.0 | 6 votes |
public Long ttl(String key) { log.trace("get set expire " + key); Jedis jedis = null; try { jedis = redisConnection.getJedis(); jedis.select(dbIndex); return jedis.ttl(key); } catch (Exception e) { log.warn(e.getMessage(), e); } finally { if (jedis != null) { jedis.close(); } } return -2L; }
Example 7
Source File: CacheServiceRedisImpl.java From redis_util with Apache License 2.0 | 6 votes |
public boolean delObject(String key) { log.trace("strar delete cache with " + key); Jedis jedis = null; try { jedis = redisConnection.getJedis(); jedis.select(dbIndex); return jedis.del(key.getBytes()) > 0; } catch (Exception e) { log.warn(e.getMessage(), e); } finally { if (jedis != null) { jedis.close(); } } return false; }
Example 8
Source File: JedisCache.java From charging_pile_cloud with MIT License | 5 votes |
public static Set<String> getAll(int dbIndex, String pattern) { Set<String> result = null; Jedis jedis = null; try { jedis = jedisManager.getJedis(); jedis.select(dbIndex); result = jedis.keys(pattern); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { jedis.close(); } return result; }
Example 9
Source File: CacheServiceRedisImpl.java From redis_util with Apache License 2.0 | 5 votes |
public void clearObject() { Jedis jedis = null; try { jedis = redisConnection.getJedis(); jedis.select(dbIndex); jedis.flushDB(); } catch (Exception e) { log.warn(e.getMessage(), e); } finally { if (jedis != null) { jedis.close(); } } }
Example 10
Source File: Main.java From JavaBase with MIT License | 5 votes |
/** * get keys */ private Set<String> getKeys(RedisPools pool, RedisPoolProperty property, int database) { Optional<Jedis> jedisOpt = pool.getJedis(property); if (!jedisOpt.isPresent()) { return new HashSet<>(0); } Jedis jedis = jedisOpt.get(); jedis.select(database); return jedis.keys("*"); }
Example 11
Source File: JedisPoolTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test public void startWithUrlString() { Jedis j = new Jedis("localhost", 6380); j.auth("foobared"); j.select(2); j.set("foo", "bar"); JedisPool pool = new JedisPool("redis://:foobared@localhost:6380/2"); Jedis jedis = pool.getResource(); assertEquals("PONG", jedis.ping()); assertEquals("bar", jedis.get("foo")); }
Example 12
Source File: RedisClientImpl.java From khan-session with GNU Lesser General Public License v2.1 | 5 votes |
@Override public <T> boolean loginContains(String key) throws IOException { Jedis jedis = pool.getResource(); try { jedis.select(redisServer.getDatabase()+1); return jedis.exists(key); } finally { pool.returnResource(jedis); } }
Example 13
Source File: RedisClientImpl.java From khan-session with GNU Lesser General Public License v2.1 | 5 votes |
@Override public <T> T loginGet(String key) throws IOException { Jedis jedis = pool.getResource(); try { jedis.select(redisServer.getDatabase()+1); return (T) marshaller.objectFromByteBuffer(jedis.get(key.getBytes())); } finally { pool.returnResource(jedis); } }
Example 14
Source File: JedisUtils.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
/** * <p> * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。 * </p> * * @param key * @param value * 过期时间,单位:秒 * @return 成功返回1 如果存在 和 发生异常 返回 0 */ public Long expire(String key, int value, int indexdb) { Jedis jedis = null; try { jedis = jedisPool.getResource(); jedis.select(indexdb); return jedis.expire(key, value); } catch (Exception e) { log.error(e.getMessage()); return 0L; } finally { returnResource(jedisPool, jedis); } }
Example 15
Source File: RedisClientImpl.java From khan-session with GNU Lesser General Public License v2.1 | 5 votes |
@Override public <T> void loginDelete(String key) throws IOException { Jedis jedis = pool.getResource(); try { jedis.select(redisServer.getDatabase()+1); jedis.del(key.getBytes()); } finally { pool.returnResource(jedis); } }
Example 16
Source File: JedisUtils.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
/** * <p> * 删除指定的key,也可以传入一个包含key的数组 * </p> * @param indexdb 选择redis库 0-15 * @param keys 一个key 也可以使 string 数组 * @return 返回删除成功的个数 */ public Long del(int indexdb,String... keys) { Jedis jedis = null; try { jedis = jedisPool.getResource(); jedis.select(indexdb); return jedis.del(keys); } catch (Exception e) { log.error(e.getMessage()); return 0L; } finally { returnResource(jedisPool, jedis); } }
Example 17
Source File: RedisClientImpl.java From khan-session with GNU Lesser General Public License v2.1 | 5 votes |
@Override @SuppressWarnings("unchecked") public <T> T get(String key) throws IOException { //logger.debug("@@@@@@@@@@@@@ cache.size=" + cache.size()); Jedis jedis = pool.getResource(); try { jedis.select(redisServer.getDatabase()); return (T) marshaller.objectFromByteBuffer(jedis.get(key.getBytes())); } finally { pool.returnResource(jedis); } //return (T) cache.get(key); }
Example 18
Source File: JedisCache.java From charging_pile_cloud with MIT License | 5 votes |
public static long delete(int dbIndex, String key) { long result = -1; Jedis jedis = null; try { jedis = jedisManager.getJedis(); jedis.select(dbIndex); result = jedis.del(key); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { jedis.close(); } return result; }
Example 19
Source File: JedisPoolPack.java From litchi with Apache License 2.0 | 5 votes |
public Jedis getJedis(int dbIndex) { Jedis jedis = getJedisPool().getResource(); if (jedis.getDB() != dbIndex) { jedis.select(dbIndex); } return jedis; }
Example 20
Source File: JedisCache.java From charging_pile_cloud with MIT License | 5 votes |
public static String getStr(int dbIndex, String key) { String result = null; Jedis jedis = null; try { jedis = jedisManager.getJedis(); jedis.select(dbIndex); result = jedis.get(key); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { jedis.close(); } return result; }