Skip to content

Instantly share code, notes, and snippets.

@ntulip
Created April 25, 2012 02:04
Show Gist options
  • Save ntulip/2485517 to your computer and use it in GitHub Desktop.
Save ntulip/2485517 to your computer and use it in GitHub Desktop.
redis_sets.sh
# How beautiful and simple it is to store relationships in redis
# Think - I have 4 friends, you have 4 friends, but how many friends
# do we have in common? And did I tell you it handles sorted sets?
# Sorted sets are like sets but with a score. The score provides sorting
# and ranking capabilities
redis 127.0.0.1:6379> sadd friends:leto ghanima paul chani jessica
(integer) 4
redis 127.0.0.1:6379> sadd friends:duncan paul jessica alia
(integer) 3
redis 127.0.0.1:6379> sismember friends:leto jessica
(integer) 1
redis 127.0.0.1:6379> sismember friends:leto vladimir
(integer) 0
redis 127.0.0.1:6379> sinter friends:leto friends:duncan
1) "jessica"
2) "paul"
redis 127.0.0.1:6379>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment