參考資料:https://www.cnblogs.com/zongfa/p/7808807.html
redis命令參考:http://doc.redisfans.com/
安裝: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<span class="space" style="display:inline-block;text-indent:2em;line-height:inherit;"> </span>#auth 密碼登錄 OK 127.0.0.1:6379> shutdown save #shutdown 關閉服務 save not 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) 1 1) "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 返回當前訂閱模式的數量為 3 client-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 # 這時再計算被訂閱模式的數量,就會得到數量為 4 client-3> PUBSUB NUMPAT (integer) 4