首页 > Linux操作系统 > Linux操作系统 > Using Sorted Sets with Jedis API

Using Sorted Sets with Jedis API

原创 Linux操作系统 作者:jieforest 时间:2012-07-15 10:21:24 0 删除 编辑
Sorted Sets and Jedis

In the previous post we started looking into Jedis API a Java Redis Client.In this post we will look into the Sorted Set(zsets).

Sorted Set works like a Set in the way it doesn’t allow duplicated values. The big difference is that in Sorted Set each element has a score in order to keep the elements sorted.
We can see some commands below:


import java.util.HashMap;
import java.util.Map;

import redis.clients.jedis.Jedis;
public class TestJedis {

public static void main(String[] args) {
String key = "mostUsedLanguages";
Jedis jedis = new Jedis("localhost");
//Adding a value with score to the set

//We could add more than one value in one calling
Map scoreMembers = new HashMap();
scoreMembers.put(90d, "Python");
scoreMembers.put(80d, "Javascript");
jedis.zadd(key, scoreMembers);

//We could get the score for a member
System.out.println("Number of Java users:" + jedis.zscore(key, "Java"));

//We could get the number of elements on the set
System.out.println("Number of elements:" + jedis.zcard(key));//ZCARD

来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录


  • 博文量
  • 访问量