hyperloglog应用
程序员文章站
2022-07-11 12:23:22
...
1.hyperloglog是应用在基数计算上。因为它不去存储数据,而是计算存储key值的数量,在 Redis 里面,每个 HyperLogLog 键只需要花费 12 KB 内存,就可以计算接近 2^64 个不同元素的基 数。这和计算基数时,元素越多耗费内存就越多的集合形成鲜明对比。
2.hyperloglog基本redis语句
http://www.runoob.com/redis/redis-hyperloglog.html
3.基于redisTemplate操作
package com.panku.web.redis;
import java.util.Collection;
import java.util.Set;import javax.annotation.Resource;import org.junit.Test;
import org.junit.runner.RunWith;
import org.Springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.HyperLogLogOperations;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Spring RedisTemplate操作-HyperLogLog操作
* @author ccx
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class RedisTemplateHyperLogLog {
@Resource(name="redisTemplate")
private RedisTemplate rt;
public void flushdb(){
rt.execute(new RedisCallback () {
public String doInRedis(RedisConnection connection) throws DataAccessException {
connection.flushDb();
return "ok";
}
});
}
@Test
public void set(){
flushdb();
HyperLogLogOperations vo = rt.opsForHyperLogLog();
vo.add("book", "a","b","c");
vo.add("bag", "a","e","d");
vo.add("del", "f","g","h");
}
@Test
public void get(){
HyperLogLogOperations vo = rt.opsForHyperLogLog();
out(vo.size("book"));
out(vo.size("bag"));
out(vo.size("del"));
out(vo.size("book","bag","del"));
vo.delete("del");
out(vo.size("book","bag","del"));
vo.union("total", "book","bag","del");
out(vo.size("total"));
}
public void out(String str){
System.out.println(str);
}
public void out(Collection list){
System.out.println(list);
}
public void out(long num){
System.out.println(num);
}
public void out(boolean num){
System.out.println(num);
}
public void out(DataType num){
System.out.println(num);
}
public void out(Object str){
System.out.println(str);
}
public void out(Set > set){
for(TypedTuple t : set){
System.out.println(t.getValue()+"---"+t.getScore());
}
}
}
https://www.aliyun.com/jiaocheng/775199.html?spm=5176.100033.2.5.htLH4i
推荐阅读
-
IOS - 应用的发布方式有哪些? 博客分类: ios
-
[转贴]Derby入门 —— (2) 博客分类: 编程技术 DerbyJava网络应用SQLJDBC
-
多进程应用帮助PHP解决难题
-
PHP应用发展的详细分析
-
php入门学习知识点四 PHP正则表达式基本应用_php入门_脚本之家
-
下载android应用的apk文件变成了zip--网上转载的解决方案 博客分类: android apkzip下载android
-
什么叫0day和Warez? 游戏网络应用
-
项目中应用Redis+Php的场景
-
WAS证书过期替换之独立WAS Server之文字操作版 博客分类: Java IBM配置管理应用服务器脚本
-
PHP-xajax的应用方法总结