标签:
Redis即Key-Value存储,也称为NoSQL数据库,Redis数据库的关键操作为存储key-value数据,通过key检索value
1)存储、检索、删除,自增值 SET,GET, DEL,INCR
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)执行自增操作
标签:
原文地址:http://www.cnblogs.com/joshuajiang/p/4615315.html