本文整理汇总了Java中redis.clients.jedis.ShardedJedisPipeline类的典型用法代码示例。如果您正苦于以下问题:Java ShardedJedisPipeline类的具体用法?Java ShardedJedisPipeline怎么用?Java ShardedJedisPipeline使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShardedJedisPipeline类属于redis.clients.jedis包,在下文中一共展示了ShardedJedisPipeline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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();
}
示例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: hsetByte
import redis.clients.jedis.ShardedJedisPipeline; //导入依赖的package包/类
/**
* 在hash中存入单个键值对
*
* @param key
* @param field
* @param value
* @param expireTime
*/
public void hsetByte(String key, String field, Object value, int expireTime) {
ShardedJedis shardedJedis = shardedJedisPool.getResource();
if (shardedJedis == null) {
return;
}
try {
ShardedJedisPipeline pipelined = shardedJedis.pipelined();
pipelined.hset(serializer.serialize(key), serializer.serialize(field),
serializer.serialize(value));
pipelined.expire(serializer.serialize(key), expireTime);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
shardedJedis.close();
}
}
示例5: testShardPipelined
import redis.clients.jedis.ShardedJedisPipeline; //导入依赖的package包/类
public void testShardPipelined() {// 0.127秒
JedisShardInfo jedis = new JedisShardInfo("120.25.241.144", 6379);
jedis.setPassword("b840fc02d52404542994");
List<JedisShardInfo> shards = Arrays.asList(jedis);
ShardedJedis sharding = new ShardedJedis(shards);
ShardedJedisPipeline pipeline = sharding.pipelined();
long start = System.currentTimeMillis();
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 + "秒");
sharding.disconnect();
try {
Closeables.close(sharding, true);
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: 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);
}
}
示例12: sets
import redis.clients.jedis.ShardedJedisPipeline; //导入依赖的package包/类
@Override
public String sets(final String... keyvalues) {
return exec0(new ShardedJedisCallback<String>() {
@Override
public String doCallback(ShardedJedis jedis) {
Object[] args = Arrays.asList(keyvalues).toArray();
final Map<String, Object> map = MapUtil.gmap(args);
pipelined(new PiplineCallbackAdapter() {
@Override
public void doCallback(ShardedJedisPipeline pipeline) {
for (Entry<String, Object> entry : map.entrySet()) {
pipeline.set(entry.getKey(), entry.getValue().toString());
}
}
});
return new String();
}
});
}
示例13: del
import redis.clients.jedis.ShardedJedisPipeline; //导入依赖的package包/类
@Override
public Long del(final String... keys) {
return exec0(new ShardedJedisCallback<Long>() {
@Override
public Long doCallback(ShardedJedis jedis) {
pipelined(new PiplineCallbackAdapter() {
@Override
public void doCallback(ShardedJedisPipeline pipeline) {
for (String key : keys) {
pipeline.del(key);
}
}
});
return new Long(keys.length);
}
});
}
示例14: testShardpipelined
import redis.clients.jedis.ShardedJedisPipeline; //导入依赖的package包/类
/**
* 分布式直连异步调用
* 耗时:
* 0.866 seconds
* 0.892 seconds
*/
@Test
@Ignore
public void testShardpipelined() {
List<JedisShardInfo> shards = Arrays.asList(
new JedisShardInfo("localhost",6379),
new JedisShardInfo("localhost",6379));
ShardedJedis sharding = new ShardedJedis(shards);
ShardedJedisPipeline pipeline = sharding.pipelined();
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
pipeline.set("sp" + i, "p" + i);
}
List<Object> results = pipeline.syncAndReturnAll();
long end = System.currentTimeMillis();
System.out.println("[email protected] SET: " + ((end - start)/1000.0) + " seconds");
sharding.disconnect();
sharding.close();
}
示例15: testShardPipelinedPool
import redis.clients.jedis.ShardedJedisPipeline; //导入依赖的package包/类
/**
* 分布式连接池异步调用
* 0.452 seconds
* 0.43 seconds
*/
@Test
@Ignore
public void testShardPipelinedPool() {
List<JedisShardInfo> shards = Arrays.asList(
new JedisShardInfo("localhost",6379),
new JedisShardInfo("localhost",6379));
ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);
ShardedJedis one = pool.getResource();
ShardedJedisPipeline pipeline = one.pipelined();
long start = System.currentTimeMillis();
for (int i = 0; i < COUNTER; i++) {
pipeline.set("sppn" + i, "n" + i);
}
List<Object> results = pipeline.syncAndReturnAll();
long end = System.currentTimeMillis();
pool.returnResource(one);
logger.info("[email protected] SET: " + ((end - start)/1000.0) + " seconds");
pool.destroy();
}