14. Сбор статистики
{post_id=42}
INCR posts:42
GET posts:42 # How many views/votes?
ZINCRBY posts 1 42
ZSCORE posts 42 # How many views/votes?
ZREVRANGE posts O 9 # TOP-10 posts
ZREVRANGE posts O 9 WITHSCORES # TOP-10 with
views/votes quantity
16. Связь между демонами
# Websocket server:
SUBSCRIBE messages
# Async jobs server:
SUBSCRIBE jobs
# Web-application:
PUBLISH jobs “videos:12:mpeg:ogg”
PUBLISH messages “Video encoding #12 started”
# Async jobs server:
PUBLISH messages “Video encoding #12 finished”
17. Построение простых
графов
# User 1 adds user 5 to friends
SADD users:1:friends 5
SADD users:5:friend_of 1
...
# Get user 5 friends
SMEMBERS users:5:friends
# Get user 5 mutual friends
SCARD users:5:friends users:5:friend_of
# Get common friens of user 5 and 7
SCARD users:5:friends users:7:friends
# Are user 7 friend of user 5?
SISMEMBER users:5:friends 7