本文整理汇总了Java中redis.clients.jedis.ShardedJedisPipeline.sync方法的典型用法代码示例。如果您正苦于以下问题:Java ShardedJedisPipeline.sync方法的具体用法?Java ShardedJedisPipeline.sync怎么用?Java ShardedJedisPipeline.sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.ShardedJedisPipeline
的用法示例。
在下文中一共展示了ShardedJedisPipeline.sync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveFile
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
ShardedJedis shardedJedis = getShardedJedis();
ShardedJedisPipeline pipelined = shardedJedis.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 = shardedJedis.pipelined();
}
}
pipelined.sync();
shardedJedis.close();
values.clear();
}
示例2: rename
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
/**
* Use transactions to add index file and then delete the old one
*
* @param fileLengthKey the key using for hash file length
* @param fileDataKey the key using for hash file data
* @param oldField the old hash field
* @param newField the new hash field
* @param values the data values of the old hash field
* @param fileLength the data length of the old hash field
*/
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
ShardedJedis shardedJedis = getShardedJedis();
ShardedJedisPipeline pipelined = shardedJedis.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();
shardedJedis.close();
values.clear();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
示例3: testSyncWithNoCommandQueued
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Test
public void testSyncWithNoCommandQueued() {
JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
shardInfo1.setPassword("foobared");
shardInfo2.setPassword("foobared");
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(shardInfo1);
shards.add(shardInfo2);
ShardedJedis jedis2 = new ShardedJedis(shards);
ShardedJedisPipeline pipeline = jedis2.pipelined();
pipeline.sync();
jedis2.close();
jedis2 = new ShardedJedis(shards);
pipeline = jedis2.pipelined();
List<Object> resp = pipeline.syncAndReturnAll();
assertTrue(resp.isEmpty());
jedis2.close();
}
示例4: get
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public Map<String, String> get(final String... keys) {
Assert.notEmpty(keys);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final ShardedJedisPipeline pipelined = jedis.pipelined();
final Map<String, Response<String>> values = Maps.newHashMap();
for (String key : keys) {
values.put(key, pipelined.get(key));
}
pipelined.sync();
final Map<String, String> valueMap = Maps.newHashMap();
values.forEach((key, response) -> valueMap.put(key, response.get()));
return valueMap;
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
示例5: set
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public Map<String, Boolean> set(final Map<String, Object> map) {
Assert.notEmpty(map);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final ShardedJedisPipeline pipelined = jedis.pipelined();
final Map<String, Response<String>> responses = Maps.newHashMap();
map.forEach((key, value) -> responses.put(key, pipelined.set(key, toJSONString(value))));
pipelined.sync();
final Map<String, Boolean> values = Maps.newHashMap();
responses.forEach((key, response) -> values.put(key, isOK(response.get())));
return values;
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
示例6: setByNX
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public boolean setByNX(final String key, final String value, final int timeout) {
Assert.hasText(key);
Assert.hasText(value);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final ShardedJedisPipeline pipeline = jedis.pipelined();
final Response<Long> set = pipeline.setnx(key, value);
final Response<Long> expire = pipeline.expire(key, timeout);
pipeline.sync();
return isSuccess(set.get()) && isSuccess(expire.get());
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
示例7: hsetByNX
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public Map<String, Boolean> hsetByNX(final String key, final Map<String, Object> map) {
Assert.hasText(key);
Assert.notEmpty(map);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final ShardedJedisPipeline pipeline = jedis.pipelined();
final Map<String, Response<Long>> responses = Maps.newHashMap();
for (Entry<String, Object> entry : map.entrySet()) {
responses.put(entry.getKey(), pipeline.hsetnx(key, entry.getKey(), toJSONString(entry.getValue())));
}
pipeline.sync();
final Map<String, Boolean> values = Maps.newHashMap();
responses.forEach((field, response) -> values.put(field, isSuccess(response.get())));
return values;
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
示例8: lrangeltrim
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public List<String> lrangeltrim(final String key, final int count) {
Assert.hasText(key);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final ShardedJedisPipeline pipeline = jedis.pipelined();
final Response<List<String>> values = pipeline.lrange(key, 0, count);
pipeline.ltrim(key, count + 1, -1);
pipeline.sync();
return values.get();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
示例9: scard
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public Map<String, Long> scard(final String... keys) {
Assert.notEmpty(keys);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final ShardedJedisPipeline pipeline = jedis.pipelined();
final Map<String, Response<Long>> responses = Maps.newHashMap();
for (String key : keys) {
responses.put(key, pipeline.scard(key));
}
pipeline.sync();
final Map<String, Long> values = Maps.newHashMap();
responses.forEach((key, response) -> values.put(key, response.get()));
return values;
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
示例10: deleteFile
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
/**
* Use transactions to delete index file
*
* @param fileLengthKey the key using for hash file length
* @param fileDataKey the key using for hash file data
* @param field the hash field
* @param blockSize the index file data block size
*/
@Override
public void deleteFile(String fileLengthKey, String fileDataKey, String field, long blockSize) {
ShardedJedis shardedJedis = getShardedJedis();
ShardedJedisPipeline pipelined = shardedJedis.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();
shardedJedis.close();
}
示例11: loadFileOnce
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public List<byte[]> loadFileOnce(String fileDataKey, String fileName, long blockSize) {
ShardedJedis shardedJedis = getShardedJedis();
ShardedJedisPipeline pipelined = shardedJedis.pipelined();
List<byte[]> res = new ArrayList<>();
List<Response<byte[]>> temps = new ArrayList<>();
int temp = 0;
//如果不分批次sync容易read time out和Java heap space
while (temp < blockSize) {
Response<byte[]> data = pipelined.hget(fileDataKey.getBytes(), getBlockName(fileName, temp));
temps.add(data);
if (temp % Constants.SYNC_COUNT == 0) {
pipelined.sync();
res.addAll(temps.stream().map(response -> uncompressFilter(response.get())).collect(Collectors.toList()));
temps.clear();
pipelined = shardedJedis.pipelined();
}
temp++;
}
try {
pipelined.sync();
} catch (JedisConnectionException e) {
log.error("pipelined = {}, blockSize = {}!", pipelined.toString(), blockSize);
log.error("", e);
} finally {
shardedJedis.close();
}
res.addAll(temps.stream().map(response -> uncompressFilter(response.get())).collect(Collectors.toList()));
temps.clear();
return res;
}
示例12: pipelineResponseWithinPipeline
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Test(expected = JedisDataException.class)
public void pipelineResponseWithinPipeline() {
jedis.set("string", "foo");
ShardedJedisPipeline p = jedis.pipelined();
Response<String> string = p.get("string");
string.get();
p.sync();
}
示例13: canRetrieveUnsetKey
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Test
public void canRetrieveUnsetKey() {
ShardedJedisPipeline p = jedis.pipelined();
Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
p.sync();
assertNull(shouldNotExist.get());
}
示例14: zaddAndRem
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public int zaddAndRem(String key, double score, String member, int maxLength) {
if (enabled) {
notEmptyKey(key);
ShardedJedis jedis = null;
try {
int newElementNum = 0;
int elementNum = 0;
jedis = shardedJedisPool.getResource();
ShardedJedisPipeline pipeline = jedis.pipelined();
Response<Long> zaddResponse = pipeline.zadd(key, score, member);
Response<Long> zcardResponse = pipeline.zcard(key);
pipeline.sync();
Long zaddRes = zaddResponse.get();
if (zaddRes != null) {
newElementNum = zaddRes.intValue();
}
Long zcardRes = zcardResponse.get();
if (zcardRes != null) {
elementNum = zcardRes.intValue();
}
if (newElementNum > 0 && elementNum > maxLength) {
this.asynShrinkZset(key, elementNum, maxLength);
}
return newElementNum;
} catch (JedisException e) {
logger.error("'zaddAndRem' key fail, key: {}, score: {}, member: {}, maxLength: {}", key, score,
member, maxLength);
logger.error(e.getMessage(), e);
} finally {
close(jedis);
}
}
return 0;
}
示例15: incr
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
@Redis(shard = true)
public void incr(String key, int times) {
ShardedJedisPipeline pipeline = shardedJedis.pipelined();
for (int i = 0; i < times; i++) {
pipeline.incr(key + i);
}
Response<String> response = pipeline.get(key + 1);
pipeline.sync();
LOGGER.info(response.get());
}