当前位置: 代码网 > it编程>数据库>Redis > RedisTemplate中boundHashOps的使用小结

RedisTemplate中boundHashOps的使用小结

2024年05月15日 Redis 我要评论
redis是一款开源的key-value数据库,运行在内存中,由c语言编写。企业开发通常采用redis来实现缓存。同类的产品还有memcache 、memcached 等。redistemplate.

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内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网! 

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com