redis是一款开源的key-value数据库,运行在内存中,由c语言编写。企业开发通常采用redis来实现缓存。同类的产品还有memcache 、memcached 等。
redistemplate.boundhashops(key) 是 redistemplate 类的一个方法,用于获取 redis 中指定哈希表的操作对象(boundhashoperations 对象)。其中,key 参数是哈希表的键值。
通过 redistemplate.boundhashops(key) 方法获取的 boundhashoperations 对象,可以方便地对指定的哈希表进行操作,包括获取、设置、删除哈希表中的键值对等。
1、往指定key中存储 键值
redistemplate.boundhashops("demo").put("1",1);2、根据指定key中得键取出值
system.out.println(redistemplate.boundhashops("demo").get("1"));3、根据指定key中得键删除
redistemplate.boundhashops("demo").delete("1");
4、根据指定key取出全部键值对
map<object, object> entries = redistemplate.boundhashops("demo").entries();
system.out.println(entries);5、根据指定key取出所有键
set<object> keys = redistemplate.boundhashops("demo").keys();
system.out.println(keys);6、批量存储到指定key中
map<string,string> map = new hashmap<>();
map.put("3","zhangsan");
map.put("4","lisi");
redistemplate.boundhashops("demo").putall(map);7、获取指定key得元素长度
long size = redistemplate.boundhashops("demo").size();
system.out.println(size);8、判断指定key中是否存在该键
system.out.println(redistemplate.boundhashops("demo").haskey("1"));9、获取指定key中所有键值对得值
list<object> values = redistemplate.boundhashops("demo").values();
system.out.println(values);10、根据指定key中的键 每次重复自增大小 (整型)
long increment = redistemplate.boundhashops("demo").increment("1", 1);
system.out.println(increment);11、根据指定key中的键 每次重复自增大小 (小数类型)
double adouble = redistemplate.boundhashops("demo").increment("1", 1.1);
system.out.println(adouble);12、根据指定key判断键是否存在,存在返回false不新增,不存在则新增键值对返回true
system.out.println(redistemplate.boundhashops("demo").putifabsent("7", 5));13、设置key得到期时间 timeunit 设置时间类型(时、分、秒...)
redistemplate.boundhashops("demo").expire(100000, timeunit.milliseconds);14、重新命名当前key得名称
redistemplate.boundhashops(key).rename("test");15、获取当前key的存储方式
system.out.println(redistemplate.boundhashops("demo").gettype());16、获取当前key过期时间
system.out.println(redistemplate.boundhashops("demo").getexpire());到此这篇关于redistemplate中boundhashops的使用小结的文章就介绍到这了,更多相关redistemplate boundhashops内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论