Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redis Workshop
# Use ZSET (sorted set) to achieve ranking
###################################
$ ZADD item:1 100 user:1 210 user:2
$ ZADD item:1 300 user:3 350 user:4
$ ZINCRBY item:1 100 user:3
# user:3 400, user:4 350, user:2 210, user:1 100
$ ZREVRANGE item:1 0 0
# result: user:3
# get the top bidder by usign ZREVRANGE
# Use LIST to acheive queue
#############################
$ LPUSH pending task1
$ LPUSH pending task2
$ LPUSH pending task3
$ RPOPLPUSH pending completed
# task1 will pop from 'pending' list and push to 'completed' list
# Use SET to achieve recommendation
###################################
$ SADD tag:1 article:1 article:2 article:3
$ SADD tag:2 article:2 article:3
$ SADD tag:3 article:1 article:3
# SMEMBER return the member in the set
$ SMEMBER tag:1
# results: article:1 article:2 article:3
# SINTER return intersection of given keys
$ SINTER tag:1 tag:2 tag:3
# results: article:3
# So basically, use SINTER to find articles also with similar tags
$ GEOADD pharmacies -0.310392 51.456454 "Charles Harry Pharmacy”
$ GEOADD pharmacies -0.296402 51.462069 "Richmond Pharmacy”
$ GEOADD pharmacies -0.318604 51.455338 "St Margerets Pharmacy”
$ GEORADIUS pharmacies -0.30566239999996014 51.452921 600 m
WITHDIST WITHCOORD ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment