当前位置: 首页>>代码示例>>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;未经允许,请勿转载。