redis常用命令

2021-10-17 14:45:38 字數 2767 閱讀 2446

1、相關命令

1、啟動redis-server.exe redis.windows.conf

2、進入redis客戶端 redis-cli

3、清楚所有快取:flushall

select 1  //切換庫

dbsize //檢視資料庫內容多少

flushall //清空所有

flushdb//清空資料庫

exists name //判斷當前key是否存在

key * //檢視所有主鍵

move name 1 //移動name到1資料庫

expire name 10 //設定過期時間

ttl name //檢視name 有效時間

type name //檢視當前key型別

strlen name //檢視name 長度

set age 1

incr age //增加1

incrby age 5 //增加5

2、字串操作

192.168.0.101:6379> set key2 hello,shizhk

ok192.168.0.101:6379> get key2

"hello,shizhk"

192.168.0.101:6379> getrange key2 2 5

192.168.0.101:6379> set key3 abcdefg

ok192.168.0.101:6379> setrange key3 1 xx

(integer) 7

192.168.0.101:6379> get key3

"axxdefg"

192.168.0.101:6379> setex key3 30 hello

ok192.168.0.101:6379> ttl key3

(integer) 24

192.168.0.101:6379> setnx key3 abc

(integer) 1

192.168.0.101:6379> mset k1 v1 k2 v2 k3 v3

ok192.168.0.101:6379> getset db redis

(nil)

192.168.0.101:6379> getset db mongodb

"redis"

3、geo操作

192.168.0.101:6379> flushdb

ok192.168.0.101:6379> geoadd china:city 116.40 39.90 beijin

(integer) 1

192.168.0.101:6379> geoadd china:city 121.47 31.23 shanghai

(integer) 1

192.168.0.101:6379> geoadd china:city 106.50 29.53 chongqing

(integer) 1

192.168.0.101:6379> geoadd china:city 114.05 22.52 shenzhen

(integer) 1

192.168.0.101:6379> geoadd china:city 120.16 30.24 hangzhou

(integer) 1

192.168.0.101:6379> geoadd china:city 108.96 34.26 xian

192.168.0.101:6379> geodist china:city beijin shanghai

"1067378.7564"

192.168.0.101:6379> geodist china:city beijin shanghai km

"1067.3788"

192.168.0.101:6379> geodist china:city beijin chongqing km

"1464.0708"

192.168.0.101:6379> georadius china:city 110 30 1000 km

1) "chongqing"

2) "xian"

3) "shenzhen"

4) "hangzhou"

192.168.0.101:6379> georadius china:city 110 30 100 km

(empty array)

192.168.0.101:6379> georadius china:city 110 30 400 km

1) "chongqing"

192.168.0.101:6379> georadius china:city 110 30 400 km withcoord

1) 1) "chongqing"

2) 1) "106.49999767541885376"

2) "29.52999957900659211"

192.168.0.101:6379> geopos china:city chongqing

1) 1) "106.49999767541885376"

2) "29.52999957900659211"

192.168.0.101:6379>

192.168.0.101:6379> georadiusbymember china:city chongqing 1000 km

1) "chongqing"

2) "xian"

Redis常用命令

1 keys 返回滿足給定pattern的所有key。例如 keys 返回所有鍵 2 exists 確認乙個key是否存在。例如 exists age 3 del 刪除指定key。例如 del age 4 expire 設定乙個key的過期時間。例如 expire age 100 單位 秒 5 pe...

redis常用命令

redis cli p 6079 登陸redis,埠為6079 auth psssword 如果redis帶密碼,則執行上邊一行,password替換為你的密碼。src redis cli p 6380 keys wei xargs src redis cli p 6380 del 批量刪除埠為63...

Redis常用命令

啟動 redis 服務 src redis server或者src redis server redis.conf src redis server redis.conf 1 log.log 2 errlog.log 1為標準輸出,2為錯誤輸出 將 redis 作為 linux 服務隨機啟動 vi ...