本文整理汇总了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");
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
}
示例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();
}
示例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));
}
示例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();
}
示例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());
}
示例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");
}
示例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();
}
示例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;
}
}
}
示例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);
}