参考资料: redis命令参考: 安装:sudo apt-get install redis-server 安装完成后,Redis服务器会自动启动,我们检查Redis服务器程序 检查服务器进程:ps -aux|grep redis 检查Redis服务器状态:netstat -nlt|grep 6379 通过启动命令检查Redis服务器状态:sudo /etc/init.d/redis-server status 安装Redis服务器,会自动地一起安装Redis命令行客户端程序
重启Redis服务器:sudo /etc/init.d/redis-server restart
配置文件:/etc/redis/redis.conf
先关闭再重启
[root@localhost src]# redis-cli #开始客户端连接127.0.0.1:6379> auth 123456 #auth 密码登录OK127.0.0.1:6379> shutdown save #shutdown 关闭服务 savenot connected> exit # not connected 表示连接已经失去, exit 退出[root@localhost src]# [root@loca [root@localhost src]# ps -ef | grep redis- # ps 查找进程 redis-server 真的关闭了root 2782 2508 0 05:57 pts/0 00:00:00 grep --color=auto redis-[root@localhost src]# redis-server ../redis.conf #重启--------------------- 作者:1990_super 来源:CSDN 原文:https://blog.csdn.net/runbat/article/details/79248527 版权声明:本文为博主原创文章,转载请附上博文链接!
from redis import StrictRedis# 使用默认方式连接到数据库redis = StrictRedis(host='localhost', port=6379, db=0)# 使用url方式连接到数据库redis = StrictRedis.from_url('redis://@localhost:6379/1')
from redis import StrictRedis,ConnectionPool# 使用默认方式连接到数据库pool = ConnectionPool(host='localhost', port=6379, db=0)redis = StrictRedis(connection_pool=pool)# 使用url方式连接到数据库pool = ConnectionPool.from_url('redis://@localhost:6379/1')redis = StrictRedis(connection_pool=pool)
redis://[:password]@host:port/db # TCP连接rediss://[:password]@host:port/db # Redis TCP+SSL 连接unix://[:password]@/path/to/socket.sock?db=db # Redis Unix Socket 连接
redis-load -h # 获取帮助信息< redis_data.json redis-load -u redis://@localhost:6379 # 将json数据导入数据库中
redis-dump -h # 获取帮助信息redis-dump -u redis://@localhost:6379 -d 1 > ./redis.data.jl # 导出到json文件redis-dump -u redis://@localhost:6379 -f adsl:* > ./redis.data.jl # 导出adsl开头的数据
=======================
打印出所有[与pattern相匹配的]活跃频道:PUBSUB CHANNELS [pattern] 活跃频道指的是那些至少有一个订阅者的频道
订阅频道的订阅者数量:PUBSUB NUMSUB channel1 channel2返回客户端订阅的所有模式的数量总和:PUBSUB NUMPAT# client-1 订阅 news.* 和 discount.* 两个模式client-1> PSUBSCRIBE news.* discount.*Reading messages... (press Ctrl-C to quit)1) "psubscribe"2) "news.*"3) (integer) 11) "psubscribe"2) "discount.*"3) (integer) 2# client-2 订阅 tweet.* 一个模式client-2> PSUBSCRIBE tweet.*Reading messages... (press Ctrl-C to quit)1) "psubscribe"2) "tweet.*"3) (integer) 1# client-3 返回当前订阅模式的数量为 3client-3> PUBSUB NUMPAT(integer) 3# 注意,当有多个客户端订阅相同的模式时,相同的订阅也被计算在 PUBSUB NUMPAT 之内# 比如说,再新建一个客户端 client-4 ,让它也订阅 news.* 频道client-4> PSUBSCRIBE news.*Reading messages... (press Ctrl-C to quit)1) "psubscribe"2) "news.*"3) (integer) 1# 这时再计算被订阅模式的数量,就会得到数量为 4client-3> PUBSUB NUMPAT(integer) 4