標籤:
http://try.redis.io/
Redis即Key-Value儲存,也稱為NoSQL資料庫,Redis資料庫的關鍵操作為儲存key-value資料,通過key檢索value
1)儲存、檢索、刪除,自增值 SET,GET, DEL,INCR
> SET server:name "fido"OK> GET server:name"fido"> SET connections 10OK> INCR connections(integer) 11> INCR connections(integer) 12> DEL connections(integer) 1> INCR connections(integer) 1
2) key到期 EXPIRE & TTL
#Redis can be told that a key should only exist for a certain length of time. This is accomplished with the EXPIRE and TTL commands. SET resource:lock "Redis Demo" EXPIRE resource:lock 120
#This causes the key resource:lock to be deleted in 120 seconds. You can test how long a key will exist with the TTL command. It returns the number of seconds until it will be deleted. TTL resource:lock => 113 // after 113s TTL resource:lock => -2
#The -2 for the TTL of the key means that the key does not exist (anymore). A -1 for the TTL of the key means that it will never expire. Note that if you SET a key, its TTL will be reset. SET resource:lock "Redis Demo 1" EXPIRE resource:lock 120 TTL resource:lock => 119 SET resource:lock "Redis Demo 2" TTL resource:lock => -1
3) 有序列表 RPUSH, LPUSH, LLEN, LRANGE, LPOP, and RPOP
4) 無序集合 SADD, SREM, SISMEMBER, SMEMBERS and SUNION.
5) 有序集合 ZADD ZRANGE
6) 散列 HSET, HGETALL, HMSET, HGET, HDEL
HINCRBY 可以對散列裡面的某一域(field)執行自增操作
Redis Tutorial - 基本操作