Redis 8 cheatsheet

Redis 8: Hashes, lists, sets and sorted sets

9 common Redis 8 tasks.

Set hash fields

Store several fields on one key.

HSET user:1 name Ada age 36

Get all hash fields

Return every field and value.

HGETALL user:1

Add to a list

Push an item onto the head of a list.

LPUSH queue job1

Take from a list

Pop an item from the tail, which gives first-in first-out with LPUSH.

RPOP queue

Read a list

Return every item in the list. 0 -1 means from the first item to the last.

LRANGE queue 0 -1

Add to a set

Add members to a set. Duplicates are ignored.

SADD tags redis cache

List a set's members

Return every member of a set, in no particular order.

SMEMBERS tags

Add to a sorted set

Add a member with a score.

ZADD leaderboard 100 ada

Read the top of a sorted set

Return the 10 highest scores, highest first.

ZRANGE leaderboard 0 9 REV WITHSCORES

Was this page helpful?