Skip to content

Instantly share code, notes, and snippets.

@MediaByte
Forked from LeCoupa/redis_cheatsheet.bash
Created March 3, 2019 01:42
Show Gist options
  • Save MediaByte/62a0149cc6273f6a7b11e7208b3318f0 to your computer and use it in GitHub Desktop.
Save MediaByte/62a0149cc6273f6a7b11e7208b3318f0 to your computer and use it in GitHub Desktop.
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# Redis Cheatsheet
# All the commands you need to know
# Basics.
SET key value # set value in key
SETNX key value # set if not exist value in key
GET key # get value in key
INCR key # increment value in key
DEL key # delete key
EXPIRE key 120 # key will be deleted in 120 seconds
TTL key # returns the number of seconds until a key is deleted
# Lists.
# A list is a series of ordered values.
RPUSH list value # puts the new value at the end of the list
LPUSH list value # puts the new value at the start of the list
LRANGE list 0 1 # gives a subset of the list
LLEN list # returns the current length of the list
LPOP list # removes the first element from the list and returns it
RPOP list # removes the last element from the list and returns it
# Sets.
# A set is similar to a list, except it does not have a specific order and each element may only appear once.
SADD myset value # adds the given value to the set
SREM myset value # removes the given value from the set
SISMEMBER myset value # tests if the given value is in the set.
SMEMBERS myset # returns a list of all the members of this set
SUNION myset otherset # combines two or more sets and returns the list of all elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment