當前位置: 首頁>>代碼示例>>Java>>正文


Java Pipeline.incr方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Pipeline.incr方法的典型用法代碼示例。如果您正苦於以下問題:Java Pipeline.incr方法的具體用法?Java Pipeline.incr怎麽用?Java Pipeline.incr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Pipeline的用法示例。


在下文中一共展示了Pipeline.incr方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testEvalKeyAndArg

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testEvalKeyAndArg() {
  String key = "test";
  String arg = "3";
  String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";

  Pipeline p = jedis.pipelined();
  p.set(key, "0");
  Response<Object> result0 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
  p.incr(key);
  Response<Object> result1 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
  Response<String> result2 = p.get(key);
  p.sync();

  assertNull(result0.get());
  assertNull(result1.get());
  assertEquals("13", result2.get());
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:19,代碼來源:PipeliningTest.java

示例2: testEvalKeyAndArgWithBinary

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testEvalKeyAndArgWithBinary() {
  // binary
  byte[] bKey = SafeEncoder.encode("test");
  byte[] bArg = SafeEncoder.encode("3");
  byte[] bScript = SafeEncoder
      .encode("redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])");

  Pipeline bP = jedis.pipelined();
  bP.set(bKey, SafeEncoder.encode("0"));
  Response<Object> bResult0 = bP.eval(bScript, Arrays.asList(bKey), Arrays.asList(bArg));
  bP.incr(bKey);
  Response<Object> bResult1 = bP.eval(bScript, Arrays.asList(bKey), Arrays.asList(bArg));
  Response<byte[]> bResult2 = bP.get(bKey);
  bP.sync();

  assertNull(bResult0.get());
  assertNull(bResult1.get());
  assertArrayEquals(SafeEncoder.encode("13"), bResult2.get());
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:21,代碼來源:PipeliningTest.java

示例3: testEvalshaKeyAndArg

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testEvalshaKeyAndArg() {
  String key = "test";
  String arg = "3";
  String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
  String sha1 = jedis.scriptLoad(script);

  assertTrue(jedis.scriptExists(sha1));

  Pipeline p = jedis.pipelined();
  p.set(key, "0");
  Response<Object> result0 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
  p.incr(key);
  Response<Object> result1 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
  Response<String> result2 = p.get(key);
  p.sync();

  assertNull(result0.get());
  assertNull(result1.get());
  assertEquals("13", result2.get());
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:22,代碼來源:PipeliningTest.java

示例4: testEvalshaKeyAndArgWithBinary

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testEvalshaKeyAndArgWithBinary() {
  byte[] bKey = SafeEncoder.encode("test");
  byte[] bArg = SafeEncoder.encode("3");
  String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
  byte[] bScript = SafeEncoder.encode(script);
  byte[] bSha1 = jedis.scriptLoad(bScript);

  assertTrue(jedis.scriptExists(bSha1) == 1);

  Pipeline p = jedis.pipelined();
  p.set(bKey, SafeEncoder.encode("0"));
  Response<Object> result0 = p.evalsha(bSha1, Arrays.asList(bKey), Arrays.asList(bArg));
  p.incr(bKey);
  Response<Object> result1 = p.evalsha(bSha1, Arrays.asList(bKey), Arrays.asList(bArg));
  Response<byte[]> result2 = p.get(bKey);
  p.sync();

  assertNull(result0.get());
  assertNull(result1.get());
  assertArrayEquals(SafeEncoder.encode("13"), result2.get());
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:23,代碼來源:PipeliningTest.java

示例5: jedisIncr

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void jedisIncr(String key, int times) {
    Jedis jedis = null;
    boolean isBroken = false;
    try {
        jedis = jedisPool.getResource();
        Pipeline pipeline = jedis.pipelined();
        pipeline.set(key, "1");
        for (int i = 0; i < times; i++) {
            pipeline.incr(key);
        }
        Response<String> response = pipeline.get(key);
        pipeline.sync();
        LOGGER.info(response.get());
        jedis.del(key);
    } catch (Exception e) {
        isBroken = true;
    } finally {
        release(jedis, isBroken);
    }
}
 
開發者ID:fangzy,項目名稱:spring-redis-plugin,代碼行數:21,代碼來源:JedisTest.java

示例6: incr

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Redis
public void incr(String key, int times) {
    Pipeline pipeline = jedis.pipelined();
    pipeline.set(key, "1");
    for (int i = 0; i < times; i++) {
        pipeline.incr(key + i);
    }
    Response<String> response = pipeline.get(key + 1);
    pipeline.sync();
    LOGGER.info(response.get());
    jedis.del(key);
}
 
開發者ID:fangzy,項目名稱:spring-redis-plugin,代碼行數:13,代碼來源:JedisServiceDemo.java

示例7: handle

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public FullHttpResponse handle(HttpRequest httpRequest,
                               Map<String, List<String>> params, ByteBuf byteBuf) {

    String requestJson = byteBuf.toString(Charset.forName("UTF-8"));
    if (requestJson.isEmpty()) {
        return StaticResponse.EMPTY_REQUEST.copy();

    }
    if (!requestJson.contains("{")) {
        return StaticResponse.MALFORMED_JSON.copy();

    }
    String token = "";
    if (httpRequest.headers().contains("Access-Token"))
        token = httpRequest.headers().get("Access-Token");
    if (params.containsKey("access_token"))
        token = params.get("access_token").get(0);

    if (!LoadDB.check_token(token)) {
        return (StaticResponse.INVALID_ACCESS_TOKEN.copy());
    }
    String cart_id = parse(requestJson);
    if (!cart_id.contains(token)) {
        if (LoadDB.user_map.containsKey(new StringBuffer(token).reverse().toString()))
            return (StaticResponse.NOT_AUTHORIZED_TO_ACCESS_CART.copy());
        else
            return (StaticResponse.CART_NOT_FOUND.copy());
    }

    //todo use lua
    Jedis jedis = Redispipe.getJedis();
    Pipeline pipeline = jedis.pipelined();
    pipeline.incr(token + "_");
    pipeline.get(token);
    pipeline.append(token, cart_id);
    pipeline.get(cart_id);
    List<Object> response = pipeline.syncAndReturnAll();
    if (!response.get(0).equals(new Long(1))) {

        if (response.get(1) != null) jedis.set(token, (String) response.get(1));
        else jedis.del(token);

        Redispipe.returnJedis(jedis);
        return (StaticResponse.ORDER_OUT_OF_LIMIT.copy());
    }


    String card_foods = (String) response.get(3);
    int food_id = 0;
    boolean order = true;
    for (int i = 0; i < card_foods.length(); i++) {
        food_id = food_id * 10 + (card_foods.charAt(i) - '0');
        if (i % 3 == 2) {
            order = order && Stock.setStock(food_id, -1);
            food_id = 0;
        }

    }

    if (!order) {
        if (response.get(1) != null) jedis.set(token, (String) response.get(1));
        else jedis.del(token);
        Redispipe.returnJedis(jedis);
        return (StaticResponse.FOOD_OUT_OF_STOCK.copy());

    }
    Redispipe.returnJedis(jedis);
    return (httpResponse(getJson_200(cart_id)));


}
 
開發者ID:eleme,項目名稱:hackathon-2015,代碼行數:73,代碼來源:MakeOrderHandler.java


注:本文中的redis.clients.jedis.Pipeline.incr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。