Using Sorted Sets with Jedis API
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.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 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
}
}
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:
CODE:
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
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部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-735499/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [翻譯]使用 ICS KeyChain API(Using the ICS KeyChain API)AIAPI
- Create orders using SAP Commerce Cloud Restful APICloudRESTAPI
- Jedis
- Jedis bitmap
- Jedis pythonPython
- Jedis操作
- Equivalent Sets(HDU-3836)UI
- Web - Redis & JedisWebRedis
- jedis操作 redisRedis
- Redis(15) jedisRedis
- 【如何使用jedis】
- Dynamics 365 Web API Set Values of all Data Types using Web API in Dynamics CRM Through C#WebAPIC#
- AtCoder ARC097C Sorted and Sorted:dp
- Jedis的基本使用
- python sorted keyPython
- MySQL 索引優化 Using where, Using filesortMySql索引優化
- MySQL explain結果Extra中"Using Index"與"Using where; Using index"區別MySqlAIIndex
- 聊聊jedis的borrow行為
- Merge Two Sorted List
- # Search in Rotated Sorted Array
- Kubernetes Replica Sets 和 Kubernetes Replica Controller的區別Controller
- 解析數倉OLAP函式:ROLLUP、CUBE、GROUPING SETS函式
- PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation3DSegmentation
- Using hints for PostgresqlSQL
- String interpolation using $
- using的用法
- Using mysqldump for backupsMySql
- MySQL 之 USINGMySql
- redis驅動-jedis實現1Redis
- 88. Merge Sorted Array
- 977. Squares of a Sorted Array
- mongodb複製集(replica sets)+分片(sharding)環境搭建MongoDB
- Lettuce和Jedis的基準測試
- jedis異常:Could not get a resource from the pool
- [Redis 客戶端整合] SpringBoot 整合 JedisRedis客戶端Spring Boot
- pdf crop using pythonPython
- MGTSC 212 using ExcelExcel
- Video Division with using OpenCvIDEOpenCV
- Dictionary application using SwingAPP