Redis String
SET
http://redisdoc.com/string/set.html
時間複雜度: O(1)
SET key value [EX seconds] [PX milliseconds] [NX|XX]
EX seconds : 將鍵的過期時間設置為 seconds 秒。執行SET key value EX seconds 的效果等同於執行 SETEX key seconds value 。
PX milliseconds : 將鍵的過期時間設置為 milliseconds 毫秒。執行SET key value PX milliseconds 的效果等同於執行 PSETEX key milliseconds value 。
NX : 只在鍵不存在時, 才對鍵進行設置操作。執行 SET key value NX 的效果等同於執行 SETNX key value 。
XX : 只在鍵已經存在時, 才對鍵進行設置操作。
GETSET
http://redisdoc.com/string/getset.html
GETSET key value
MSET key value [key value …]
http://redisdoc.com/string/mset.html
MSET key value [key value …]
GETRANGE
http://redisdoc.com/string/getrange.html
GETRANGE key start end
127.0.0.1:6379> set name samsung
OK
127.0.0.1:6379> getrange name 0 3
"sams"
127.0.0.1:6379> getrange name 0 -1
"samsung"
127.0.0.1:6379> getrange name 0 -3
"samsu"
127.0.0.1:6379> getrange name -3 -1
"ung"
SETEX
http://redisdoc.com/string/setex.html
SETEX key seconds value
PSETEX
http://redisdoc.com/string/psetex.html
PSETEX key milliseconds value
SETRANGE
http://redisdoc.com/string/setrange.html
SETRANGE key offset value
127.0.0.1:6379> SET greeting "hello world"
OK
127.0.0.1:6379> SETRANGE greeting 6 "Redis"
(integer) 11
127.0.0.1:6379> GET greeting
"hello Redis"
STRLEN
http://redisdoc.com/string/strlen.html
STRLEN key
Cheat Sheet
· APPEND mykey "Hello" (appends the value at the end of the string).
· INCR mykey (Increments the number stored at key by one).
· INCRBY mykey 5
· DECR mykey (Decrements the number stored at key by one.)
· DECRBY mykey 3 (Decrements the number stored at key )
· INCRBYFLOAT mykey 0.1(Increment the string representing a floating point number)
· GETSET mycounter "0" (Atomically sets key to value and returns the old value stored at key)
· MSET key1 "Hello" key2 "World" (Sets the given keys to their respective values.)
· MGET key1 key2 (Returns the values of all specified keys).
· SETNX mykey "Hello" (Set key to hold string value if key does not exist.)
· MSETNX key1 "Hello" key2 "there" (Sets the given keys to their respective values.)
· GETRANGE mykey 0 3 (Returns the substring of the string value stored at key).
· GETRANGE mykey -3 -1. (-1 means the last character and so on).
· SETEX mykey 10 "Hello" (Set key to hold the string value and set key to timeout after a given number of seconds.)
· PSETEX mykey 1000 "Hello" ( expire time is specified in milliseconds instead of seconds.)
· SETRANGE key1 6 "Redis" (Overwrites part of the string stored at key) .
· STRLEN mykey ( Returns the length of the string ).