package com.redis.dao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import com.redis.dto.User;
@Component
public class UserDao {
@Autowired
private RedisTemplate<String, User> redis;
@Autowired
private RedisTemplate<String, String> rediss;
public List<String> toAdd() {
// TODO Auto-generated method stub
ListOperations<String, String> opsForList = rediss.opsForList();
// opsForList.leftPush("paytype", "现金");
// opsForList.leftPush("paytype", "信用卡");
// opsForList.leftPush("paytype", "储蓄卡");
// opsForList.leftPush("paytype", "微信");
// opsForList.leftPush("paytype", "支付宝");
List<String> range = opsForList.range("paytype", 0, -1);
return range;
}
public List<User> findUserList() {
// TODO Auto-generated method stub
HashOperations<String, String, User> opsForHash = redis.opsForHash();
List<User> list = opsForHash.values("user");
return list;
}
public void add(User user) {
// TODO Auto-generated method stub
HashOperations<String, String, User> opsForHash = redis.opsForHash();
opsForHash.put("user", user.getUid(), user);
}
public void del(String id) {
// TODO Auto-generated method stub
HashOperations<String, String, User> opsForHash = redis.opsForHash();
opsForHash.delete("user", id);
}
public User toUpd(String id) {
// TODO Auto-generated method stub
HashOperations<String, String, User> opsForHash = redis.opsForHash();
User user = opsForHash.get("user", id);
return user;
}
public void update(User user) {
// TODO Auto-generated method stub
HashOperations<String, String, User> opsForHash = redis.opsForHash();
opsForHash.put("user", user.getUid(), user);
}
}
十年前你是谁,一年前你是谁,甚至昨天你是谁,都不重要,重要的是,今天你是谁,以及明天你将成为谁,1999年马云被人说是大骗子,74年大家还在笑话的洗车工周润发,14岁的王宝强还在做民工,曾被老婆养六年的李安,曾被中国十大影业拒绝的徐峥,曾在校篮球队落选,被体育老师看不起的乔丹,曾被无数白人排斥的黑鬼迈克尓杰克逊,曾被拒绝1000多次才当上演员的史泰龙,人生或多或少都会遇到挫折,除非你的心脏停止跳动了,所以梦想不能轻易放弃,想成功就得先努力,有梦不怕痛,想赢别喊停
本文介绍了一个基于Spring Data Redis的Java项目中用户操作的数据访问对象(DAO)层实现细节,包括用户信息的添加、查询、更新和删除等功能。
756

被折叠的 条评论
为什么被折叠?



