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


Java Pipeline.get方法代码示例

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


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

示例1: main

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public static void main(String[] args) throws UnknownHostException, IOException {
  Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
  jedis.connect();
  jedis.auth("foobared");
  jedis.flushAll();

  long begin = Calendar.getInstance().getTimeInMillis();

  Pipeline p = jedis.pipelined();
  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    String key = "foo" + n;
    p.set(key, "bar" + n);
    p.get(key);
  }
  p.sync();

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:23,代码来源:PipelinedGetSetBenchmark.java

示例2: multiWithSync

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void multiWithSync() {
  jedis.set("foo", "314");
  jedis.set("bar", "foo");
  jedis.set("hello", "world");
  Pipeline p = jedis.pipelined();
  Response<String> r1 = p.get("bar");
  p.multi();
  Response<String> r2 = p.get("foo");
  p.exec();
  Response<String> r3 = p.get("hello");
  p.sync();

  // before multi
  assertEquals("foo", r1.get());
  // It should be readable whether exec's response was built or not
  assertEquals("314", r2.get());
  // after multi
  assertEquals("world", r3.get());
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:21,代码来源:PipeliningTest.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: test5

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
private static void test5() {
    System.out.println("Test: [raw/pipeline] single instance");
    Jedis client = new Jedis(HOST);
    long t1 = System.currentTimeMillis();
    try {
        Pipeline p = client.pipelined();
        for (int i = 0; i < NUM_RUNS; i++) {
            p.get(SafeEncoder.encode("DEMO"));
        }
        List<Object> result = p.syncAndReturnAll();
        System.out.println(result);
    } finally {
        client.close();
    }
    long t2 = System.currentTimeMillis();
    System.out.println("Get [" + NUM_RUNS + "] times in " + (t2 - t1) + " ms.");
    System.out.println("Speed: " + ((double) NUM_RUNS * 1000) / (t2 - t1) + " gets/sec");
    System.out.println();
}
 
开发者ID:DDTH,项目名称:ddth-redis,代码行数:20,代码来源:QndTestRedisClient.java

示例9: pipeline

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void pipeline() throws UnsupportedEncodingException {
  Pipeline p = jedis.pipelined();
  p.set("foo", "bar");
  p.get("foo");
  List<Object> results = p.syncAndReturnAll();

  assertEquals(2, results.size());
  assertEquals("OK", results.get(0));
  assertEquals("bar", results.get(1));

}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:13,代码来源:PipeliningTest.java

示例10: pipelineResponseWithinPipeline

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test(expected = JedisDataException.class)
public void pipelineResponseWithinPipeline() {
  jedis.set("string", "foo");

  Pipeline p = jedis.pipelined();
  Response<String> string = p.get("string");
  string.get();
  p.sync();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:10,代码来源:PipeliningTest.java

示例11: canRetrieveUnsetKey

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void canRetrieveUnsetKey() {
  Pipeline p = jedis.pipelined();
  Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
  p.sync();
  assertNull(shouldNotExist.get());
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:8,代码来源:PipeliningTest.java

示例12: piplineWithError

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void piplineWithError() {
  Pipeline p = jedis.pipelined();
  p.set("foo", "bar");
  Response<Set<String>> error = p.smembers("foo");
  Response<String> r = p.get("foo");
  p.sync();
  try {
    error.get();
    fail();
  } catch (JedisDataException e) {
    // that is fine we should be here
  }
  assertEquals(r.get(), "bar");
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:16,代码来源:PipeliningTest.java

示例13: testDiscardInPipeline

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testDiscardInPipeline() {
  Pipeline pipeline = jedis.pipelined();
  pipeline.multi();
  pipeline.set("foo", "bar");
  Response<String> discard = pipeline.discard();
  Response<String> get = pipeline.get("foo");
  pipeline.sync();
  discard.get();
  get.get();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:12,代码来源:PipeliningTest.java

示例14: processElement

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext processContext) throws Exception {
  ScanParams scanParams = new ScanParams();
  scanParams.match(processContext.element());

  String cursor = ScanParams.SCAN_POINTER_START;
  boolean finished = false;
  while (!finished) {
    ScanResult<String> scanResult = jedis.scan(cursor, scanParams);
    List<String> keys = scanResult.getResult();

    Pipeline pipeline = jedis.pipelined();
    if (keys != null) {
      for (String key : keys) {
        pipeline.get(key);
      }
      List<Object> values = pipeline.syncAndReturnAll();
      for (int i = 0; i < values.size(); i++) {
        processContext.output(KV.of(keys.get(i), (String) values.get(i)));
      }
    }

    cursor = scanResult.getStringCursor();
    if (cursor.equals("0")) {
      finished = true;
    }
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:29,代码来源:RedisIO.java

示例15: 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


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