Redis Hset 命令
语法
redis Hset 命令基本语法如下:
redis 127.0.0.1:6379> HSET KEY_NAME FIELD VALUE
实例
实例
redis 127.0.0.1:6379> HSET myhash field1 "foo"
OK
redis 127.0.0.1:6379> HGET myhash field1
"foo"
redis 127.0.0.1:6379> HSET website google "www.g.cn" # 设置一个新域
(integer) 1
redis 127.0.0.1:6379>HSET website google "www.google.com" # 覆盖一个旧域
redisTemplate的相关api:
/**
* Increment {@code value} of a hash {@code hashKey} by the given {@code delta}.
*
* @param key must not be {@literal null}.
* @param hashKey must not be {@literal null}.
* @param delta
* @return {@literal null} when used in pipeline / transaction.
*/
Long increment(H key, HK hashKey, long delta);
具体Java实现
private Long storyIncrease(Integer id, String type) {
Long l = stringRedisTemplate.opsForHash().increment(storyKey(id), type, 1L);
stringRedisTemplate.expire(storyKey(id), 3L, TimeUnit.DAYS);
return l;
}
为什么用stringredistemplate
来源:CSDN
作者:雪中鱼01
链接:https://blog.csdn.net/songkai558919/article/details/104591431