本文整理了Java中redis.clients.jedis.Jedis.scan()
方法的一些代码示例,展示了Jedis.scan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.scan()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:scan
暂无
代码示例来源:origin: sohutv/cachecloud
@Override
public ScanResult<String> scan(final String cursor) {
return scan(cursor, new ScanParams());
}
代码示例来源:origin: changmingxie/tcc-transaction
public static Boolean isSupportScanCommand(Jedis jedis) {
try {
ScanParams scanParams = buildDefaultScanParams(SCAN_TEST_PATTERN, SCAN_COUNT);
jedis.scan(SCAN_INIT_CURSOR, scanParams);
} catch (JedisDataException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
logger.info("Redis **NOT** support scan command");
return false;
}
logger.info("Redis support scan command");
return true;
}
代码示例来源:origin: changmingxie/tcc-transaction
@Override
public Set<byte[]> doInJedis(Jedis jedis) {
if (isSupportScan) {
List<String> allKeys = new ArrayList<String>();
String cursor = RedisHelper.SCAN_INIT_CURSOR;
ScanParams scanParams = RedisHelper.buildDefaultScanParams(keyPrefix + "*", fetchKeySize);
do {
ScanResult<String> scanResult = jedis.scan(cursor, scanParams);
allKeys.addAll(scanResult.getResult());
cursor = scanResult.getStringCursor();
} while (!cursor.equals(RedisHelper.SCAN_INIT_CURSOR));
Set<byte[]> allKeySet = new HashSet<byte[]>();
for (String key : allKeys) {
allKeySet.add(key.getBytes());
}
logger.info(String.format("find all key by scan command with pattern:%s allKeySet.size()=%d", keyPrefix + "*", allKeySet.size()));
return allKeySet;
} else {
return jedis.keys((keyPrefix + "*").getBytes());
}
}
});
代码示例来源:origin: caoxinyu/RedisClient
protected Set<String> getResult() {
Set<String> nodekeys = new HashSet<String>();
assert(container != null);
ScanParams params = new ScanParams();
params.match(container + keyPattern);
ScanResult<String> result;
String cursor = SCAN_POINTER_START;
do {
result = jedis.scan(cursor, params);
nodekeys.addAll(result.getResult());
cursor = result.getStringCursor();
}while(!result.getStringCursor().equals(SCAN_POINTER_START));
return nodekeys;
}
代码示例来源:origin: qiurunze123/miaosha
public List<String> scanKeys(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
List<String> keys = new ArrayList<String>();
String cursor = "0";
ScanParams sp = new ScanParams();
sp.match("*"+key+"*");
sp.count(100);
do{
ScanResult<String> ret = jedis.scan(cursor, sp);
List<String> result = ret.getResult();
if(result!=null && result.size() > 0){
keys.addAll(result);
}
//再处理cursor
cursor = ret.getStringCursor();
}while(!cursor.equals("0"));
return keys;
} finally {
if (jedis != null) {
jedis.close();
}
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SCAN' cannot be called in pipeline / transaction mode.");
}
ScanParams params = JedisConverters.toScanParams(options);
redis.clients.jedis.ScanResult<String> result = connection.getJedis().scan(Long.toString(cursorId), params);
return new ScanIteration<>(Long.valueOf(result.getCursor()),
JedisConverters.stringListToByteList().convert(result.getResult()));
}
代码示例来源:origin: prestodb/presto
private boolean fetchKeys()
{
try (Jedis jedis = jedisPool.getResource()) {
switch (split.getKeyDataType()) {
case STRING: {
String cursor = SCAN_POINTER_START;
if (redisCursor != null) {
cursor = redisCursor.getStringCursor();
}
log.debug("Scanning new Redis keys from cursor %s . %d values read so far", cursor, totalValues);
redisCursor = jedis.scan(cursor, scanParms);
List<String> keys = redisCursor.getResult();
keysIterator = keys.iterator();
}
break;
case ZSET:
Set<String> keys = jedis.zrange(split.getKeyName(), split.getStart(), split.getEnd());
keysIterator = keys.iterator();
break;
default:
log.debug("Redis type of key %s is unsupported", split.getKeyDataFormat());
return false;
}
}
return true;
}
代码示例来源:origin: alexxiyang/shiro-redis
private Set<byte[]> getKeysFromClusterNode(JedisPool jedisPool, byte[] pattern) {
Set<byte[]> keys = new HashSet<byte[]>();
Jedis jedis = jedisPool.getResource();
try {
ScanParams params = new ScanParams();
params.count(count);
params.match(pattern);
byte[] cursor = ScanParams.SCAN_POINTER_START_BINARY;
ScanResult<byte[]> scanResult;
do {
scanResult = jedis.scan(cursor, params);
keys.addAll(scanResult.getResult());
cursor = scanResult.getCursorAsBytes();
} while (scanResult.getStringCursor().compareTo(ScanParams.SCAN_POINTER_START) > 0);
} finally {
jedis.close();
}
return keys;
}
代码示例来源:origin: alexxiyang/shiro-redis
private long getDbSizeFromClusterNode(JedisPool jedisPool, byte[] pattern) {
long dbSize = 0L;
Jedis jedis = jedisPool.getResource();
try {
ScanParams params = new ScanParams();
params.count(count);
params.match(pattern);
byte[] cursor = ScanParams.SCAN_POINTER_START_BINARY;
ScanResult<byte[]> scanResult;
do {
scanResult = jedis.scan(cursor, params);
dbSize++;
cursor = scanResult.getCursorAsBytes();
} while (scanResult.getStringCursor().compareTo(ScanParams.SCAN_POINTER_START) > 0);
} finally {
jedis.close();
}
return dbSize;
}
代码示例来源:origin: alexxiyang/shiro-redis
/**
* Return all the keys of Redis db. Filtered by pattern.
* @param pattern key pattern
* @return key set
*/
public Set<byte[]> keys(byte[] pattern) {
Set<byte[]> keys = new HashSet<byte[]>();
Jedis jedis = getJedis();
try {
ScanParams params = new ScanParams();
params.count(count);
params.match(pattern);
byte[] cursor = ScanParams.SCAN_POINTER_START_BINARY;
ScanResult<byte[]> scanResult;
do {
scanResult = jedis.scan(cursor, params);
keys.addAll(scanResult.getResult());
cursor = scanResult.getCursorAsBytes();
} while (scanResult.getStringCursor().compareTo(ScanParams.SCAN_POINTER_START) > 0);
} finally {
jedis.close();
}
return keys;
}
代码示例来源:origin: alexxiyang/shiro-redis
/**
* Return the size of redis db.
* @param pattern key pattern
* @return key-value size
*/
@Override
public Long dbSize(byte[] pattern) {
long dbSize = 0L;
Jedis jedis = getJedis();
try {
ScanParams params = new ScanParams();
params.count(count);
params.match(pattern);
byte[] cursor = ScanParams.SCAN_POINTER_START_BINARY;
ScanResult<byte[]> scanResult;
do {
scanResult = jedis.scan(cursor, params);
List<byte[]> results = scanResult.getResult();
for (byte[] result : results) {
dbSize++;
}
cursor = scanResult.getCursorAsBytes();
} while (scanResult.getStringCursor().compareTo(ScanParams.SCAN_POINTER_START) > 0);
} finally {
jedis.close();
}
return dbSize;
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public ScanResult<String> scan(String cursor, ScanParams params) {
String command = "scan";
return instrumented(command, () -> delegated.scan(cursor, params));
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public ScanResult<byte[]> scan(byte[] cursor) {
String command = "scan";
return instrumented(command, () -> delegated.scan(cursor));
}
代码示例来源:origin: org.nutz/nutz-integration-jedis
@Deprecated
/**
* This method is deprecated due to bug (scan cursor should be unsigned long)
* And will be removed on next major release
* @see https://github.com/xetorthio/jedis/issues/531
*/
public ScanResult<String> scan(int cursor) {
Jedis jedis = getJedis();
try {
return jedis.scan(cursor);
} finally {Streams.safeClose(jedis);}
}
代码示例来源:origin: org.nutz/nutz-integration-jedis
public ScanResult<String> scan(String cursor) {
Jedis jedis = getJedis();
try {
return jedis.scan(cursor);
} finally {Streams.safeClose(jedis);}
}
代码示例来源:origin: org.nutz/nutz-integration-jedis
public ScanResult<byte[]> scan(byte[] cursor) {
Jedis jedis = getJedis();
try {
return jedis.scan(cursor);
} finally {Streams.safeClose(jedis);}
}
代码示例来源:origin: org.nutz/nutz-integration-jedis
public ScanResult<byte[]> scan(byte[] cursor, ScanParams params) {
Jedis jedis = getJedis();
try {
return jedis.scan(cursor, params);
} finally {Streams.safeClose(jedis);}
}
代码示例来源:origin: org.springframework.data/spring-data-redis
@Override
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SCAN' cannot be called in pipeline / transaction mode.");
}
ScanParams params = JedisConverters.toScanParams(options);
redis.clients.jedis.ScanResult<String> result = connection.getJedis().scan(Long.toString(cursorId), params);
return new ScanIteration<>(Long.valueOf(result.getStringCursor()),
JedisConverters.stringListToByteList().convert(result.getResult()));
}
代码示例来源:origin: mindwind/craft-atom
private ScanResult<String> scan_match(Jedis j, String cursor, String pattern) {
ScanParams param = new ScanParams();
param.match(pattern);
redis.clients.jedis.ScanResult<String> sr = j.scan(cursor, param);
return new ScanResult<String>(sr.getStringCursor(), sr.getResult());
}
代码示例来源:origin: mindwind/craft-atom
private ScanResult<String> scan_match_count(Jedis j, String cursor, String pattern, int count) {
ScanParams param = new ScanParams();
param.match(pattern);
param.count(count);
redis.clients.jedis.ScanResult<String> sr = j.scan(cursor, param);
return new ScanResult<String>(sr.getStringCursor(), sr.getResult());
}
内容来源于网络,如有侵权,请联系作者删除!