标签:
EXISTS mykey
0
APPEND mykey "Hello"
5
APPEND mykey " world"
11
GET mykey
Hello world
SETBIT bit 100861
0
SETBIT bit 100861
1
GETBIT bit 10086
1
GETBIT bit 100
0
BITCOUNT bits
0
SETBIT bits 01
0
BITCOUNT bits
1
SETBIT bits 31
0
BITCOUNT bits
2
SETBIT peter 1011
EXISTS bit
0
GETBIT bit 10086
0
SETBIT bit 41
0
GETBIT bit 4
1
SET num 10
OK
DECR num
9
EXISTS count
0
DECR count
-1
SET count 10
OK
DECRBY count 20
-10
EXISTS pages
0
DECRBY pages 1
-1
DECRBY pages -1
0
DECRBY pages -3
3
GET db
SET DB redis
OK
get DB
redis
DEL db
0
EXISTS db
0
LPUSH db redis mongodb mysql
3
GET db
ERR Operation against a key holding the wrong kind of value
SET greeting "Hello,my friend"
OK
GETRANGE greeting 04
Hello
GETRANGE greeting -1-5
GETRANGE greeting -3-1
end
GETRANGE greeting 0-1
Hello,my friend
GETRANGE greeting 010000000
Hello,my friend
GETSET db mongodb
GET db
mongodb
GETSET db redis
mongodb
INCR mycount
1
INCR mycount
2
INCR mycount
3
GETSET mycount 0
3
SET page_view 20
OK
INCR page_view
21
SET rank 50
OK
INCRBY rank 20
70
GET rank
70
SET book "REDIS"
OK
INCRBY book 1
ERR value is not an integer or out of range
SET mykey 10.50
OK
INCRBYFLOAT mykey 0.1
10.6
SET mykey 314e-2
OK
INCRBYFLOAT mykey 0.5
3.64
SET mykey 4
OK
INCRBYFLOAT mykey 0.5
4.5
SET redis redis.com
OK
SET mongodb mongodb.com
OK
MGET redis mongodb mysql
redis.com
mongodb.com
MSET date "2012-05" time "11:00 am" weather "SUNNY"
OK
MGET date time weather
2012-05
11:00 am
SUNNY
SET google "google.hk"
OK
MSET google "google.com"
OK
GET google
google.com
MSETNX rmdbs "MySql" nosql "MongoDB" key-value-store "Redis"
1
MGET rmdbs nosql
MySql
MongoDB
MSETNX rmdbs "MySql" language "Java"
0
PSETEX mykey 10000"HELLO"
OK
PTTL mykey
7110
GET mykey
HELLO
PTTL mykey
-1
GET mykey
SET key value PX millisecond
效果等同于 PSETEX key millisecond value。
SET key "value"
OK
GET key
value
SET key "new-value"
OK
get key
new-value
SET key "hello" EX 100860
OK
TTL key
100856
TTL key
100852
SET key "moto" PX 123331
OK
TTL key
121
get key
moto
TTL key
107
SET key "value" NX
SET key1 "value" NX
OK
SET key "value" XX
OK
SET key2 "value" XX
SETEX user_id 6010086
OK
TTL user_id
54
get user_id
10086
get user_id
10086
TTL user_id
36
EXISTS job
0
SETNX job "code-farmer"
1
SETNX job "programmer"
0
GET job
code-farmer
redis> SET greeting "hello world"
OK
redis> SETRANGE greeting 6"Redis"
(integer)11
redis> GET greeting
"hello Redis"
# 对空字符串/不存在的 key 进行 SETRANGE
redis> EXISTS empty_string
(integer)0
redis> SETRANGE empty_string 5"Redis!"# 对不存在的 key 使用 SETRANGE
(integer)11
redis> GET empty_string # 空白处被"\x00"填充
"\x00\x00\x00\x00\x00Redis!"
SET mykey "Hello World"
OK
STRLEN mykey
11
STRLEN nonestr
0
------------
以上为Redis中对string类型的基本操作命令。
本文主要参考:http://redisdoc.com/
标签:
原文地址:http://www.cnblogs.com/jingLongJun/p/4526510.html