ubuntu redis 安裝 &基本命令

參考資料:http://www.javashuo.com/article/p-tnxntxko-kb.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 restarthtml

配置文件:/etc/redis/redis.confredis

先關閉再重啓
[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 NUMPATjson

# 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
相關文章
相關標籤/搜索