redis php ismember,Spring StringRedisTemplate 配置

1 先看pom.xml

org.apache.commons

commons-pool2

2.0

redis.clients

jedis

2.9.0

org.springframework.data

spring-data-redis

1.6.2.RELEASE

commons-io

commons-io

2.4

junit

junit

4.12

2 创建 redis.properties

# Redis settings

redis.host=192.168.1.88

redis.port=6379

redis.timeOut=10000

# redis.pass=

redis.maxIdle=300

redis.maxTotal=1024

redis.maxWaitMillis=10000

redis.testOnBorrow=true

3 applicationContext.xml

两段配置都要

classpath:redis/redis.properties

4 创建Test.cs

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("/applicationContext.xml")

public class RedisTest {

@Autowired

StringRedisTemplate redisTemplate;

@Test

public void Test() throws Exception{

redisTemplate.opsForValue().set("a","test");

String q = redisTemplate.opsForValue().get("a")+" hello";

System.out.println(q);

}

}

比较 RedisTemplate 和 StringRedisTemplate的相关信息:

RedisTemplate

方法

子API接口

描述

opsForValue()

ValueOperations

描述具有简单值的条目

opsForList()

ListOperations

操作具有list值的条目

opsForSet()

SetOperations

操作具有set值的条目

opsForZSet()

ZSetOperations

操作具有ZSet值(排序的set)的条目

opsForHash()

HashOperations

操作具有hash值的条目

boundValueOps(K)

BoundValueOperations

以绑定指定key的方式,操作具有简单值的条目

boundListOps(K)

BoundListOperations

以绑定指定key的方式,操作具有list的条目

boundSetOps(K)

BoundSetOperations

以绑定指定key的方式,操作具有set的条目

boundZSet(K)

BoundZSetOperations

以绑定指定key的方式,操作具有ZSet(排序的set)的条目

boundHashOps(K)

BoundHashOperations

以绑定指定key的方式,操作具有hash值的条目

StringRedisTemplate

方法

子API接口

描述

opsForValue()

ValueOperationsString>

描述具有简单值的条目

opsForList()

ListOperations

操作具有list值的条目

opsForSet()

SetOperations

操作具有set值的条目

opsForZSet()

ZSetOperations

操作具有ZSet值(排序的set)的条目

opsForHash()

HashOperations

操作具有hash值的条目

boundValueOps(K)

BoundValueOperations

以绑定指定key的方式,操作具有简单值的条目

boundListOps(K)

BoundListOperations

以绑定指定key的方式,操作具有list的条目

boundSetOps(K)

BoundSetOperations

以绑定指定key的方式,操作具有set的条目

boundZSet(K)

BoundZSetOperations

以绑定指定key的方式,操作具有ZSet(排序的set)的条目

boundHashOps(K)

BoundHashOperations

以绑定指定key的方式,操作具有hash值的条目

常用方法:

转载:http://blog.csdn.net/u011911084/article/details/53435172

[java] view plain copy

stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向redis里存入数据和设置缓存时间

[java] view plain copy

stringRedisTemplate.boundValueOps("test").increment(-1);//val做-1操作

[java] view plain copy

stringRedisTemplate.opsForValue().get("test")//根据key获取缓存中的val

[java] view plain copy

stringRedisTemplate.boundValueOps("test").increment(1);//val +1

[java] view plain copy

stringRedisTemplate.getExpire("test")//根据key获取过期时间

[java] view plain copy

stringRedisTemplate.getExpire("test",TimeUnit.SECONDS)//根据key获取过期时间并换算成指定单位

[java] view plain copy

stringRedisTemplate.delete("test");//根据key删除缓存

[java] view plain copy

stringRedisTemplate.hasKey("546545");//检查key是否存在,返回boolean值

[java] view plain copy

stringRedisTemplate.opsForSet().add("red_123", "1","2","3");//向指定key中存放set集合

[java] view plain copy

stringRedisTemplate.expire("red_123",1000 , TimeUnit.MILLISECONDS);//设置过期时间

[java] view plain copy

stringRedisTemplate.opsForSet().isMember("red_123", "1")//根据key查看集合中是否存在指定数据

[java] view plain copy

stringRedisTemplate.opsForSet().members("red_123");//根据key获取set集合

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值