redis-cli

Here are some basic redis command.
From redis.

  • SET GET

Redis is what is called a key-value store, often referred to as a NoSQL database. The essence of a key-value store is the ability to store some data, called a value, inside a key. This data can later be retrieved only if we know the exact key used to store it. We can use the command SET to store the value “fido” at key “server:name”:

SET server:name "fido" Redis will store our data permanently, so we can later ask "What is the value stored at key server:name?" and Redis will reply with "fido":

GET server:name => "fido"

Redis also supports several more complex data structures. The first one we’ll look at is a list. A list is a series of ordered values. Some of the important commands for interacting with lists are RPUSH, LPUSH, LLEN, LRANGE, LPOP, and RPOP. You can immediately begin working with a key as a list, as long as it doesn’t already exist as a different type.

  • LIST

RPUSH puts the new value at the end of the list.

RPUSH friends "Alice"
RPUSH friends "Bob"

LPUSH puts the new value at the start of the list.

LPUSH friends "Sam" 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.

LRANGE friends 0 -1 => 1) "Sam", 2) "Alice", 3) "Bob"
LRANGE friends 0 1 => 1) "Sam", 2) "Alice"
LRANGE friends 1 2 => 1) "Alice", 2) "Bob"
redis-cli
//login a redis-server
>auth PASSWORD 

//Get the length of a list
>LLEN listName
5
//Get keys in a Hash
>HKEYS hashName
 1) "127.0.0.1/test/hello"
 2) "127.0.0.1/test/nice"
 
//Get value of hashKey in hashName
>HGET hashName "127.0.0.1/test/hello"
"{\"fullName\":\"ABC\",\"tags\":[\"7\"]}"

//show the size of a database 
>dbsize
10942