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)的更多相关文章

  1. Redis与Memcached的incr/decr差异对比

    目前广泛使用的分布式缓存Redis和Memcached均支持对整数型Value值的增减,对应到具体命令中就是incr和decr命令. incr/decr是原子性操作(memcached 1.2.4及以 ...

  2. redis的LRU算法(二)

    前文再续,书接上一回.上次讲到redis的LRU算法,文章实在精妙,最近可能有机会用到其中的技巧,顺便将下半部翻译出来,实现的时候参考下. 搏击俱乐部的第一法则:用裸眼观测你的算法 Redis2.8的 ...

  3. 基于Redis的BloomFilter算法去重

    BloomFilter算法及其适用场景 BloomFilter是利用类似位图或者位集合数据结构来存储数据,利用位数组来简洁的表示一个集合,并且能够快速的判断一个元素是不是已经存在于这个集合.因为基于H ...

  4. spring data redis RedisTemplate操作redis相关用法

    http://blog.mkfree.com/posts/515835d1975a30cc561dc35d spring-data-redis API:http://docs.spring.io/sp ...

  5. redis的LRU算法(一)

    最近加班比较累,完全不想写作了.. 刚看到一篇有趣的文章,是redis的作者antirez对redis的LRU算法的回顾.LRU算法是Least Recently Used的意思,将最近最少使用的资源 ...

  6. Redis的LRU算法

    Redis的LRU算法 LRU算法背后的的思想在计算机科学中无处不在,它与程序的"局部性原理"很相似.在生产环境中,虽然有Redis内存使用告警,但是了解一下Redis的缓存使用策 ...

  7. 【Redis 设置Redis使用LRU算法】

    转自:http://ifeve.com/redis-lru/ 本文将介绍Redis在生产环境中使用的Redis的LRU策略,以及自己动手实现的LRU算法(php) 1.设置Redis使用LRU算法 L ...

  8. redis分布式映射算法

    redis分布式映射算法 一致性Hash算法的原理和实现 为了解决分布式系统中的负载均衡的问题 背景问题 有N台服务器提供缓存服务,需要对服务器进行负载均衡,将请求平均发到每台服务器上,每台服务器负载 ...

  9. 理解 Redis(4) - 关于 string 的更多命令(SETEX, SETNX, INCR, DECR, MSET...)

    上一节介绍了关于字符串值的一些基本命令, 这一节将介绍一些进阶命令: 清理终端: 127.0.0.1:6379> clear 设置一个键值对, 同时设置过期时间为10秒: 127.0.0.1:6 ...

随机推荐

  1. .netcore2.0 发布CentOS7

    1.一般在windows pc上使用vscode 开发好.netcore 程序如果需要发布到其他平台需要注意一些事情 首先需要明白2个概念:FDD(Framework-dependent deploy ...

  2. unity3d之实现各种滑动效果

    一. 点击滑动页面 新建了一个带mask的prefab,加上代码只需要将图片prefab.按钮prefab和所想添加的图片 拖进去会自动生成按钮,滑动速度可以随意调time,滑动效果用itween实现 ...

  3. Effective C++ .15,16获取原始资源和成对使用同类型new和delete

    15. 智能指针可以通过get操作 #include <iostream> #include <cstdlib> #include <memory> using n ...

  4. Cocos2d-js 开发记录:基本图形绘制

    做着做着想要用基本绘图函数画个矩形,在cocos2d-js 3.0里可以使用DrawNode var dn = new cc.DrawNode(); var ltp = cc.p(0, 32); va ...

  5. 接口调用 读取图片报错 Access to the path '' is denied.解决方案

    调用接口 读取服务器上 图片 报错: Server was unable to process request. ---> Access to the path '图片路径' is denied ...

  6. ccf-201709-2 公共钥匙盒

    问题描述 有一个学校的老师共用N个教室,按照规定,所有的钥匙都必须放在公共钥匙盒里,老师不能带钥匙回家.每次老师上课前,都从公共钥匙盒里找到自己上课的教室的钥匙去开门,上完课后,再将钥匙放回到钥匙盒中 ...

  7. WPF中使用定时器 DispatcherTimer 做TCP连接中的心跳 HeartBeat

    开发过程中经常遇到定时触发的需求,如:TCP/IP连接中,使用心跳包保持连接或检测连接是否已经中断. WPF中有多种定时器: 1.using System.Windows.Threading; 代码如 ...

  8. Apache Phoenix on CDH 5

    We are happy to announce the inclusion of Apache Phoenix in Cloudera Labs. [Update: A new package fo ...

  9. 【Udacity】数据的集中程度:众数、平均数和中位数

    重视Code Review 极致--目标是成为优秀的开发者 Data tells a story!(数据会讲故事) 分析过程对于建模非常的重要,可以帮助我们减少实际上不相关的特征被错误的加入到模型中, ...

  10. Picasso通过URL获取--用户头像的圆形显示

    1.设置布局属性: <ImageView android:scaleType="fitXY"/> 2.BitmapUtils类-- 得到指定圆形的Bitmap对象 pu ...