码迷,mamicode.com
首页 > 其他好文 > 详细

Redis Tutorial - 基本操作

时间:2015-07-04 12:34:17      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

http://try.redis.io/

Redis即Key-Value存储,也称为NoSQL数据库,Redis数据库的关键操作为存储key-value数据,通过key检索value

1)存储、检索、删除,自增值 SET,GET, DEL,INCR

OK
(integer) 11
(integer) 12
(integer) 1
(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) 有序列表 RPUSHLPUSHLLENLRANGELPOP, and RPOP

 4) 无序集合 SADDSREMSISMEMBERSMEMBERS and SUNION.

 5) 有序集合 ZADD ZRANGE

 6) 散列 HSET, HGETALL, HMSET, HGET, HDEL

  HINCRBY 可以对散列里面的某一域(field)执行自增操作 

Redis Tutorial - 基本操作

标签:

原文地址:http://www.cnblogs.com/joshuajiang/p/4615315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!