Skip to content

Instantly share code, notes, and snippets.

@prahaladbelavadi
Created August 1, 2018 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prahaladbelavadi/f6f677e7fbc9e7215772fee4b9d62713 to your computer and use it in GitHub Desktop.
Save prahaladbelavadi/f6f677e7fbc9e7215772fee4b9d62713 to your computer and use it in GitHub Desktop.
Redis commands
  • GET parameter
  • SET xyz: "something"
  • INCR xyz increments integer by one atomically
  • del xyz deletes a collection
  • EXPIRE resource:lock 120 time specified for it to expire in seconds
  • TTL resource:Lock checks for time remaining for a key to exist The -2 for the TTL of the key means that the key does not exist (anymore). A -1 for the TTL of the key means that it will never expire. Note that if you SET a key, its TTL will be reset.
  • Rpush parameter places the object at the end of the list;
  • Lpush places the object at the beginning of the list; LRANGE gives a subset of the list. It takes the index of the first element you want to retrieve as its first parameter and the index of the last element you want to retrieve as its second parameter. A value of -1 for the second parameter means to retrieve elements until the end of the list.
  • LLEN returns the length of the list
  • LPOP returs the list with the first element removed
  • RPOP returns the list with the last element removed
  • SADD: adds value to a set
  • SREM: removes value from a set
  • SISMEMBER: checks if value is a member of a set
  • SMEMBERS: returns members of the set
  • SUNION: combines sets and returns all their elements
  • HSET user:1000 name "John Smith"
  • HSET user:1000 email "john.smith@example.com"
  • HSET user:1000 password "s3cret"
  • HMSET user:1001 name "Mary Jones" password "hidden" email "mjones@example.com"
  • HGETALL user:1000

HSET user:1000 visits 10 HINCRBY user:1000 visits 1 => 11 HINCRBY user:1000 visits 10 => 21 HDEL user:1000 visits HINCRBY user:1000 visits 1 => 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment