本文整理汇总了Java中redis.clients.jedis.Pipeline.syncAndReturnAll方法的典型用法代码示例。如果您正苦于以下问题:Java Pipeline.syncAndReturnAll方法的具体用法?Java Pipeline.syncAndReturnAll怎么用?Java Pipeline.syncAndReturnAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Pipeline
的用法示例。
在下文中一共展示了Pipeline.syncAndReturnAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: scheduleMulti
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* Add multiple jobs to the TimeBasedJobScheduler, using a pipeline command to avoid O(n) network round trips.
* Note that this implementation does not support quiescence.
* @see #schedule(String, String, long, long)
*
* @param tube Used in conjunction with the redisPrefixKey (constructor) to make up the full redis key name.
* @param jobStrs String representations of the jobs to be scheduled
* @param millisInFuture The "priority" of the job in terms of the number of millis in the future that this job should become available.
* @return number of newly scheduled jobs
*/
public int scheduleMulti(final String tube, final Iterable<String> jobStrs, final long millisInFuture) {
try (Handle handle = rdbi.open()) {
final Pipeline pl = handle.jedis().pipelined();
for (String jobStr : jobStrs) {
pl.zadd(getReadyQueue(tube),
Instant.now().getMillis() + millisInFuture,
jobStr);
}
int numAdded = 0;
for (Object rslt : pl.syncAndReturnAll()) {
numAdded += (Long) rslt;
}
return numAdded;
}
}
示例3: execute
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public List<Entry> execute() {
Jedis conn = pool.getResource();
Pipeline pipe = conn.pipelined();
String tmpKey = root.execute(pipe);
pipe.zrevrangeWithScores(tmpKey, query.sort.offset, query.sort.offset + query.sort.limit);
List<Object> res = pipe.syncAndReturnAll();
conn.close();
Set<Tuple> ids = (Set<Tuple>) res.get(res.size() - 1);
List<Entry> entries = new ArrayList<>(ids.size());
for (Tuple t : ids) {
entries.add(new Entry(t.getElement(), t.getScore()));
}
return entries;
}
示例4: testSyncWithNoCommandQueued
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testSyncWithNoCommandQueued() {
// we need to test with fresh instance of Jedis
Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
Pipeline pipeline = jedis2.pipelined();
pipeline.sync();
jedis2.close();
jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
pipeline = jedis2.pipelined();
List<Object> resp = pipeline.syncAndReturnAll();
assertTrue(resp.isEmpty());
jedis2.close();
}
示例5: hashMultiGet
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public List<String> hashMultiGet(String[] mapNames, String[] fieldNames) {
if (mapNames.length != fieldNames.length) {
throw new IllegalArgumentException(
"List of map names and list of field names must have same number of elements!");
}
Pipeline p = redisClient.pipelined();
for (int i = 0; i < mapNames.length; i++) {
String mapName = mapNames[i];
String fieldName = fieldNames[i];
p.hget(mapName, fieldName);
}
List<?> result = p.syncAndReturnAll();
return (List<String>) result;
}
示例6: hashMultiGetAsBinary
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public List<byte[]> hashMultiGetAsBinary(String[] mapNames, String[] fieldNames) {
if (mapNames.length != fieldNames.length) {
throw new IllegalArgumentException(
"List of map names and list of field names must have same number of elements!");
}
Pipeline p = redisClient.pipelined();
for (int i = 0; i < mapNames.length; i++) {
byte[] mapName = SafeEncoder.encode(mapNames[i]);
byte[] fieldName = SafeEncoder.encode(fieldNames[i]);
p.hget(mapName, fieldName);
}
List<?> result = p.syncAndReturnAll();
return (List<byte[]>) result;
}
示例7: 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"));
}
示例8: 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));
}
示例9: multi
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void multi() {
Pipeline p = jedis.pipelined();
p.multi();
Response<Long> r1 = p.hincrBy("a", "f1", -1);
Response<Long> r2 = p.hincrBy("a", "f1", -2);
Response<List<Object>> r3 = p.exec();
List<Object> result = p.syncAndReturnAll();
assertEquals(new Long(-1), r1.get());
assertEquals(new Long(-3), r2.get());
assertEquals(4, result.size());
assertEquals("OK", result.get(0));
assertEquals("QUEUED", result.get(1));
assertEquals("QUEUED", result.get(2));
// 4th result is a list with the results from the multi
@SuppressWarnings("unchecked")
List<Object> multiResult = (List<Object>) result.get(3);
assertEquals(new Long(-1), multiResult.get(0));
assertEquals(new Long(-3), multiResult.get(1));
assertEquals(new Long(-1), r3.get().get(0));
assertEquals(new Long(-3), r3.get().get(1));
}
示例10: 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();
}
}
示例11: testCombPipelineTrans
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void testCombPipelineTrans() {// 0.099秒
Jedis jedis = new Jedis("120.25.241.144", 6379);
jedis.auth("b840fc02d52404542994");
long start = System.currentTimeMillis();
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
for (int i = 0; i < 1000; i++) {
pipeline.set("n" + i, "n" + i);
System.out.println(i);
}
pipeline.exec();
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();
}
}
示例12: 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;
}
}
}
示例13: execute
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* Execute with a call back action with result in pipeline.
*/
public List<Object> execute(PipelineAction pipelineAction) throws JedisException {
Jedis jedis = null;
boolean broken = false;
try {
jedis = jedisPool.getResource();
Pipeline pipeline = jedis.pipelined();
pipelineAction.action(pipeline);
return pipeline.syncAndReturnAll();
} catch (JedisException e) {
broken = handleJedisException(e);
throw e;
} finally {
closeResource(jedis, broken);
}
}
示例14: test3Pipelined
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void test3Pipelined() {
Pipeline pipeline = jedis.pipelined();
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
pipeline.set("p" + i, "p" + i);
}
// System.out.println(pipeline.get("p1000").get());
List<Object> results = pipeline.syncAndReturnAll();
long end = System.currentTimeMillis();
System.out.println("Pipelined SET: " + ((end - start) / 1000.0) + " seconds");
}
示例15: test4combPipelineTrans
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void test4combPipelineTrans() {
long start = System.currentTimeMillis();
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
for (int i = 0; i < 100000; i++) {
pipeline.set("" + i, "" + i);
}
pipeline.exec();
List<Object> results = pipeline.syncAndReturnAll();
long end = System.currentTimeMillis();
System.out.println("Pipelined transaction: " + ((end - start) / 1000.0) + " seconds");
}