Java Code Examples for redis.clients.jedis.Jedis#lpush()
The following examples show how to use
redis.clients.jedis.Jedis#lpush() .
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: JedisSingleDemo.java From Redis-4.x-Cookbook with MIT License | 8 votes |
public static void main(String[] args) { //Connecting to localhost Redis server Jedis jedis = new Jedis("localhost"); //String operations String restaurant = "Extreme Pizza"; jedis.set(restaurant, "300 Broadway, New York, NY"); jedis.append(restaurant, " 10011"); String address = jedis.get("Extreme Pizza"); System.out.printf("Address for %s is %s\n", restaurant, address); //List operations String listKey = "favorite_restaurants"; jedis.lpush(listKey, "PF Chang's", "Olive Garden"); jedis.rpush(listKey, "Outback Steakhouse", "Red Lobster"); List<String> favoriteRestaurants = jedis.lrange(listKey, 0, -1); System.out.printf("Favorite Restaurants: %s\n", favoriteRestaurants); System.exit(0); }
Example 2
Source File: JedisUtil.java From newblog with Apache License 2.0 | 6 votes |
public void lpush(String key, String ele) { Jedis jedis = null; try { jedis = getJedis(); if (jedis == null) { logger.error("get jedis failed."); } jedis.lpush(key, ele); } catch (JedisConnectionException e) { if (jedis != null) { jedis.close(); jedis = null; } logger.error("increame connect error:", e); } finally { returnJedisResource(jedis); } }
Example 3
Source File: RedisSentinelTest.java From cachecloud with Apache License 2.0 | 6 votes |
@Test public void testSentinel() { JedisSentinelPool sentinelPool = ClientBuilder.redisSentinel(appId) .setConnectionTimeout(2000) .setSoTimeout(1000) .build(); HostAndPort currentHostMaster = sentinelPool.getCurrentHostMaster(); logger.info("current master: {}", currentHostMaster.toString()); Jedis jedis = sentinelPool.getResource(); for (int i = 0; i < 10; i++) { jedis.lpush("mylist", "list-" + i); } jedis.close(); sentinelPool.destroy(); }
Example 4
Source File: RedisMessageQueue.java From framework with Apache License 2.0 | 6 votes |
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param key * @param value <br> */ @Override public void push(final String key, final byte[] value) { Jedis jedis = null; try { jedis = RedisClientFactory.getJedisPool().getResource(); jedis.lpush(key.getBytes(), value); } catch (Exception e) { throw new UtilException(ErrorCodeDef.CACHE_ERROR_10002, e); } finally { if (jedis != null) { jedis.close(); } } }
Example 5
Source File: JedisScoredQueueStore.java From vscrawler with Apache License 2.0 | 6 votes |
@Override public boolean addFirst(String queueID, ResourceItem e) { Jedis jedis = null; if (!lockQueue(queueID)) { return false; } try { remove(queueID, e.getKey()); jedis = jedisPool.getResource(); jedis.lpush(makePoolQueueKey(queueID), e.getKey()); jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e)); } finally { IOUtils.closeQuietly(jedis); unLockQueue(queueID); } return true; }
Example 6
Source File: RedisServiceImpl.java From ace-cache with Apache License 2.0 | 5 votes |
@Override public Long lpush(String key, String... strs) { Jedis jedis = null; Long res = null; try { jedis = pool.getResource(); res = jedis.lpush(key, strs); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { returnResource(pool, jedis); } return res; }
Example 7
Source File: RedisUtil.java From zheng with MIT License | 5 votes |
/** * lpush * @param key * @param key */ public synchronized static void lpush(String key, String... strings) { try { Jedis jedis = RedisUtil.getJedis(); jedis.lpush(key, strings); jedis.close(); } catch (Exception e) { LOGGER.error("lpush error : " + e); } }
Example 8
Source File: RedisUtil.java From zhcc-server with Apache License 2.0 | 5 votes |
/** * lpush * @param key * @param key */ public synchronized static void lpush(String key, String... strings) { try { Jedis jedis = RedisUtil.getJedis(); jedis.lpush(key, strings); jedis.close(); } catch (Exception e) { LOGGER.error("lpush error : " + e); } }
Example 9
Source File: RedisClient.java From Mykit with Apache License 2.0 | 5 votes |
/** * 该方法不适用于普通的调用,该方法只针对于错误日志记录 * * @param key * @param field */ public void lpushForErrorMsg(String key, String field) { Jedis client = jedisPool.getResource(); try { if (client.llen(key) > 1000) { return; } client.lpush(key, field); } finally { // 向连接池“归还”资源 jedisPool.returnResourceObject(client); } }
Example 10
Source File: RedisSockjsClient.java From slime with MIT License | 5 votes |
public static void PUBLISH(String address, JsonObject msg) { msg.put("address", address); Jedis jedis = null; try { jedis = JedisConnectionPool.getJedisConnection(); jedis.lpush(RedisKeyStore.PUBLISH.getMaster(), msg.toString()); } catch (Exception e) { e.printStackTrace(); } finally { if (jedis != null) JedisConnectionPool.close(jedis); } }
Example 11
Source File: RedisClient.java From Mykit with Apache License 2.0 | 5 votes |
/** * * * @param key * @param field */ public void lpush(String key, String field) { Jedis client = jedisPool.getResource(); try { client.lpush(key, field); } finally { // 向连接池“归还”资源 jedisPool.returnResourceObject(client); } }
Example 12
Source File: RedisPoolUtil.java From seconds-kill with MIT License | 5 votes |
/** * List - put 操作 */ public static Long listPut(String key, String count, String sale, String version) { Jedis jedis = null; Long result = null; try { jedis = RedisPool.getJedis(); result = jedis.lpush(key, version, sale, count); } catch (Exception e) { log.error("listPut key:{} error", key, e); } finally { RedisPool.jedisPoolClose(jedis); } return result; }
Example 13
Source File: DoTestJedisHookProxy.java From uavstack with Apache License 2.0 | 5 votes |
private static void foo2() { System.out.println("TEST JedisPool ======================================================"); JedisPoolConfig cfg = new JedisPoolConfig(); cfg.setMaxTotal(5); cfg.setMaxIdle(1); cfg.setMaxWaitMillis(10000L); JedisPool jp = new JedisPool(cfg, ip, port); Jedis jedis = jp.getResource(); jedis.set("foo", "bar"); // jedis.close(); jedis = jp.getResource(); jedis.get("foo"); // jedis.close(); jedis = jp.getResource(); jedis.lpush("lll", "a"); jedis.lpush("lll", "b"); jedis.lpush("lll", "c"); jedis.lpop("lll"); jedis.lpop("lll"); jedis.lpop("lll"); // jedis.close(); jedis = jp.getResource(); jedis.hset("mmm", "abc", "123"); jedis.hset("mmm", "def", "456"); jedis.hgetAll("mmm"); jp.close(); }
Example 14
Source File: SingleRedis.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override public void lpush(String queueName, byte[] data) throws MQRedisException { Jedis jedis = this.jedisPool.getResource(); try { jedis.lpush(SafeEncoder.encode(queueName), data); } catch (Exception e) { commandLog.error("mq lpush error", e); throw new MQRedisException(e); } finally { if (jedis != null) { jedis.close(); } } }
Example 15
Source File: RedisPerformanceTest.java From yahoo-streaming-benchmark with Apache License 2.0 | 4 votes |
/** * Very simple test to see how fast Redis can go */ public static void main(String[] args) { Jedis flush_jedis = new Jedis("localhost"); flush_jedis.select(1); List<String> campaigns = new ArrayList<String>(); for (int i = 0; i < 100; i++) { campaigns.add(UUID.randomUUID().toString()); } long campaignUpdates = 0; //long redisOps = 0; //long lastLog = -1; //long lastElements = 0; // log number of redis operations StandaloneThroughputLogger stl = new StandaloneThroughputLogger(150000); while (true) { for (String campaign : campaigns) { campaignUpdates++; long now = System.currentTimeMillis(); stl.observe(now); if (campaignUpdates % 50000 == 0) { System.out.println("Updated " + campaignUpdates + " windows. Redis ops: " + stl.getObservations()); } String timestamp = Long.toString(now % 10000); String windowUUID = flush_jedis.hmget(campaign, timestamp).get(0); stl.observe(now); if (windowUUID == null) { windowUUID = UUID.randomUUID().toString(); flush_jedis.hset(campaign, timestamp, windowUUID); stl.observe(now); String windowListUUID = flush_jedis.hmget(campaign, "windows").get(0); stl.observe(now); if (windowListUUID == null) { windowListUUID = UUID.randomUUID().toString(); flush_jedis.hset(campaign, "windows", windowListUUID); stl.observe(now); } flush_jedis.lpush(windowListUUID, timestamp); stl.observe(now); } flush_jedis.hincrBy(windowUUID, "seen_count", 1 /*use static value here*/); stl.observe(now); flush_jedis.hset(windowUUID, "time_updated", Long.toString(System.currentTimeMillis())); stl.observe(now); flush_jedis.lpush("time_updated", Long.toString(System.currentTimeMillis())); stl.observe(now); } } }
Example 16
Source File: JedisSegmentScoredQueueStore.java From vscrawler with Apache License 2.0 | 4 votes |
@Override public ResourceItem pop(String queueID) { if (!lockQueue(queueID)) { return null; } @Cleanup Jedis jedis = jedisPool.getResource(); try { String sliceQueueKey = makeSliceQueueKey(queueID); String firstResourceKey; String firstSliceID = null; while (true) { String sliceID = jedis.lpop(sliceQueueKey); if (isNil(sliceID)) { // empty queue return null; } if (firstSliceID == null) { firstSliceID = sliceID; } else if (firstSliceID.equals(sliceID)) { // 这个条件下,数据紊乱了? jedis.lpush(sliceQueueKey, firstSliceID); return null; } firstResourceKey = jedis.lpop(makePoolQueueKey(queueID, sliceID)); if (!isNil(firstResourceKey)) { jedis.lpush(sliceQueueKey, sliceID); break; } jedis.rpush(sliceQueueKey, sliceID); } String dataJson = jedis.hget(makeDataKey(queueID), firstResourceKey); if (isNil(dataJson)) { throw new IllegalStateException( "this is no meta data for key queue :" + queueID + " ,for resourceKey :" + firstResourceKey); } jedis.hdel(makeDataKey(queueID), firstResourceKey); return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class); } finally { unLockQueue(queueID); } }
Example 17
Source File: Main.java From JavaBase with MIT License | 4 votes |
private void transferList(String key, Jedis originJedis, Jedis targetJedis) { List<String> data = originJedis.lrange(key, 0, -1); String[] temps = new String[data.size()]; String[] results = data.toArray(temps); targetJedis.lpush(key, results); }
Example 18
Source File: ListOperUtil.java From springboot-learn with MIT License | 3 votes |
public static void oper(Jedis jedis) { Long lpush = jedis.lpush("list", "a", "b", "c"); String list = jedis.lpop("list"); System.out.println("lpush:" + lpush + "---" + list + "---type:" + jedis.type("list")); }
Example 19
Source File: RedisClient.java From springboot-learn with MIT License | 2 votes |
/** * 列表添加 * * @param key * @param values */ public void lPush(String key, String... values) { Jedis jedis = jedisPool.getResource(); jedis.lpush(key, values); }
Example 20
Source File: RedisClient.java From springboot-learn with MIT License | 2 votes |
/** * 列表添加 * * @param key * @param values */ public void lPush(String key, String... values) { Jedis jedis = jedisPool.getResource(); jedis.lpush(key, values); }