Redis(RedisTemplate)运算、算法(incr、decr、increment)
RedisTemplate配置:https://www.cnblogs.com/weibanggang/p/10188682.html
package com.wbg.springRedis.test; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.RedisTemplate; public class TestCal { static RedisTemplate redisTemplate = null;
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-redis.xml");
redisTemplate = applicationContext.getBean(RedisTemplate.class);
//设值
redisTemplate.opsForValue().set("i", "10");
print();
//加1
redisTemplate.getConnectionFactory().getConnection().incr(
redisTemplate.getKeySerializer().serialize("i")
);
//加4
redisTemplate.getConnectionFactory().getConnection().incrBy(
redisTemplate.getKeySerializer().serialize("i"), 4
);
print();
//
//减1
redisTemplate.getConnectionFactory().getConnection().decr(
redisTemplate.getKeySerializer().serialize("i")
);
//减4
redisTemplate.getConnectionFactory().getConnection().decrBy(
redisTemplate.getKeySerializer().serialize("i"), 4
);
print();
print(); //加2.3 increment是float类型
redisTemplate.opsForValue().increment("i",2.3);
print();
}
//打印
public static void print(){
System.out.println(redisTemplate.opsForValue().get("i"));
} }
Redis(RedisTemplate)运算、算法(incr、decr、increment)的更多相关文章
- Redis与Memcached的incr/decr差异对比
目前广泛使用的分布式缓存Redis和Memcached均支持对整数型Value值的增减,对应到具体命令中就是incr和decr命令. incr/decr是原子性操作(memcached 1.2.4及以 ...
- redis的LRU算法(二)
前文再续,书接上一回.上次讲到redis的LRU算法,文章实在精妙,最近可能有机会用到其中的技巧,顺便将下半部翻译出来,实现的时候参考下. 搏击俱乐部的第一法则:用裸眼观测你的算法 Redis2.8的 ...
- 基于Redis的BloomFilter算法去重
BloomFilter算法及其适用场景 BloomFilter是利用类似位图或者位集合数据结构来存储数据,利用位数组来简洁的表示一个集合,并且能够快速的判断一个元素是不是已经存在于这个集合.因为基于H ...
- spring data redis RedisTemplate操作redis相关用法
http://blog.mkfree.com/posts/515835d1975a30cc561dc35d spring-data-redis API:http://docs.spring.io/sp ...
- redis的LRU算法(一)
最近加班比较累,完全不想写作了.. 刚看到一篇有趣的文章,是redis的作者antirez对redis的LRU算法的回顾.LRU算法是Least Recently Used的意思,将最近最少使用的资源 ...
- Redis的LRU算法
Redis的LRU算法 LRU算法背后的的思想在计算机科学中无处不在,它与程序的"局部性原理"很相似.在生产环境中,虽然有Redis内存使用告警,但是了解一下Redis的缓存使用策 ...
- 【Redis 设置Redis使用LRU算法】
转自:http://ifeve.com/redis-lru/ 本文将介绍Redis在生产环境中使用的Redis的LRU策略,以及自己动手实现的LRU算法(php) 1.设置Redis使用LRU算法 L ...
- redis分布式映射算法
redis分布式映射算法 一致性Hash算法的原理和实现 为了解决分布式系统中的负载均衡的问题 背景问题 有N台服务器提供缓存服务,需要对服务器进行负载均衡,将请求平均发到每台服务器上,每台服务器负载 ...
- 理解 Redis(4) - 关于 string 的更多命令(SETEX, SETNX, INCR, DECR, MSET...)
上一节介绍了关于字符串值的一些基本命令, 这一节将介绍一些进阶命令: 清理终端: 127.0.0.1:6379> clear 设置一个键值对, 同时设置过期时间为10秒: 127.0.0.1:6 ...
随机推荐
- The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter.
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the assoc ...
- 如何将一个SpringBoot简便地打成一个war包(转)
为什么要把SpringBoot打成war包 正常情况下SpringBoot项目是以jar包的形式,通过命令行: java -jar demo.jar 来运行的,并且SpringBoot是内嵌Tomca ...
- img 加载网络图片失败 显示默认图片
1. 概述 当从网络加载图片失败 希望显示默认图 img 标签有个 onerror属性 2. 代码 2.1 java服务端组织标签整个返回前端 String imgUrl = "javasc ...
- VS2013 C++ 动态链接库的生成
原文:http://www.cnblogs.com/djiankuo/p/5092025.html 这个东西搞了好几天,现在终于没有问题了,其实现在想来还是微软做的东西好用啊,在这里点个赞!!! LL ...
- Jmeter CSV 参数化/检查点/断言
当参数的值没有规律且量不太大时,可以使用CSV Data set config这种方法. 案例: 应用Sogou自动搜索关键字: 软件开发测试,web功能自动化测试,性能自动化测试,Selenium以 ...
- Http重要知识点
- SSIS ->> 管理和维护SSISDB
Comming soon!!! 参考文献: Setup and Performance Issues with the Integration Services (SSIS) 2012 Catalog ...
- 如何使用Adobe Reader复制PDF文档上的文字
PDF文档大家常用,但是有没有简单的方法能够提取PDF文档上的文字,然后使用呢?除了将PDF转换成Word,这里介绍一种更为简单实用的方法复制PDF文本文字,Adobe Reader是大家都常用的PD ...
- markdown中设置、调整图片尺寸
使用百分比描述尺寸 <img src="https://img2018.cnblogs.com/blog/1122471/201902/1122471-2019022218575673 ...
- 关于TCHAR和string对象的c.str()一些注意事项
1.TCHAR 根据预处理器的设置,如果是_MBCS, 那么TCHAR = char: 如果 如果设置的是UNICODE和_UNICODE,那么TCHAR=wchar_t.就等于根据当前环境会选择不同 ...