package com.springboot.springboot.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;
import redis.clients.jedis.*;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
* @author WilsonSong
* @date 2018/6/1
*/
@Service
public class JedisAdapter implements InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(JedisAdapter.class);
private JedisPool pool;
public static void print(int index, Object object) {
System.out.println(String.format("%d, %s", index, object.toString()));
}
@Override
public void afterPropertiesSet() throws Exception {
pool = new JedisPool("redis://localhost:6379/10");
}
//增加
public long sadd(String key, String value) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.sadd(key, value);
} catch (Exception e) {
logger.error("Redis添加数据异常" + e.getMessage());
} finally {
if (jedis != null) {
jedis.close();
}
}
return 0;
}
public long srem(String key, String value){
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.srem(key,value);
}catch (Exception e){
logger.error("Redis删除数据异常");
}finally {
if (jedis != null){
jedis.close();
}
}
return 0;
}
//查询数量
public long scard(String key){
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.scard(key);
}catch (Exception e){
logger.error("Redis统计数量异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return 0;
}
public boolean sismember(String key, String value){
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.sismember(key,value);
}catch (Exception e){
logger.error("Redis查询异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return false;
}
public long lpush(String key, String value){
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.lpush(key,value);
}catch (Exception e){
logger.error("Redis队列添加异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return 0;
}
public List<String> lrange(String key, int start, int end){
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.lrange(key, start, end);
}catch (Exception e){
logger.error("取值发生异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return null;
}
public List<String> brpop(int timeout, String key){
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.brpop(timeout,key);
}catch (Exception e){
logger.error("Redis队列弹出数据异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return null;
}
//从线程池里获取一个jedis的线程
public Jedis getJedis(){
return pool.getResource();
}
//jedis的事务 transaction是jedis中的事务管理对象
public Transaction multi(Jedis jedis){
try{
return jedis.multi(); //开启事务
}catch (Exception e){
logger.error("事务开启异常" + e.getMessage());
}
return null;
}
//multi开启事务执行之后再zsort中返回的是list
public List<Object> exec(Transaction tx, Jedis jedis){
try{
return tx.exec(); //执行事务
}catch (Exception e){
logger.error("事务启动异常" + e.getMessage());
}finally {
//当事务不为空的时候要将其关闭
if (tx != null){
try{
tx.close();
}catch (IOException ioe){
logger.error("发生异常" + ioe.getMessage());
}
}
//把jedis关闭
if(jedis != null){
jedis.close();
}
}
return null;
}
//把用户加到关注的列表中
public long zadd(String key, double score, String value){
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.zadd(key,score,value);
}catch (Exception e){
logger.error("添加用户关注失败" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return 0;
}
public Set<String> zrevrange(String key, int start, int end){
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.zrevrange(key, start, end);
}catch (Exception e){
logger.error("发生异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return null;
}
public long zcard(String key){
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.zcard(key);
}catch (Exception e){
logger.error("发生异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return 0;
}
public Double zscore(String key, String member){ //Double是类,是double的实现类,double是属性
Jedis jedis = null;
try{
jedis = pool.getResource();
return jedis.zscore(key, member);
}catch (Exception e){
logger.error("发生异常" + e.getMessage());
}finally {
if (jedis != null){
jedis.close();
}
}
return null;
}
// public static void main(String[] args){
// Jedis jedis = new Jedis("redis://localhost:6379/9"); //连接6379端口的9号数据库
//
// jedis.flushDB(); //把DB的数据删除
//
// //文本 get set
// jedis.set("hello","world");
// print(1,jedis.get("hello"));
// jedis.rename("hello","newHello");
// print(1,jedis.get("newHello"));
// jedis.setex("hello2",15,"world"); //15秒后过期 验证码,短信验证等等
//
// //数值加减
// jedis.set("pv", "100");
// jedis.incr("pv"); //加1
// print(2, jedis.get("pv"));
// jedis.incrBy("pv",5); //加5
// print(2,jedis.get("pv"));
// jedis.decr("pv");
// print(2,jedis.get("pv"));
// jedis.decrBy("pv", 5);
// print(2, jedis.get("pv"));
//
// print(3,jedis.keys("*"));
//
// //list命令
// String listName = "list";
// jedis.del(listName); //存在的话就删掉
// for (int i=0; i<10; ++i){
// jedis.lpush(listName, "a"+String.valueOf(i));
// }
// print(4, jedis.lrange(listName, 0 , 9)); //取出从0到9个
// print(4, jedis.lrange(listName, 1 , 6)); //取出从0到9个
// print(4, jedis.llen(listName)); //list 的长度
// print(4, jedis.lpop(listName)); //list中的值弹出来,弹出一个,弹出之后就没有�
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于SpringBoot+Mybatis实现的仿写知乎问答的网站源码+项目说明.zip SpringBoot+SpringMVC+Mybatis 仿写知乎问答的网站 【实现的功能】 登陆注册,增删改查,提问,评论,敏感词过滤,站内信,点赞,新鲜事,邮件通知,solr搜索等 框架:SpringBoot + Mybatis 存储:数据库使用MySQL 缓存:Redis 模板引擎:freemarker 搜索引擎:solr 【技术栈】 基于redis的缓存 基于前缀树的敏感词过滤 异步框架的设计,底层使用的是Redis的异步队列,使用异步队列实现站内信,点赞,邮件等功能 solr结合IKAnalyzer自定义中文分词,实现搜索引擎 timeline推拉模式结合的时间轴,渲染新鲜事,实现内容的推送 【备注】 主要针对计算机相关专业的正在做毕设的学生和需要项目实战的Java学习者。 【特别强调】 1、csdn上资源保证是完整最新,会不定期更新优化; 2、请用自己的账号在csdn官网下载,若通过第三方代下,博主不对您下载的资源作任何保证,且不提供任何形式的技术支持和答疑!!!
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot+Mybatis实现的仿写知乎问答的网站源码+项目说明.zip (805个子文件)
JedisAdapter.class 8KB
JedisAdapter.class 8KB
FollowController.class 8KB
FollowController.class 8KB
QuestionController.class 7KB
QuestionController.class 7KB
MessageController.class 6KB
MessageController.class 6KB
indexController.class 6KB
indexController.class 6KB
MultiThreadTests.class 5KB
registerController.class 5KB
registerController.class 5KB
FeedHandler.class 5KB
FeedHandler.class 5KB
FollowService.class 5KB
SearchService.class 5KB
SearchService.class 5KB
FollowService.class 5KB
userService.class 5KB
userService.class 5KB
homeController.class 5KB
homeController.class 5KB
MailSender.class 4KB
MailSender.class 4KB
SensitiveService.class 4KB
SensitiveService.class 4KB
SearchController.class 4KB
SearchController.class 4KB
CommentController.class 4KB
CommentController.class 4KB
PassportInterceptor.class 4KB
PassportInterceptor.class 4KB
EventConsumer.class 4KB
EventConsumer.class 4KB
LikeController.class 3KB
LikeController.class 3KB
FeedController.class 3KB
FeedController.class 3KB
InitDatabaseTests.class 3KB
WendaUtil.class 3KB
WendaUtil.class 3KB
EventModel.class 3KB
EventModel.class 3KB
FollowHandler.class 3KB
FollowHandler.class 3KB
LikeHandler.class 3KB
LikeHandler.class 3KB
EventConsumer$1.class 2KB
EventConsumer$1.class 2KB
CommentService.class 2KB
CommentService.class 2KB
MessageDAO.class 2KB
MessageDAO.class 2KB
LoginRequiredInterceptor.class 2KB
LoginRequiredInterceptor.class 2KB
MessageService.class 2KB
MessageService.class 2KB
Message.class 2KB
Message.class 2KB
SensitiveService$TrieNode.class 2KB
SensitiveService$TrieNode.class 2KB
questionService.class 2KB
questionService.class 2KB
CommentDAO.class 2KB
CommentDAO.class 2KB
AddQuestionHandler.class 2KB
AddQuestionHandler.class 2KB
Comment.class 2KB
Comment.class 2KB
LikeService.class 2KB
LikeService.class 2KB
Feed.class 2KB
Feed.class 2KB
logAspect.class 2KB
logAspect.class 2KB
RedisKeyUtil.class 2KB
RedisKeyUtil.class 2KB
LikeServiceTests.class 2KB
Question.class 2KB
Question.class 2KB
User.class 2KB
User.class 2KB
WendaWepConfiguration.class 2KB
WendaWepConfiguration.class 2KB
FeedService.class 2KB
FeedService.class 2KB
LoginExceptionHandler.class 2KB
LoginExceptionHandler.class 2KB
EventType.class 2KB
EventType.class 2KB
questionDAO.class 1KB
questionDAO.class 1KB
loginTickets.class 1KB
loginTickets.class 1KB
MultiThreadTests$2.class 1KB
Customer.class 1KB
userDAO.class 1KB
userDAO.class 1KB
EventProducer.class 1KB共 805 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
onnx
- 粉丝: 1w+
上传资源 快速赚钱
我的内容管理
展开
我的资源
快来上传第一个资源
我的收益 登录查看自己的收益
我的积分
登录查看自己的积分
我的C币
登录后查看C币余额
我的收藏
我的下载
下载帮助
前往需求广场,查看用户热搜最新资源
- ssm-jvm-1.4.26.jar
- mediastoredata-jvm-1.0.68-javadoc.jar
- neptunedata-jvm-1.3.100-sources.jar
- kinesisvideo-jvm-1.3.6-javadoc.jar
- wafregional-jvm-1.4.21.jar
- way-gdrive-0.1.1-test-sources.jar
- iotdeviceadvisor-jvm-1.4.36.jar
- kinesisanalyticsv2-jvm-1.0.36-sources.jar
- pinpoint-jvm-1.5.7-sources.jar
- voyager-core-android-debug-1.0.0-rc08-sources.jar
- archbase-domain-driven-design-spec-1.0.27-sources.jar
- ssmsap-1.5.4-javadoc.jar
- resourceexplorer2-jvm-1.5.2-javadoc.jar
- kinesisvideo-jvm-1.0.0-javadoc.jar
- s3outposts-jvm-1.2.9.jar
- lambda-jvm-0.21.2-beta-sources.jar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功