27

Redis | 001能做什么?

 5 years ago
source link: https://UncleCatMySelf.github.io/2019/02/24/001redis/?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

本博客猫叔的博客,转载请申明出处

前言

本系列整理出于《Redis深度历险:核心原理与应用实践》一书,摘抄整理读后感与总结。

好的程序员都会Redis

说说Redis能做什么呢?

  • 1、记录帖子的点赞数、评论数和点击数(hash);
  • 2、记录用户的帖子ID列表(排序),便于快速显示用户的帖子列表(zset);
  • 3、记录帖子的标题、摘要、作者和封面信息,用于列表页展示(hash);
  • 4、记录帖子的点赞用户ID列表,评论ID列表,用于显示和去重计数(zset);
  • 5、缓存近期热帖内容(帖子内容的空间占用比较大),减少数据库压力(hash);
  • 6、记录帖子的相关文章ID,根据内容推荐相关帖子(list);
  • 7、如果帖子ID是整数自增的,可以使用Redis来分配帖子ID(计数器);
  • 8、收藏集和帖子之间的关系(zset);
  • 9、记录热榜帖子ID列表、总热榜和分类热榜(zset);
  • 10、缓存用户行为历史,过滤恶意行为(zset、hash);

安装Redis

Redis的安装主要有以下三种方式:

  • 1、使用Docker安装;
  • 2、通过GitHub源码编译;
  • 3、直接安装apt-get install(Ubuntu)、yum install(RedHat)、brew install(Mac)

1、Docker方式

# 拉取 Redis 镜像
> docker pull redis
# 运行 Redis 容器
> docker run --name myredis -d -p6379:6379 redis
# 执行容器中的 redis-cli 可以直接使用命令行操作 redis
> docker exec -it myredis redis-cli

2、GitHub源码编译

# 下载源码
> git clone --branch 2.8 --depth 1 [email protected]:antirez/redis.git
> cd redis
# 编译
> make
> cd src
# 运行服务器,daemonize表示在后台运行
> ./redis-server --daemonize yes
# 运行命令行
> ./redis-cli

3、直接安装

# mac
> brew install redis
# ubuntu
> apt-get install redis
# redhat
> yum install redis
# 运行客户端
> redis-cli

公众号:Java猫说

现架构设计(码农)兼创业技术顾问,不羁平庸,热爱开源,杂谈程序人生与不定期干货。

EJFriqR.jpg!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK