UserToken userToken = new UserToken();
userToken.setMobile("176****6708");
List list = Lists.newArrayList(userToken);
redisTemplate.opsForValue().set("test",list,5,TimeUnit.MINUTES);
2、使用Jackson2JsonRedisSerializer序列化后的数据形式:
3、使用Jackson2JsonRedisSerializer反序列化时报错
List list2 = (List)redisTemplate.opsForValue().get("test");
list2.forEach(userToken1 -> System.out.println(userToken1.getMobile()));
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.com.baisq.model.UserToken
原因:序列化带泛型的数据时,会以map的结构进行存储,反序列化是不能将map解析成对象。
4、解决方案:序列化存储时,转成JSON字符串
UserToken userToken = new UserToken();
userToken.setMobile("176****6708");
List list = Lists.newArrayList(userToken);
redisTemplate.opsForValue().set("test3", JSON.toJSONString(userToken),5,TimeUnit.MINUTES);
String list2 = (String)redisTemplate.opsForValue().get("test3");
JSON.parseArray(list2,UserToken.class).forEach(userToken1 -> System.out.println(userToken1.getMobile()));
RedisTemplate template = new RedisTemplate();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
UserToken userToken = new UserToken();
userToken.setMobile("176****6708");
List list = Lists.newArrayList(userToken);
redisTemplate.opsForValue().set("test2",list,5,TimeUnit.MINUTES);
2、使用GenericJackson2JsonRedisSerializer序列化后的数据形式:
3、使用GenericJackson2JsonRedisSerializer可以正常反序列化
List list2 = (List)redisTemplate.opsForValue().get("test2");
list2.forEach(userToken1 -> System.out.println(userToken1.getMobile()));
long start = System.currentTimeMillis();
UserToken userToken = new UserToken();
userToken.setMobile("176****6708");
List list = Lists.newArrayListWithCapacity(100);
for (int i = 0; i < 1000; i++) {
list.add(userToken);
}
redisTemplate.opsForValue().set("test",JSON.toJSONString(list),5,TimeUnit.MINUTES);
String data = (String)redisTemplate.opsForValue().get("test");
List list2 = JSON.parseArray(data, UserToken.class);
long end = System.currentTimeMillis();
long time = end - start;
public class Server
{
//用来存储所有连接上来的客户
private List<ServerThread> clients;
public static void main(String[] args)
{
Server s = new Server();
s.startServer(9988);
}
publi
I got serveral questions about auto.offset.reset. This configuration parameter governs how consumer read the message from Kafka when there is no initial offset in ZooKeeper or
two cursors.
Make the first cursor go K steps first.
/*
* 第 13 题:题目:输入一个单向链表,输出该链表中倒数第 k 个节点
*/
public void displayKthItemsBackWard(ListNode head,int k){
ListNode p1=head,p2=head;
一、sh 脚本不执行的原因
sh脚本不执行的原因 只有2个
1.权限不够
2.sh脚本里路径没写完整。
二、解决You have new mail in /var/spool/mail/root
修改/usr/share/logwatch/default.conf/logwatch.conf配置文件
MailTo =
MailFrom
三、查询连接数
$ git push joe prod-2295-1
To [email protected]:joe.le/dr-frontend.git
! [rejected] prod-2295-1 -> prod-2295-1 (non-fast-forward)
error: failed to push some refs to '[email protected]