Skip to content

Instantly share code, notes, and snippets.

@jwkfreedom
Created December 24, 2013 11:30
Show Gist options
  • Save jwkfreedom/8112000 to your computer and use it in GitHub Desktop.
Save jwkfreedom/8112000 to your computer and use it in GitHub Desktop.
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
jedis.zadd(key,100,"Java");//ZADD
//We could add more than one value in one calling
Map<Double, String> scoreMembers = new HashMap<Double, String>();
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment