本文整理汇总了Java中redis.clients.jedis.Pipeline.sync方法的典型用法代码示例。如果您正苦于以下问题:Java Pipeline.sync方法的具体用法?Java Pipeline.sync怎么用?Java Pipeline.sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Pipeline
的用法示例。
在下文中一共展示了Pipeline.sync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rename
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
long blockSize = 0;
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Pipeline pipelined = jedis.pipelined();
//add new file length
pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
//add new file content
blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
}
values.clear();
pipelined.sync();
} finally {
jedis.close();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
}
示例2: deleteFile
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
* Use transactions to delete index file
*
* @param fileLengthKey
* @param fileDataKey
* @param field
* @param blockSize
*/
@Override
public void deleteFile(String fileLengthKey, String fileDataKey, String field, long blockSize) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Pipeline pipelined = jedis.pipelined();
//delete file length
pipelined.hdel(fileLengthKey.getBytes(), field.getBytes());
//delete file content
for (int i = 0; i < blockSize; i++) {
byte[] blockName = getBlockName(field, i);
pipelined.hdel(fileDataKey.getBytes(), blockName);
}
pipelined.sync();
} finally {
jedis.close();
}
}
示例3: saveFile
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Pipeline pipelined = jedis.pipelined();
pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
if (i % Constants.SYNC_COUNT == 0) {
pipelined.sync();
pipelined = jedis.pipelined();
}
}
values.clear();
pipelined.sync();
} finally {
jedis.close();
}
}
示例4: rename
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
Jedis jedis = openJedis();
Pipeline pipelined = jedis.pipelined();
//add new file length
pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
//add new file content
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
}
pipelined.sync();
jedis.close();
values.clear();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
示例5: saveFile
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
Jedis jedis = openJedis();
Pipeline pipelined = jedis.pipelined();
pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
if (i % Constants.SYNC_COUNT == 0) {
pipelined.sync();
pipelined = jedis.pipelined();
}
}
pipelined.sync();
jedis.close();
values.clear();
}
示例6: 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");
}
示例7: testSync
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testSync() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Pipeline pipeline = jedis.pipelined();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
Snapshot pipelineSnapshot = pipelineTracker.snapshot();
pipelineSnapshot.increment();
Response<Long> added = pipeline.sadd(key, value);
pipeline.sync();
assertEquals(1, (long) added.get());
pipelineSnapshot.validate();
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例8: containsKeys
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public boolean containsKeys(Collection<K> keys) {
if (keys == null || keys.size() == 0) {
return false;
}
// 使用 Redis 提供的管道进行批处理,提高效率
Pipeline pipeline = jedisProxy.pipelined();
Set<Response<Boolean>> responses = new HashSet<Response<Boolean>>(keys.size());
for (K key : keys) {
if (localMapCache != null && localMapCache.containsKey(key)) {
continue;
}
responses.add(pipeline.hexists(SerializeUtil.serialize(getName()), SerializeUtil.serialize(key)));
}
if (responses.size() < 1) {
return true;
}
pipeline.sync();
for (Response<Boolean> response : responses) {
if (!response.get()) {
return false;
}
}
return true;
}
示例9: gets
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public Map<K, V> gets(Collection<K> keys) {
Map<K, V> result = new HashMap<>(keys.size());
Pipeline pipeline = jedisProxy.pipelined();
byte[] keyBytes = SerializeUtil.serialize(getName());
Map<K, Response<byte[]>> responseMap = new HashMap<>(keys.size());
for (K key : keys) {
if (localMapCache != null && localMapCache.containsKey(key)) {
result.put(key, localMapCache.get(key));
continue;
}
responseMap.put(key, pipeline.hget(keyBytes, SerializeUtil.serialize(key)));
}
if (responseMap.size() < 1) {
return result;
}
pipeline.sync();
for (Map.Entry<K, Response<byte[]>> entry : responseMap.entrySet()) {
result.put(entry.getKey(), (V) SerializeUtil.deserialize(entry.getValue().get()));
}
return result;
}
示例10: getAllFromRedis
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
private Table<String, ResourceType, Response<Map<String, String>>> getAllFromRedis(Set<String> userIds) {
if (userIds.size() == 0) {
return HashBasedTable.create();
}
try (Jedis jedis = jedisSource.getJedis()) {
Table<String, ResourceType, Response<Map<String, String>>> responseTable =
ArrayTable.create(userIds, new ArrayIterator<>(ResourceType.values()));
Pipeline p = jedis.pipelined();
for (String userId : userIds) {
for (ResourceType r : ResourceType.values()) {
responseTable.put(userId, r, p.hgetAll(userKey(userId, r)));
}
}
p.sync();
return responseTable;
} catch (Exception e) {
log.error("Storage exception reading all entries.", e);
}
return null;
}
示例11: 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());
}
示例12: pipelineWithTransaction
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void pipelineWithTransaction() {
Jedis jedis = pool.getResource();
try {
Pipeline p = jedis.pipelined();
p.multi();
for (int i = 0; i < rowCount; i++) {
String key = RandomStringUtils.randomAlphabetic(8);
p.set(key, RandomStringUtils.randomNumeric(5));
p.expire(key, 5 * 60);
}
p.exec();
p.sync();
} catch (Exception e) {
pool.returnResource(jedis);
}
}
示例13: remove
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void remove(@NonNull String id) {
try (Jedis jedis = jedisSource.getJedis()) {
Map<String, String> userRolesById = jedis.hgetAll(userKey(id, ResourceType.ROLE));
Pipeline p = jedis.pipelined();
p.srem(allUsersKey(), id);
for (String roleName : userRolesById.keySet()) {
p.srem(roleKey(roleName), id);
}
for (ResourceType r : ResourceType.values()) {
p.del(userKey(id, r));
}
p.sync();
} catch (Exception e) {
log.error("Storage exception reading " + id + " entry.", e);
}
}
示例14: 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();
}
}
}
示例15: 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());
}