本文整理匯總了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");
}