redis|stringコマンド
2446 ワード
string
stringコマンド詳細
設定
# SET key value
127.0.0.1:6379> SET name kity
OK
# SETNX key value ,
# GET key
127.0.0.1:6379> GET name
"kity"
# GETSET key value key value,
127.0.0.1:6379> GETSET age 12
"10"
127.0.0.1:6379> GET age
"12"
# SETEX key seconds value key-value ( : )
127.0.0.1:6379> SETEX age 20 18
OK
127.0.0.1:6379> GET age
"18"
127.0.0.1:6379> GET a
(nil)
# MSET key value [key value ...]
127.0.0.1:6379> KEYS *
1) "name"
127.0.0.1:6379> MSET age 18 gender 1
OK
127.0.0.1:6379> KEYS *
1) "age"
2) "name"
3) "gender"
# SETRANGE key offset value offset , key string
127.0.0.1:6379> SET name 'hello kitty'
OK
127.0.0.1:6379> SETRANGE name 6 world
(integer) 11
127.0.0.1:6379> GET name
"hello world"
# offset key string , string 0 offset。
127.0.0.1:6379> SETRANGE name 12 two
(integer) 15
127.0.0.1:6379> get name
"hello kitty\x00two"
取得
# STRLEN key
127.0.0.1:6379> STRLEN name
(integer) 7
# GETRANGE key start end key
127.0.0.1:6379> GETRANGE name 6 -1
"kitty one"
# MGET key [key ...]
127.0.0.1:6379> MGET age name gender
1) "18"
2) "kity"
3) "1"
えんざん
# INCR key key value 1
127.0.0.1:6379> GET age
"18"
127.0.0.1:6379> INCR age
(integer) 19
127.0.0.1:6379> INCR age
(integer) 20
#
127.0.0.1:6379> GET name
"kity"
127.0.0.1:6379> INCR name
(error) ERR value is not an integer or out of range
# INCRBY key increment key increment
127.0.0.1:6379> GET age
"20"
127.0.0.1:6379> INCRBY age 10
(integer) 30
# INCBYFLOAT key increment
127.0.0.1:6379> SET num 1
OK
127.0.0.1:6379> INCRBYFLOAT num 2.1
"3.1"
# DECR key key value 1
127.0.0.1:6379> GET gender
"1"
127.0.0.1:6379> DECR gender
(integer) 0
127.0.0.1:6379> DECR gender
(integer) -1
# DECRBY key increment key increment
127.0.0.1:6379> DECRBY age 10
(integer) 20
# APPEND key value
127.0.0.1:6379> APPEND name ' one'
(integer) 7
127.0.0.1:6379> GET name
"kity one"