StringRedisTemplate 多余空格问题

StringRedisTemplate 多余空格问题

使用StringRedisTemplate的set方法为key设置过期时间时出现了redis中的value前出现了一大串的utf8编码后的空格。经过一番调研发现,是我使用的方法错误了,误以为提供的void set(K var1, V var2, long var3);方法就是设置过期时间的,实则上下载源码后根据注释就能看出来

/**
	 * Overwrite parts of {@code key} starting at the specified {@code offset} with given {@code value}.
	 *
	 * @param key must not be {@literal null}.
	 * @param value
	 * @param offset
	 * @see <a href="https://redis.io/commands/setrange">Redis Documentation: SETRANGE</a>
	 */
	void set(K key, V value, long offset);

这个注释翻译下的意思就是:将value从指定的位置开始覆盖原有的值。如果指定的开始位置大于字符串长度,先补空格在追加。

实际设置过期时间的方法为void set(K key, V value, long timeout, TimeUnit unit);

/**
	 * Set the {@code value} and expiration {@code timeout} for {@code key}.
	 *
	 * @param key must not be {@literal null}.
	 * @param value must not be {@literal null}.
	 * @param timeout the key expiration timeout.
	 * @param unit must not be {@literal null}.
	 * @see <a href="https://redis.io/commands/setex">Redis Documentation: SETEX</a>
	 */
	void set(K key, V value, long timeout, TimeUnit unit);

参考文章: 使用StringRedisTemplate保存的value前面有很多空格的坑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值