02.17 redis常用命令


redis常用命令

以windows平臺上的redis為例啟動redis服務時,一般需要帶上配置信息,啟動命令如下redis-server.exe redis.windows.conf

redis自帶了一個命令行客戶端工具(redis-cli), 連接服務的命令如下

redis-cli.exe -h 192.168.58.143 -p 6379 -a p@ssw0rd --raw

或者redis-cli.exe -h 192.168.58.143 -p 6379

然後再輸入auth password

增加了--raw 會稍微美化一下輸出結果.


顯示連接服務端後,就可以進行下面的操作

get key_name (獲取key_name的值)randomkey (隨機獲取一個key)keys * (列出所有key)TTL key_name (獲取key_name到期的剩餘秒數)

client list (獲取所有連接的客戶端)info (顯示服務器的信息)monitor (顯示實時日誌)

config get timeout(查看超時,如果連接沒有使用,就會根據timeout的值關閉連接) -- 對應了配置文件中的timeout值

config set timeout 30 -- (Close the connection after a client is idle for 30 seconds)

註冊成系統服務:redis-server.exe –-service-install redis.windows.conf卸載服務redis-server –-service-uninstall

查看key的過期時間

PTTL KEY_NAME


分享到:


相關文章: