Redis安装与使用

来自CloudWiki
Cloud17讨论 | 贡献2022年8月17日 (三) 09:01的版本 (创建页面,内容为“==安装Redis== *Centos 8 配置yum源 yum install redis -y ==Redis启动== [root@ecs-c031 receive-mail]# redis-server /etc/redis.conf & [1] 519787 [root@ec…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

安装Redis

yum install redis -y

Redis启动

[root@ecs-c031 receive-mail]# redis-server /etc/redis.conf &

[1] 519787

[root@ecs-c031 receive-mail]# ps -ef | grep redis

root      519787  517298  0 07:05 pts/0    00:00:00 redis-server 127.0.0.1:6379
root      519794  517298  0 07:05 pts/0    00:00:00 grep --color=auto redis

https://blog.csdn.net/u010520724/article/details/109670156

python配置redis模块

[root@localhost op]# pip3 install redis

Redis常用操作

以python为例:

[root@localhost op]# python3

Python 3.7.5 (default, May  8 2020, 10:08:52)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> r = redis.Redis(host='localhost',port=6379,db=0)  #连接redis
>>> r.set('foo','bar') #添加键值对
True
>>> r.get('foo')#查询键值对
b'bar'
>>> r.keys() #获得所有的键
[b'foo']
>>> r.exists('foo') #判断某键是否存在
1
>>> exit()

参考:

https://www.cnblogs.com/yrdy/p/16529806.html 1