Redis安装与使用
来自CloudWiki
安装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()
参考: