redis五大基本型別---String
阿新 • • 發佈:2020-12-04
String(字串)
指定配置檔案啟動redis,並連線,預設6379埠,看如何連線
[root@5444 src]# ./redis-server redis2.conf
[root@5444 src]# redis-cli -p 6380
127.0.0.1:6380> ping
PONG
記錄命令,先看
set
get
mset
mget
incr
decr
incrby
decrby
setex
setnx
msetnx
keys *
append
strlen
ttl
getrange
使用:
127.0.0.1:6379> keys * //獲取所有鍵值對
1) " name"
2) "k3"
3) "k2"
4) "views"
5) "k1"
127.0.0.1:6380> FLUSHALL
OK
127.0.0.1:6380> keys *
127.0.0.1:6380> set k1 v1 //設定鍵值對
OK
127.0.0.1:6380> get k1 //獲取鍵值對
"v1"
127.0.0.1:6380> mset k2 v2 k3 v3 //批量設定鍵值對
OK
127.0.0.1:6380> mget k1 k2 //批量獲取鍵值對
1) "v1"
2) "v2"
127.0.0.1:6380> set views 0
OK
127.0.0.1 :6380> incr views //使views自增 +1
(integer) 1
127.0.0.1:6380> incr views
(integer) 2
127.0.0.1:6380> incrby views 1000 //使views自增 +1000
(integer) 1002
127.0.0.1:6380> decrby views 999 //使views自增 -999
(integer) 3
127.0.0.1:6380> exists k1 //判斷鍵是否存在
(integer) 1
127.0.0.1:6380> append key1 "hello redis" //追加字串,如果當前key不存在,就相當於setkey
(integer) 11
127.0.0.1:6380> get key1
"hello redis"
127.0.0.1:6380> strlen key1 //計算值的長度
(integer) 11
127.0.0.1:6380> getrange key1 0 3 //迴圈輸出
"hell"
127.0.0.1:6380> get key2
"\x00MM"