本文整理汇总了Java中redis.clients.jedis.Pipeline类的典型用法代码示例。如果您正苦于以下问题:Java Pipeline类的具体用法?Java Pipeline怎么用?Java Pipeline使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pipeline类属于redis.clients.jedis包,在下文中一共展示了Pipeline类的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: testCloseSyncs
import redis.clients.jedis.Pipeline; //导入依赖的package包/类
@Test
public void testCloseSyncs() 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.close();
assertEquals(1, (long) added.get());
pipelineSnapshot.validate();
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例9: 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;
}
示例10: 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;
}
示例11: getAll
import redis.clients.jedis.Pipeline; //导入依赖的package包/类
private List<Map<String, String>> getAll(final List<String> keys) {
try {
return localCacheOfRedisData.get(keys.hashCode() + "", new Callable<List<Map<String, String>>>() {
@Override
public List<Map<String, String>> call() throws Exception {
return redisConfig.execute(new RedisCallback<List<Map<String, String>>>() {
@Override
public List<Map<String, String>> call(Jedis jedis) {
Pipeline pipeline = jedis.pipelined();
for (String key : keys) {
pipeline.hgetAll(key);
}
List result = pipeline.syncAndReturnAll();
return result;
}
});
}
});
} catch (Exception e) {
LOGGER.error(keys.toString(), e);
}
return new ArrayList<>();
}
示例12: updateKafkaLogEvent
import redis.clients.jedis.Pipeline; //导入依赖的package包/类
public static boolean updateKafkaLogEvent(int unixtime, final String event){
Date date = new Date(unixtime*1000L);
final String dateStr = DateTimeUtil.formatDate(date ,DATE_FORMAT_PATTERN);
final String dateHourStr = DateTimeUtil.formatDate(date ,YYYY_MM_DD_HH);
boolean commited = new RedisCommand<Boolean>(jedisPool) {
@Override
protected Boolean build() throws JedisException {
String keyD = MONITOR_PREFIX+dateStr;
String keyH = MONITOR_PREFIX+dateHourStr;
Pipeline p = jedis.pipelined();
p.hincrBy(keyD, "e:"+event , 1L);
p.expire(keyD, AFTER_4_DAYS);
p.hincrBy(keyH, "e:"+event , 1L);
p.expire(keyH, AFTER_2_DAYS);
p.sync();
return true;
}
}.execute();
return commited;
}
示例13: updateMonitorEvent
import redis.clients.jedis.Pipeline; //导入依赖的package包/类
public static boolean updateMonitorEvent(int unixtime, final String event){
Date date = new Date(unixtime*1000L);
final String dateStr = DateTimeUtil.formatDate(date ,DATE_FORMAT_PATTERN);
final String dateHourStr = DateTimeUtil.formatDate(date ,YYYY_MM_DD_HH);
boolean commited = new RedisCommand<Boolean>(jedisPool) {
@Override
protected Boolean build() throws JedisException {
String keyD = MONITOR_PREFIX+dateStr;
String keyH = MONITOR_PREFIX+dateHourStr;
Pipeline p = jedis.pipelined();
p.hincrBy(keyD, event , 1L);
p.expire(keyD, AFTER_2_DAYS);
p.hincrBy(keyH, event , 1L);
p.expire(keyH, AFTER_1_DAY);
p.sync();
return true;
}
}.execute();
return commited;
}
示例14: addUser
import redis.clients.jedis.Pipeline; //导入依赖的package包/类
public static boolean addUser(String keyPrefix, int unixTime, String metric, final String uuid) {
Date date = new Date(unixTime*1000L);
final String dateStr = DateTimeUtil.formatDate(date, DateTimeUtil.DATE_FORMAT_PATTERN);
return new RedisCommand<Boolean>(redisAdDataStats) {
@Override
protected Boolean build() throws JedisException {
Pipeline p = jedis.pipelined();
String keyTotal = keyPrefix+"t";
String keyDaily = keyPrefix+dateStr+":t";
String keyHourly = keyPrefix+dateStr+":"+metric;
p.pfadd(keyTotal, uuid);
p.pfadd(keyDaily, uuid);
p.pfadd(keyHourly, uuid);
p.expire(keyDaily, AFTER_7_DAYS);
p.expire(keyHourly, AFTER_3_DAYS);
p.sync();
return true;
}
}.execute();
}
示例15: 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);
}
}