本文整理了Java中redis.clients.jedis.Tuple.getElement()
方法的一些代码示例,展示了Tuple.getElement()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.getElement()
方法的具体详情如下:
包路径:redis.clients.jedis.Tuple
类名称:Tuple
方法名:getElement
暂无
代码示例来源:origin: caoxinyu/RedisClient
@Override
public String[] getText(int row) {
String[] values = new String[]{"", ""};
int index = row-start;
if(index == -1)
return new String[]{"", ""};
if(index < page.length){
Tuple tuple = (Tuple) page[index];
values = new String[]{String.valueOf(tuple.getScore()), tuple.getElement()};
}
return values;
}
代码示例来源:origin: io.leopard/leopard-redis
/**
* 将有序集的元素转成String,保存到集合中.
*
* @param set
* @return
*/
public static Set<String> tupleToString(Set<Tuple> set) {
Set<String> result = new LinkedHashSet<String>();
for (Tuple tuple : set) {
String element = tuple.getElement();
result.add(element);
}
return result;
}
代码示例来源:origin: mindwind/craft-atom
private List<Map.Entry<String, Double>> convert(List<Tuple> list) {
if (list == null || list.isEmpty()) return Collections.emptyList();
List<Map.Entry<String, Double>> l = new ArrayList<Map.Entry<String,Double>>(list.size());
for (Tuple tuple : list) {
Map.Entry<String, Double> entry = new AbstractMap.SimpleEntry<String, Double>(tuple.getElement(), tuple.getScore());
l.add(entry);
}
return l;
}
代码示例来源:origin: mindwind/craft-atom
private Map<String, Double> convert4zrangewithscores(Set<Tuple> set) {
Map<String, Double> map = new LinkedHashMap<String, Double>(set.size());
for (Tuple tuple : set) {
map.put(tuple.getElement(), tuple.getScore());
}
return map;
}
代码示例来源:origin: io.leopard/leopard-redis
/**
* 将有序集转成List.
*
* @param set 有序集
* @return
*/
public static List<Entry<String, Double>> toEntryList(Set<Tuple> set) {
if (set == null || set.isEmpty()) {
return null;
}
List<Entry<String, Double>> result = new ArrayList<Entry<String, Double>>();
for (Tuple tuple : set) {
String element = tuple.getElement();
Double score = tuple.getScore();
Entry<String, Double> entry = new SimpleEntry<String, Double>(element, score);
result.add(entry);
}
return result;
}
代码示例来源:origin: agoragames/java-leaderboard
/**
* Massage the leaderboard data into LeaderData objects
*
* @param leaderboardName Leaderboard
* @param memberData Tuple of member and score
* @param useZeroIndexForRank Use zero-based index for rank
* @return List of LeaderData objects which contains member, score and rank
*/
private List<LeaderData> massageLeaderData(String leaderboardName, Set<Tuple> memberData, boolean useZeroIndexForRank) {
List<LeaderData> leaderData = new ArrayList<LeaderData>();
Iterator<Tuple> memberDataIterator = memberData.iterator();
while (memberDataIterator.hasNext()) {
Tuple memberDataTuple = memberDataIterator.next();
LeaderData leaderDataItem = new LeaderData(memberDataTuple.getElement(), memberDataTuple.getScore(), rankForIn(leaderboardName, memberDataTuple.getElement(), useZeroIndexForRank));
leaderData.add(leaderDataItem);
}
return leaderData;
}
}
代码示例来源:origin: io.leopard/leopard-biz
protected void load() {
Set<Tuple> set = this.sortedSetBizRedisImpl.listAll();
// System.err.println("load set:" + set);
if (set == null || set.isEmpty()) {
return;
}
for (Tuple tuple : set) {
String element = tuple.getElement();
double score = tuple.getScore();
this.sortedSetBizMemoryImpl.zadd(element, score);
}
}
代码示例来源:origin: kingston-csj/jforgame
public List<CrossRank> queryRank(int rankType, int start, int end) {
List<CrossRank> ranks = new ArrayList<>();
Set<Tuple> tupleSet = cluster.zrevrangeWithScores("CrossRank_" + rankType, start , end );
Class<? extends AbstractCrossRank> rankClazz = rank2Class.get(rankType);
for (Tuple record:tupleSet) {
try{
String element = record.getElement();
AbstractCrossRank rankProto = rankClazz.newInstance();
String resultKey = rankProto.buildResultKey();
String data = cluster.hget(resultKey, element);
CrossRank rank = unserialize(data, rankClazz);
ranks.add(rank);
}catch(Exception e) {
e.printStackTrace();
}
}
return ranks;
}
代码示例来源:origin: Baqend/Orestes-Bloomfilter
@Override
public TimeMap<T> getTimeToLiveMap() {
try (Jedis jedis = pool.getResource()) {
Set<Tuple> tuples = jedis.zrangeByScoreWithScores(keys.TTL_KEY, now() - config.gracePeriod(), Double.POSITIVE_INFINITY);
return tuples.stream().collect(TimeMap.collectMillis(t -> (T) t.getElement(), t -> (long) t.getScore()));
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public ScanResult<Entry<String, Double>> zscan(final String key, final long cursor, final ScanParams params) {
Assert.hasText(key);
Assert.notNull(params);
try {
final ScanResult<Tuple> res = cluster.zscan(key, String.valueOf(cursor), params);
final List<Tuple> tuples = res.getResult();
if (CollectionUtils.isEmpty(tuples)) {
return new ScanResult<>(res.getStringCursor(), Collections.emptyList());
}
final List<Entry<String, Double>> newTuples = Lists.newArrayList();
tuples.forEach(tuple -> newTuples.add(new AbstractMap.SimpleEntry<>(tuple.getElement(), tuple.getScore())));
return new ScanResult<>(res.getStringCursor(), newTuples);
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
}
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrangeWithScores(final String key, final long start, final long end, final TypeReference<T> type) {
Assert.hasText(key);
Assert.notNull(type);
try {
final Set<Tuple> tuples = cluster.zrangeWithScores(key, start, end);
if (!CollectionUtils.isEmpty(tuples)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple tuple : tuples) {
newValues.put(parseObject(tuple.getElement(), type), tuple.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrevrangeWithScores(final String key, final long start, final long end, final TypeReference<T> type) {
Assert.hasText(key);
Assert.notNull(type);
try {
final Set<Tuple> tuples = cluster.zrevrangeWithScores(key, start, end);
if (!CollectionUtils.isEmpty(tuples)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple tuple : tuples) {
newValues.put(parseObject(tuple.getElement(), type), tuple.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrevrangeByScoreWithScores(final String key, final double max, final double min, final TypeReference<T> type) {
Assert.hasText(key);
Assert.notNull(type);
try {
Set<Tuple> tuples = cluster.zrevrangeByScoreWithScores(key, max, min);
if (!CollectionUtils.isEmpty(tuples)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple tuple : tuples) {
newValues.put(parseObject(tuple.getElement(), type), tuple.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrevrangeByScoreWithScores(final String key, final double max, final double min, final int offset, final int count,
final TypeReference<T> type) {
Assert.hasText(key);
Assert.notNull(type);
try {
Set<Tuple> tuples = cluster.zrevrangeByScoreWithScores(key, max, min, offset, count);
if (!CollectionUtils.isEmpty(tuples)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple tuple : tuples) {
newValues.put(parseObject(tuple.getElement(), type), tuple.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrangeByScoreWithScores(final String key, final String min, final String max, final int offset, final int count,
final TypeReference<T> type) {
Assert.hasLength(key);
Assert.hasText(min);
Assert.hasText(max);
Assert.notNull(type);
try {
final Set<Tuple> tuples = cluster.zrangeByScoreWithScores(key, min, max, offset, count);
if (!CollectionUtils.isEmpty(tuples)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple tuple : tuples) {
newValues.put(parseObject(tuple.getElement(), type), tuple.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrangeByScoreWithScores(final String key, final String min, final String max, final TypeReference<T> type) {
Assert.hasText(key);
Assert.hasText(min);
Assert.hasText(max);
Assert.notNull(type);
try {
final Set<Tuple> tuples = cluster.zrangeByScoreWithScores(key, min, max);
if (!CollectionUtils.isEmpty(tuples)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple tuple : tuples) {
newValues.put(parseObject(tuple.getElement(), type), tuple.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrevrangeWithScores(final String key, final long start, final long end, final TypeReference<T> type) {
Assert.hasText(key);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final Set<Tuple> values = jedis.zrevrangeWithScores(key, start, end);
if (!CollectionUtils.isEmpty(values)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple value : values) {
newValues.put(parseObject(value.getElement(), type), value.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrevrangeByScoreWithScores(final String key, final double max, final double min, final TypeReference<T> type) {
Assert.hasText(key);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final Set<Tuple> values = jedis.zrevrangeByScoreWithScores(key, max, min);
if (!CollectionUtils.isEmpty(values)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple value : values) {
newValues.put(parseObject(value.getElement(), type), value.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrangeWithScores(final String key, final long start, final long end, final TypeReference<T> type) {
Assert.hasText(key);
Assert.notNull(type);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final Set<Tuple> values = jedis.zrangeWithScores(key, start, end);
if (!CollectionUtils.isEmpty(values)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple value : values) {
newValues.put(parseObject(value.getElement(), type), value.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
代码示例来源:origin: org.nanoframework/nano-orm-jedis
@Override
public <T> Map<T, Double> zrangeByScoreWithScores(final String key, final String min, final String max, final int offset, final int count,
final TypeReference<T> type) {
Assert.hasText(key);
Assert.hasText(min);
Assert.hasText(max);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final Set<Tuple> values = jedis.zrangeByScoreWithScores(key, min, max, offset, count);
if (!CollectionUtils.isEmpty(values)) {
final Map<T, Double> newValues = Maps.newHashMap();
for (Tuple value : values) {
newValues.put(parseObject(value.getElement(), type), value.getScore());
}
return newValues;
}
return Collections.emptyMap();
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
内容来源于网络,如有侵权,请联系作者删除!