redis

本文涉及的产品
云原生内存数据库 Tair,内存型 2GB
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Redis 版,倚天版 1GB 1个月
简介: -

大部分企业可能还在使用redis4的版本,今年redis也迎来了6的版本更新,这次更新最大的改变应该就是支持了多线程,性能相较于上一代有大幅提升,

springboot+redis开发

redisconfig需要序列化redis的value和key等类型

序列化就是将对象包装成各种文件

反序列化就是将对象取出

java的序列化规则

1.静态资源不能序列化,因此static修饰的不能序列化,如果仍能反序列化,那是jvm的static对象,

static修饰的为类状态,序列号修饰的是对象状态

2.transient修饰的不能序列化,常在银行卡密码等处使用,防止反序列化

java的序列号版本

会自动根据类的改变生成,也可以自己定义

应用场景,微信的更新,如果自动生成序列号,那么每次更新都会强制执行,否则无法使用。但是自定义序列号,可以有老版本和新版本,不更新无法体验新功能,但是不影响使用。

window安装及使用

下载安装包安装

Redis地址: https://github.com/MicrosoftArchive/redis/releases

桌面管理可视化

RedisStudio地址: https://github.com/cinience/RedisStudio/releases

Another Redis Desktop Manager 下载地址:

Github:https://github.com/qishibo/AnotherRedisDesktopManager/releases

Gitee:https://gitee.com/qishibo/AnotherRedisDesktopManager/releases

修改conf文件的参数

举例:

设置密码--默认无密码,设置后执行redis的操作需要密码

常用命令

#启动服务

redis-server.exe --service-start

#终止服务

redis-server.exe --service-stop

#开启redis

redis-cli.exe -h ip地址 -p 端口


LINUX安装

https://blog.csdn.net/hello_list/article/details/123003445

gcc升级到gcc9.0

yum -y install centos-release-scl

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

#scl命令启用只是临时的,新开的会话默认还是原gcc版本。


#如果要长期使用gcc 9.1的话执行下面的命令即可:

echo -e "

source /opt/rh/devtoolset-9/enable" >>/etc/profile

编译安装

#解压

tar -zxvf redis-6.0.3.tar.gz

#编译

cd redis-6.0.3/

make

make install PREFIX=/opt/app/redis6

 

#如果编译出错之后再编译可以先执行命令删除之前的编译文件

make distclean







#测试需要依赖tcl

yum install tcl -y

#测试

make test


#创建data文件夹保存数据

mkdir /opt/app/redis6/data

#赋值redis.conf到指定文件

cp /home/wyk/redis-6.0.3/redis.conf /opt/app/redis6/bin/

修改redis.conf

vim /opt/app/redis6/bin/redis.conf






#daemonize no 改为yes,开启后台运行,默认是前台运行

daemonize yes

 

#把这一行注释,监听所有IP

#bind 127.0.0.1

 

 

#protected-mode yes 如果改为no,则是关闭保护模式,这种模式下不能配置系统服务,建议还是开启

protected-mode yes

 

#requirpass,保护模式开启的时候要配置密码或者bind ip

requirepass 123456

 

#修改本参数,指定数据目录

dir /opt/app/redis6/data

 

#修改本参数,指定日志目录

logfile /opt/app/redis6/redis_6379.log




#启动redis

cd /opt/app/redis6/bin

./redis-server redis.conf




##注册服务

vim /lib/systemd/system/redis.service

[Unit]

Description=Redis

After=network.target

 

[Service]

Type=forking

PIDFile=/var/run/redis_6379.pid

ExecStart=/opt/app/redis6/bin/redis-server /opt/app/redis6/bin/redis.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target






systemctl命令:

# 重载服务

systemctl daemon-reload

# 开机自启

systemctl enable redis

# 启动

systemctl start redis

 

# 重启

systemctl restart redis    

 

# 停止

systemctl stop redis

# 查看状态

systemctl status redis

 

# 关闭开机启动

systemctl disable redis


可能遇到问题

已加载插件:fastestmirror, langpacks /var/run/yum.pid 已被锁定,PID 为 10001

该服务是离线更新,两种方法,

  • 永久禁用
  • 强制关闭yum

强制关闭

[root@ZY01 tom]# rm -rf /var/run/yum.pid


[root@ZY01 tom]# yum repolist

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

* base: mirrors.aliyun.com

* extras: mirrors.aliyun.com

* updates: mirrors.aliyun.com

源标识                              源名称                                状态

base/7/x86_64                       CentOS-7 - Base                       10,072

extras/7/x86_64                     CentOS-7 - Extras                        516

updates/7/x86_64                    CentOS-7 - Updates                     4,156

repolist: 14,744


Job for redis.service failed because the control process exited with error c

进度:安装完redis设置完redis.conf和注册服务redis.service,启动时出错

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
11月前
|
JSON NoSQL Redis
|
3月前
|
存储 NoSQL 测试技术
【Redis】redis为什么快
【Redis】redis为什么快
|
2月前
|
消息中间件 缓存 NoSQL
【Redis】 初识 Redis
【Redis】 初识 Redis
|
3月前
|
存储 SQL NoSQL
[Redis]——初识Redis
[Redis]——初识Redis
|
3月前
|
缓存 NoSQL 数据库
Redis的三剑客
Redis的三剑客
|
3月前
|
NoSQL 网络协议 安全
Redis系列-1.Redis浅谈
Redis系列-1.Redis浅谈
35 0
|
10月前
|
NoSQL Redis
06Redis - Redis的使用
06Redis - Redis的使用
48 0
|
10月前
|
存储 NoSQL Linux
Redis之Redis为什么这么快解读
Redis之Redis为什么这么快解读
|
11月前
|
存储 缓存 NoSQL
|
存储 NoSQL Unix
redis
redis
103 0