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


Java Pipeline.set方法代碼示例

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


在下文中一共展示了Pipeline.set方法的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: store

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public void store(Document... docs) {

    Jedis conn = pool.getResource();
    Pipeline pipe = conn.pipelined();
    try {
        for (Document doc : docs) {

            String encoded = gson.toJson(doc);
            pipe.set(key(doc.getId()), encoded);

        }
        pipe.sync();
    } finally {
        conn.close();
    }
}
 
開發者ID:RedisLabs,項目名稱:ReSearch,代碼行數:18,代碼來源:JSONStore.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: testCloseable

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testCloseable() throws IOException {
  // we need to test with fresh instance of Jedis
  Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
  jedis2.auth("foobared");

  Pipeline pipeline = jedis2.pipelined();
  Response<String> retFuture1 = pipeline.set("a", "1");
  Response<String> retFuture2 = pipeline.set("b", "2");

  pipeline.close();

  // it shouldn't meet any exception
  retFuture1.get();
  retFuture2.get();
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:17,代碼來源:PipeliningTest.java

示例8: run

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public void run() {
    Thread.currentThread().setName("ConsumerThread-"+topicConfig.getTopic());
    try {
        while (running) {

            ConsumerRecords<String, String> records = consumer.poll(1000);
            logger.info(String.format("poll count:"+records.count()));
            Pipeline jedisPipe = jedis.pipelined();
            for (ConsumerRecord<String, String> record : records) {
                String key = record.key();
                String value = record.value();
                if(key!=null && value!=null) {
                    jedisPipe.set(key,value);
                }
            }
            jedisPipe.sync();
        }
    }finally {
        if (consumer!=null) {
            consumer.close();
        }
    }
}
 
開發者ID:xausky,項目名稱:kafka-consumer-redis,代碼行數:25,代碼來源:ConsumerThread.java

示例9: doUpsertString

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void doUpsertString(Record record, List<ErrorRecord> tempRecords, Pipeline pipeline, String key, Field value)
    throws StageException {
  if (value != null && value.getType() == Field.Type.STRING) {
    String val = value.getValueAsString();
    pipeline.set(key, val);
    tempRecords.add(new ErrorRecord(record, "String", key, val));
  } else {
    LOG.error(Errors.REDIS_04.getMessage(), value.getType(), " value should be String");
    errorRecordHandler.onError(
        new OnRecordErrorException(
            record,
            Errors.REDIS_04,
            value.getType(),
            "value should be String"
        )
    );
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:19,代碼來源:RedisTarget.java

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

示例11: testPipelining

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Pipelining
 * 測試時間:0.287 seconds
 */
@Test
@Ignore
public void testPipelining(){
	Jedis jedis = new Jedis("localhost");
	Pipeline pipeline = jedis.pipelined();
	long start = System.currentTimeMillis();
	for(int i = 0; i< COUNTER; i++){
		pipeline.set("p" + i, "p" + i);
		if(i == 100){
			System.out.println(jedis.get("p1"));
		}
	}
	List<Object> results = pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	logger.info("Pipelined SET: " + ((end - start)/1000.0) + " seconds");
	jedis.close();
	System.out.println("result: " + results.get(0));
	System.out.println(jedis.get("p1"));
}
 
開發者ID:leopardoooo,項目名稱:easyooo-framework,代碼行數:24,代碼來源:JedisApiTest.java

示例12: testResetStateWhenInMultiWithinPipeline

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testResetStateWhenInMultiWithinPipeline() {
  jedis.auth("foobared");

  Pipeline p = jedis.pipelined();
  p.multi();
  p.set("foooo", "barrr");

  jedis.resetState();
  assertEquals(null, jedis.get("foooo"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:12,代碼來源:TransactionCommandsTest.java

示例13: pipelineWithoutTransaction

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public void pipelineWithoutTransaction() {
  Jedis jedis = pool.getResource();
  try {
    Pipeline p = jedis.pipelined();
    for (int i = 0; i < rowCount; i++) {
      String key = RandomStringUtils.randomAlphabetic(8);
      p.set(key, RandomStringUtils.randomNumeric(5));
      p.expire(key, 5 * 60);
    }
    p.sync();
  } catch (Exception e) {
    pool.returnResource(jedis);
  }
}
 
開發者ID:nickevin,項目名稱:Qihua,代碼行數:15,代碼來源:RedisTransactionTest.java

示例14: testPipelined

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public void testPipelined() {// 0.076秒
	Jedis jedis = new Jedis("120.25.241.144", 6379);
	jedis.auth("b840fc02d52404542994");

	long start = System.currentTimeMillis();
	Pipeline pipeline = jedis.pipelined();
	for (int i = 0; i < 1000; i++) {
		pipeline.set("n" + i, "n" + i);
		System.out.println(i);
	}
	pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	System.out.println("共花費:" + (end - start) / 1000.0 + "秒");

	jedis.disconnect();
	try {
		Closeables.close(jedis, true);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:xiangxik,項目名稱:java-platform,代碼行數:22,代碼來源:RedisExample.java

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


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