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集合
總結
以上是生活随笔為你收集整理的redis php ismember,Spring StringRedisTemplate 配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: behavior php,behavio
- 下一篇: oracle 表空间写文件,Oracle