Redis对List类型操作
1. rpush
lpush、rpush:添加值,格式是:lpush list的key item项的值(值可以有多个)
127.0.0.1:6379>rpush mylist v1 v2 v3
(integer)3
127.0.0.1:6379>lrange mylist 0-1
1)"v1"
2)"v2"
3)"v3"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void list(){
stringRedisTemplate.delete(KEY);
/**
* 示例1: 相当于执行 rpush mylist v1 v2 v3
*/
final Long rlong=stringRedisTemplate.opsForList().rightPushAll(KEY,"v1","v2","v3");
System.out.println(rlong);
}
2. lpush
lpush、rpush:添加值,格式是:lpush list的key item项的值(值可以有多个)
127.0.0.1:6379>lpush mylist v11 v12 v13
(integer)6
127.0.0.1:6379>lrange mylist 0-1
1)"v13"
2)"v12"
3)"v11"
4)"v1"
5)"v2"
6)"v3"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void list(){
stringRedisTemplate.delete(KEY);
/**
* 示例2: 相当于执行 lpush mylist v11 v12 v13
*/
final Long llong=stringRedisTemplate.opsForList().leftPushAll(KEY,"v11","v12","v13");
System.out.println(llong);
}
3.range
lrange:按索引范围获取值,格式是:lrange list的key 起始索引 终止索引 (-1表示最后一个索引)
127.0.0.1:6379> lrange mylist 0 -1
1) "v13"
2) "v12"
3) "v11"
4) "v1"
5) "v2"
6) "v3"
127.0.0.1:6379> lindex mylist 0
"v13"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void range(){
/**
* 示例1: 相当于执行 lrange mylist 0 -1
*/
stringRedisTemplate.opsForList().range(KEY,0,-1).forEach(System.out::println);
System.out.println("---------");
/**
* 示例2: 相当于执行 lindex mylist 0
*/
stringRedisTemplate.opsForList().range(KEY,0,0).forEach(System.out::println);
}
4.lpop
lpop、rpop:弹出值,格式是:lpop list的key
127.0.0.1:6379>lrange mylist 0-1
1)"v13"
2)"v12"
3)"v11"
4)"v1"
5)"v2"
6)"v3"
127.0.0.1:6379>lindex mylist 0
"v13"
127.0.0.1:6379>lpop mylist
"v13"
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"v11"
3)"v1"
4)"v2"
5)"v3"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void pop(){
/**
* 示例1: 相当于执行 lpop mylist
*/
final String leftPop=stringRedisTemplate.opsForList().leftPop(KEY);
System.out.println(leftPop);
}
5.rpop
blpop、brpop:弹出值,格式是:blpop list的key值 过期时间。(key可以是多个,如果没有值,会一直等到有值,直到过期)
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"v11"
3)"v1"
4)"v2"
5)"v3"
127.0.0.1:6379>rpop mylist
"v3"
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"v11"
3)"v1"
4)"v2"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void pop(){
/**
* 示例2: 相当于执行 rpop mylist
*/
final String rightPop=stringRedisTemplate.opsForList().rightPop(KEY);
System.out.println(rightPop);
}
6.lle
llen:获取list中元素的个数,格式是:llen list的key
127.0.0.1:6379>llen mylist
(integer)4
127.0.0.1:6379>
Java代码示例如下:
@Test
public void line(){
/**
* 获取列表长度
* 示例1: 相当于执行 llen mylist
*/
final Long size=stringRedisTemplate.opsForList().size(KEY);
System.out.println(size);
}
7. remove
lrem:删除元素,格式是:lrem list的key 数量 item项的值,(数量可正负,表示从左或从右删除;如果数量为0,表示删除全部与给定值相符的项)
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"v11"
3)"v1"
4)"v2"
127.0.0.1:6379>lrem mylist-1v2
(integer)1
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"v11"
3)"v1"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void remove(){
/**
* 移除列表元素
*/
*示例1: 相当于执行 lrem mylist-1v2
*/
final Long index=stringRedisTemplate.opsForList().remove(KEY,-1,"v2");
System.out.println(index);
}
8.trim
ltrim:保留指定索引区间的元素,格式是:ltrim list的key 起始索引 结束索引
127.0.0.1:6379>ltrim mylist 0 1
OK
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"v11"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void trim(){
/**
* 示例1: 相当于执行 ltrim mylist 0 1
* 裁剪,void,删除除了[start,end]以外的所有元素
*/
stringRedisTemplate.opsForList().trim(KEY,0,1);
}
9.set
lset:设置指定索引的值,格式是:lset list的key 索引 新的值
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"v11"
127.0.0.1:6379>lset mylist 1vip
OK
127.0.0.1:6379>lrange mylist 0-1
1)"v12"
2)"vip"
127.0.0.1:6379>
Java代码示例如下:
@Test
public void set(){
/**
* 示例1: 相当于执行 lset mylist 1 vip
*/
stringRedisTemplate.opsForList().set(KEY,1,"vip");
}
Redis对Hash类型操作
1. hset
hset:设置值。格式是:hset hash的key 项的key 项的值
@Test
public void put(){
/**
* 示例1: 相当于执行 hset myhash name tom
*/
stringRedisTemplate.opsForHash().put(KEY,"name","tom");
/**
* 127.0.0.1:6379> hget myhash name
* "tom"
* 127.0.0.1:6379>
*/
}
2. hset
同时设置多对值。格式是:hmset hash的key 项的key 项的值。(项的key和项的值可以多对)
@Test
public void putAll(){
/**
* 示例1: hset myhash id 1 name jack age 12
*/
Map<String, Object> map=new HashMap<>();
map.put("id","1");
map.put("name","jack");
map.put("age","12");
stringRedisTemplate.opsForHash().putAll(KEY,map);
/**
* 127.0.0.1:6379> hset myhash id 1 name jack age 12
* (integer) 0
* 127.0.0.1:6379> hget myhash id
* "1"
* 127.0.0.1:6379>
*
*/
}
3. hget
hget:获取值。格式是:hget hash的key 项的key
@Test
public void hget(){
/**
* 示例1: hget myhash id
*/
String id=(String)stringRedisTemplate.opsForHash().get(KEY,"id");
String name=(String)stringRedisTemplate.opsForHash().get(KEY,"name");
String age=(String)stringRedisTemplate.opsForHash().get(KEY,"age");
System.out.println(String.format("id = %s, name = %s, age=%s",id,name,age));
}
4. hgetall
hgetall:获取该key下所有的值。格式是:hgetall hash的key
@Test
public void hmget(){
/**
* 示例1: hgetall myhash
*/
final Map<Object, Object> entries=stringRedisTemplate.opsForHash().entries(KEY);
entries.forEach((key,value)->System.out.println("key: "+key+" value: "+value));
for(Object value:entries.values()){
System.out.println("value: "+value);
}
entries.values().forEach(System.out::println);
for(Object key:entries.keySet()){
System.out.println("key: "+key+" value: "+entries.get(key));
}
for(Map.Entry<Object, Object> entry:entries.entrySet()){
System.out.println("key: "+entry.getKey()+" value: "+entry.getValue());
}
/**
* 127.0.0.1:6379> hgetall myhash
* 1) "name"
* 2) "jack"
* 3) "id"
* 4) "1"
* 5) "age"
* 6) "12"
* 127.0.0.1:6379>
*/
}
5. delete
hdel:删除某个项。格式是:hdel hash的key 项的key
@Test
public void delete(){
/**
* 示例1: hdel myhash id
*/
stringRedisTemplate.opsForHash().delete(KEY,"id");
/**
*127.0.0.1:6379> hdel myhash id
* (integer) 1
* 127.0.0.1:6379> hgetall myhash
* 1) "name"
* 2) "jack"
* 3) "age"
* 4) "12"
* 127.0.0.1:6379>
*/
}
6 hkeys
hkeys:获取所有的item的key,格式是:hkeys hash的key
@Test
public void hkeys(){
/**
* 示例1: hdel myhash id
*/
final Set<Object> keys=stringRedisTemplate.opsForHash().keys(KEY);
keys.forEach(System.out::println);
/**
* 127.0.0.1:6379> hkeys myhash
* 1) "name"
* 2) "age"
* 127.0.0.1:6379>
*/
}
Redis对Set类型操作
1. sadd
sadd:添加元素,格式是:sadd set的key item的项值,item项可以有多个。
@Test
public void sadd(){
/**
* 示例1:相当于执行 sadd myset v1 v2 v3
*/
stringRedisTemplate.opsForSet().add(KEY,"v1","v2","v3");
/**
* 127.0.0.1:6379> smembers myset
* 1) "v3"
* 2) "v2"
* 3) "v1"
* 127.0.0.1:6379>
*/
}
2.smembers
smembers:获取集合中所有元素,格式是:smembers set的key
@Test
public void members(){
/**
* 示例1:相当于执行 smembers myset
*/
final Set<String> members=stringRedisTemplate.opsForSet().members(KEY);
members.forEach(System.out::println);
/**
* 127.0.0.1:6379> smembers myset
* 1) "v3"
* 2) "v2"
* 3) "v1"
* 127.0.0.1:6379>
*/
}
3.sismember
sismember:判断元素是否在集合中,格式是:sismember set的key item的项值
@Test
public void sismember(){
/**
* 示例1:相当于执行 sismember myset v1
*/
final Boolean v1=stringRedisTemplate.opsForSet().isMember(KEY,"v1");
System.out.println(v1);
/**
* 127.0.0.1:6379> sismember myset v1
* (integer) 1
* 127.0.0.1:6379>
*/
}
4.srem
srem:删除元素,格式是:srem set的key item项的值
@Test
public void srem(){
/**
* 示例1:相当于执行 sismember myset v1
*/
final Long v1=stringRedisTemplate.opsForSet().remove(KEY,"v1");
System.out.println(v1);
/**
* 127.0.0.1:6379> srem myset v1
* (integer) 1
* 127.0.0.1:6379> smembers myset
* 1) "v3"
* 2) "v2"
* 127.0.0.1:6379>
*/
}
5. scard
scard:获取集合中元素的个数,格式是:scard set的key
@Test
public void scard(){
/**
* 示例1:相当于执行 sismember myset v1
*/
final Long size=stringRedisTemplate.opsForSet().size(KEY);
System.out.println(size);
/**
* 127.0.0.1:6379> scard myset
* (integer) 2
* 127.0.0.1:6379>
*/
}
6.srandmember
srandmember:随机获取集合中的元素,格式是:srandmember set的key[数量]。(数量为正数时,会随机获取这么多个不重复的元素;如果数量大于集合元素个数,返回全部;如果数量为负,会随机获取这么多个元素,可能有重复。)
@Test
public void srandmember(){
/**
* 示例1:相当于执行 srandmember myset 1
*/
final String value=stringRedisTemplate.opsForSet().randomMember(KEY);
System.out.println(value);
/**
127.0.0.1:6379> sadd myset v1 v2 v3 v4 v4 v5 v6 v7 v8 v7
(integer) 6
127.0.0.1:6379> smembers myset
1) "v8"
2) "v2"
3) "v5"
4) "v7"
5) "v4"
6) "v3"
7) "v1"
8) "v6"
127.0.0.1:6379> srandmember myset 1
1) "v3"
127.0.0.1:6379>
*/
final List<String> values=stringRedisTemplate.opsForSet().randomMembers(KEY,2);
System.out.println(values);
/**
* 127.0.0.1:6379> srandmember myset 2
* 1) "v8"
* 2) "v2"
* 127.0.0.1:6379>
*/
}
7. spop
spop:弹出元素,格式是:spop set的key
@Test
public void spop(){
/**
* 示例1:相当于执行 sismember myset v1
*/
final String value=stringRedisTemplate.opsForSet().pop(KEY);
// final List<String> values = stringRedisTemplate.opsForSet().pop(KEY, 2);
System.out.println(value);
/**
* 127.0.0.1:6379> spop myset
* 127.0.0.1:6379> smembers myset
* 1) "v8"
* 2) "v2"
* 3) "v3"
* 4) "v1"
* 5) "v6"
* 6) "v5"
* 7) "v4"
* 8) "v7"
* 127.0.0.1:6379> smembers myset
* 1) "v8"
* 2) "v2"
* 3) "v3"
* 4) "v1"
* 5) "v6"
* 6) "v4"
* 7) "v7"
* 127.0.0.1:6379>
*/
}
8. sdiff
sdiff:差集,返回在第一个set里面而不在后面任何一个set里面的项。格式是:sdiff set的key 用来比较的多个set的key
@Test
public void sdiff(){
/**
* 示例1:相当于执行 sismember myset v1
*/
final Set<String> difference=stringRedisTemplate.opsForSet().difference(KEY,"myset1");
difference.forEach(System.out::println);
/**
* 127.0.0.1:6379> sadd myset1 1 2 3 v3 v6 v6 v8
* (integer) 6
* 127.0.0.1:6379> smembers myset1
* 1) "v8"
* 2) "2"
* 3) "3"
* 4) "v3"
* 5) "1"
* 6) "v6"
* 127.0.0.1:6379> sdiff myset myst1
* 1) "v8"
* 2) "v2"
* 3) "v7"
* 4) "v4"
* 5) "v3"
* 6) "v1"
* 7) "v6"
* 127.0.0.1:6379>
*/
}
9.sinter
sinter:交集,返回多个set里面都有的项。格式是:sinter 多个set的key
@Test
public void sinter(){
/**
* 示例1:相当于执行 sinter myset myset1
*/
final Set<String> myset1=stringRedisTemplate.opsForSet().intersect(KEY,"myset1");
myset1.forEach(System.out::println);
/**
* 127.0.0.1:6379> sinter myset myset1
* 1) "v8"
* 2) "v3"
* 3) "v6"
* 127.0.0.1:6379>
*/
}
10. sinterstore
sinterstore:交集并保留结果。格式是:sinterstore 存放结果的key 多个set的key
@Test
public void sinterstore(){
/**
* 示例1:相当于执行 sinterstore myset2 myset myset1
*/
stringRedisTemplate.opsForSet().differenceAndStore(KEY,"myset1","myset3");
/**
* 127.0.0.1:6379> sinterstore myset2 myset myset1
* (integer) 3
* 127.0.0.1:6379> smembers myset2
* 1) "v3"
* 2) "v8"
* 3) "v6"
* 127.0.0.1:6379>
*/
}
11.sunion
sunion:并集。格式是:sunion 多个set的key
@Test
public void sunion(){
/**
* 示例1:相当于执行 sunion myset myset1
*/
final Set<String> union=stringRedisTemplate.opsForSet().union(KEY,"myset1");
union.forEach(System.out::println);
/**
* 127.0.0.1:6379> sunion myset myset1
* 1) "v3"
* 2) "v1"
* 3) "v6"
* 4) "v8"
* 5) "v2"
* 6) "2"
* 7) "3"
* 8) "v4"
* 9) "v7"
* 10) "1"
* 127.0.0.1:6379>
*/
}
12.sunionstore
sunionstore:并集并保留结果。格式是:sunionstore 存放结果的set的key 多个set的key
@Test
public void sunionstore(){
/**
* 示例1:相当于执行 sunionstore myset4 myset myset1
*/
final Long sunionstore=stringRedisTemplate.opsForSet().unionAndStore(KEY,"myset1","myset4");
System.out.println(sunionstore);
/**
* 127.0.0.1:6379> smembers myset4
* 1) "v3"
* 2) "v1"
* 3) "v6"
* 4) "v8"
* 5) "v2"
* 6) "2"
* 7) "3"
* 8) "v4"
* 9) "v7"
* 10) "1"
* 127.0.0.1:6379>
*/
}
Redis对ZSet类型操作
1. zadd
zadd :添加元素,格式是:zadd zset的key score值 项的值, Score和项可以是多对,score可以是整数,也可以是浮点数,还可以是+inf表示无穷大,-inf表示负无穷大
@Test
public void zadd() {
/**
* 示例1:相当于执行 127.0.0.1:6379> zadd myzset 10 v1
*/
final Boolean add = stringRedisTemplate.opsForZSet().add(KEY, "v4", 40);
System.out.println(add);
Set<ZSetOperations.TypedTuple<String>> values = new HashSet<>();
values.add(new DefaultTypedTuple("v5", 50.0));
values.add(new DefaultTypedTuple("v6", 60.0));
final Long add1 = stringRedisTemplate.opsForZSet().add(KEY, values);
System.out.println(add1);
/**
* 127.0.0.1:6379> zadd myzset 10 v1
* (integer) 1
* 127.0.0.1:6379> zadd myzset 10 v1 20 v2 30 v3
* (integer) 2
* 127.0.0.1:6379> zrange myzset 0 -1
* 1) "v1"
* 2) "v2"
* 3) "v3"
* 4) "v4"
* 5) "v5"
* 6) "v6"
* 127.0.0.1:6379> zrange myzset 0 -1 withscores
* 1) "v1"
* 2) "10"
* 3) "v2"
* 4) "20"
* 5) "v3"
* 6) "30"
* 7) "v4"
* 8) "40"
* 9) "v5"
* 10) "50"
* 11) "v6"
* 12) "60"
*/
}
2. zrange
zrange :获取索引区间内的元素,格式是:zrange zset的key 起始索引 终止索引 (withscore)
@Test
public void zrange() {
/**
* 示例1:相当于执行 zrange myzset 0 -1 withscores
* 示例2:相当于执行 zzrange myzset 0 -1
*/
final Set<String> range = stringRedisTemplate.opsForZSet().range(KEY, 0, -1);
range.forEach(System.out::println);
final Set<ZSetOperations.TypedTuple<String>> v2 = stringRedisTemplate.opsForZSet().differenceWithScores(KEY, "otherKey");
System.out.println(JSONObject.toJSON(v2));
/**
* v1
* v2
* v3
* v4
* v5
* v6
* [{"score":10.0,"value":"v1"},{"score":20.0,"value":"v2"},{"score":30.0,"value":"v3"},{"score":40.0,"value":"v4"},{"score":50.0,"value":"v5"},{"score":60.0,"value":"v6"}]
* 127.0.0.1:6379> zrange myzset 0 -1
* 1) "v1"
* 2) "v2"
* 3) "v3"
* 4) "v4"
* 5) "v5"
* 6) "v6"
* 127.0.0.1:6379> zrange myzset 0 -1 withscores
* 1) "v1"
* 2) "10"
* 3) "v2"
* 4) "20"
* 5) "v3"
* 6) "30"
* 7) "v4"
* 8) "40"
* 9) "v5"
* 10) "50"
* 11) "v6"
* 12) "60"
*/
}
3. zrangebyscore
// zrangebyscore :获取分数区间内的元素,格式是:zrangebyscore zset的key 起始score 终止score (withscore),默认是包含端点值的,如果加上"("表示不包含,后面还可以加上limit来限制。
@Test
public void score() {
/**
* 示例1:相当于执行 zrangebyscore myzset 10 30 默认是包含端点值的,如果加上"("表示不包含,后面还可以加上limit来限制。
*/
final Set<String> range = stringRedisTemplate.opsForZSet().rangeByScore(KEY, 10, 30);
range.forEach(System.out::println);
/**
* 127.0.0.1:6379> zrangebyscore myzset 10 30
* 1) "v1"
* 2) "v2"
* 3) "v3"
* 127.0.0.1:6379>
*/
}
4. zrem
//zrem 删除元素,格式是:zrem zset的key 项的值,项的值可以是多个
@Test
public void zrem() {
/**
* 示例1:相当于执行 zrem myzset v1
*/
final Long zremove = stringRedisTemplate.opsForZSet().remove(KEY, "v1");
System.out.println(zremove);
/**
* 127.0.0.1:6379> zrange myzset 0 -1 withscores
* 1) "v1"
* 2) "10"
* 3) "v2"
* 4) "20"
* 5) "v3"
* 6) "30"
* 7) "v4"
* 8) "40"
* 9) "v5"
* 10) "50"
* 11) "v6"
* 12) "60"
* 127.0.0.1:6379> zrem myzset v1
* (integer) 1
* 127.0.0.1:6379> zrange myzset 0 -1 withscores
* 1) "v2"
* 2) "20"
* 3) "v3"
* 4) "30"
* 5) "v4"
* 6) "40"
* 7) "v5"
* 8) "50"
* 9) "v6"
* 10) "60"
* 127.0.0.1:6379>
*/
}
5. zcard
获取集合中元素个数,格式是:zcard zset的key
@Test
public void zcard() {
/**
* 示例1:相当于执行 zcard myzset
*/
final Long zcard = stringRedisTemplate.opsForZSet().size(KEY);
System.out.println(zcard);
/**
* 127.0.0.1:6379> zcard myzset
* (integer) 5
* 127.0.0.1:6379>
*/
}
6.zincrby
zincrby :增减元素的score,格式是:zincrby zset的key 正负数字 项的值
@Test
public void zincrby() {
/**
* 示例1:相当于执行 zincrby myzset 21 v1
*/
final Double aDouble = stringRedisTemplate.opsForZSet().incrementScore(KEY, "v1", 21);
System.out.println(aDouble);
/**
* 127.0.0.1:6379> zincrby myzset 0 v0
* "0"
* 127.0.0.1:6379> zrange myzset 0 -1 withscores
* 1) "v0"
* 2) "0"
* 3) "v2"
* 4) "20"
* 5) "v1"
* 6) "21"
* 7) "v3"
* 8) "30"
* 9) "v4"
* 10) "40"
* 11) "v5"
* 12) "50"
* 13) "v6"
* 14) "60"
* 127.0.0.1:6379>
*/
}
7.zrank
zrank : 获取项在zset中的索引,格式是:zrank zset的key 项的值
@Test
public void zrank() {
/**
* 示例1:相当于执行 zrank myzset v2
*/
final Long rank = stringRedisTemplate.opsForZSet().rank(KEY,"v2");
System.out.println(rank);
/**
* 127.0.0.1:6379> zrank myzset v2
* (integer) 1
*/
}
8.zscore
zscore :获取元素的分数,格式是:zscore zset的key 项的值,返回项在zset中的score
@Test
public void zscore() {
/**
* 示例1:相当于执行 zscore myzset v2
*/
final Double zscore = stringRedisTemplate.opsForZSet().score(KEY,"v2");
System.out.println(zscore);
/**
* 127.0.0.1:6379> zscore myzset v2
* "20"
* 127.0.0.1:6379>
*/
}
String类:
1.redisTemplate.opsForValue().set(key,value)); //设置指定键的值
2.redisTemplate.opsForValue().get(key)); //获取指定键的值。
3.redisTemplate.opsForValue().get(key, start, end);//获取存储在键上的字符串的子字符串。
4.redisTemplate.opsForValue().getAndSet(key, value);//设置键的字符串值并返回其旧值。
5.redisTemplate.opsForValue().getBit(key, offset);//返回在键处存储的字符串值中偏移处的位值。
6.redisTemplate.opsForValue().multiGet(keys);//获取所有给定键的值
7.redisTemplate.opsForValue().setBit(key, offset, value);//存储在键上的字符串值中设置或清除偏移处的位
8.redisTemplate.opsForValue().set(K key, V value, long timeout, TimeUnit unit);//使用键和到期时间来设置值
9.redisTemplate.opsForValue().setIfAbsent(key, value);//设置键的值,仅当键不存在时
10.redisTemplate.opsForValue().set(K key, V value, long offset);//在指定偏移处开始的键处覆盖字符串的一部分
11.redisTemplate.opsForValue().size(key));//获取存储在键中的值的长度
12.redisTemplate.opsForValue().multiGet(Collection<K> keys);//为多个键分别设置它们的值
13.redisTemplate.opsForValue().multiSetIfAbsent(Map<? extends K, ? extends V> m);// 为多个键分别设置它们的值,仅当键不存在时
Hash类:
1.redisTemplate.opsForHash().delete(H key, Object... hashKeys);//删除一个或多个哈希字段。
2.redisTemplate.opsForHash().hasKey(key, hashKey);//判断是否存在散列字段。
3.redisTemplate.opsForHash().get(key, hashKey);// 获取存储在指定键的哈希字段的值。
4.redisTemplate.opsForHash().entries(key);//返回map集合
5.redisTemplate.opsForHash().increment(H key, HK hashKey, long delta);//获取存储在指定键的哈希中的所有字段和值
6.redisTemplate.opsForHash().keys(key);//返回map的key集合Set
7.redisTemplate.opsForHash().size(key); //获取散列中的字段数量
8.redisTemplate.opsForHash().multiGet(H key, Collection<HK> hashKeys);//获取所有给定哈希字段的值
9.redisTemplate.opsForHash().putAll(H key, Map<? extends HK, ? extends HV> m);//为多个哈希字段分别设置它们的值
10.redisTemplate.opsForHash().put(key, hashKey, value);//设置散列字段的字符串值
11.redisTemplate.opsForHash().putIfAbsent(key, hashKey, value);//仅当字段不存在时,才设置散列字段的值
12.redisTemplate.opsForHash().values(key);// 获取哈希中的所有值
list类:
1.redisTemplate.opsForList().leftPush(key, value);//从左向右存压栈
2.redisTemplate.opsForList().rightPush(key, value);//从右向左存压栈
3.redisTemplate.opsForList().size(key);//获取大小
4.redisTemplate.opsForList().range(key, start, end);//范围检索,根据下标,返回[start,end]的List
5.redisTemplate.opsForList().remove(key, i, value);//移除key中值为value的i个,返回删除的个数;如果没有这个元素则返回0
6.redisTemplate.opsForList().index(key, index);//检索
7.redisTemplate.opsForList().set(key, index, value);//赋值
8.redisTemplate.opsForList().trim(key, start, end);//裁剪,void,删除除了[start,end]以外的所有元素
9.redisTemplate.opsForList().rightPopAndLeftPush(String sourceKey, String destinationKey);//将源key的队列的右边的一个值删除,然后塞入目标key的队列的左边,返回这个值
set类:
1.redisTemplate.opsForSet().add(key, value); ;//如果不存在这个字符串,将字符串存入set集合,返回存入元素的个数;如果存在这个字符串就不操作,返回0;
2.redisTemplate.opsForSet().members(key);//列出key的所有set集合
3.redisTemplate.opsForSet().randomMember(key);//随机取key的一个set元素
4.redisTemplate.opsForSet().distinctRandomMembers(key,n);//随机取N次key的元素,组成一个set集合,不可以重复取出
5.redisTemplate.opsForSet().size(key);//返回set长度
6.redisTemplate.opsForSet().difference(key, otherkey);//比较key与otherKey的set集合,取出与otherKey的set集合不一样的set集合
7.redisTemplate.opsForSet().intersect(key, otherkey);//比较key与otherKey的set集合,取出二者交集,返回set交集合
8.redisTemplate.opsForSet().union(key, otherkey);比较key与otherKey的set集合,取出二者并集,返回set并集合
9.redisTemplate.opsForSet().unionAndStore(key, otherkey,destkey);比较key与otherKey的set集合,取出二者并集,并存入destKey集合,返回destKey集合个数