逍遥游

redis入门(3)---事务、生存时间、排序、消息通知

transaction

  • MULTI … EXEC (Notice: 2 methods to handle exceptions) (1. wrong command: return wrong directly after exec) (2. wrong syntax: execute each command)
  • WATCH key [key…] (watch key(s), if these keys has been modified before transaction, abort this transaction. watch will be canceled after EXEC) (Notice: if a key is removed because of EXPIRE, watch wouldn’t regard it changed)

expires

  • EXPIRE key time (remove this key after time second(s))
  • TTL key (see how long will key be alive)
  • PERSIST key (cancel EXPIRE, GET or GETSET can also do this)

sort (result is list, n+m*log(m))

  • SORT key [ALPHA] [DESC] [LIMIT offset count] (sort set, sorted set, list by asc, if ALPHA is set, sort by directory in asc order)
  • SORT key1 BY key2:*->field (sort key by fields in key2)
  • SORT key1 BY key2:*->field GET key2:*->field [GET key3:*->field …] (sort and get field)
  • SORT key1 BY key2:*->field GET # (sort and get * itself)
  • SORT key STORE key2 (sort and store to key2)

message queue

  • BRPOP key timeout (block and RPOP, timeout is timeout, 0 for nil)
  • BRPOP queue1 [queue …] (RPOP from queue1 to nil, and then RPOP queue2, …)

pub/sub

  • PUBLISH channel message
  • SUBCRIBE channel [channel…]
  • PSUBCRIBE pattern (SUBCRIBE channel1.*) (Notice: as patterns can be various for one channel, a channel can be subscribed more than once)
  • UNSUBSCRIBE [channel …] (default is all)
  • PUNSUBSCRBE pattern1 [pattern2…] (can only cancel PSUBCRIBE pattern1) (Notice: SUBSCRIBE and PSUBCRIBE is handled differently, thus the subscribed channels has no relationship)

多说停止服务,disqus引导注册太过分,暂时不上评论系统了。有机会自己造轮子吧。邮箱:input@newnius.com