Redis - SeanHolden/Wiki GitHub Wiki

#Redis

Server

Start:

$ sudo redis-server /etc/redis/redis.conf

Stop:

$ sudo /etc/init.d/redis-server stop

Basic SET and GET

$ SET username "sean"

$ GET username => "sean"

View all keys

KEYS *

HASH

$ HMSET user:1000 username antirez password P1pp0 age 34

$ HSET user:1000 hair brown

$ HGETALL user:1000 =>

1) "username"
2) "antirez"
3) "password"
4) "thisIsMyPassword"
5) "age"
6) "34"
7) "hair"
8) "brown"

$ HGET user:1000 username => "antirez"

LIST

Pretty much an array

$ RPUSH friends "Tom"

$ RPUSH friends "Bob"

$ LPUSH friends "Sam"

$ LRANGE friends 0 -1 => ["Sam","Tom","Bob"]

SET

A set is similar to a list, except it does not have a specific order and each element may only appear once

$ SADD superpowers "flight"

$ SADD superpowers "x-ray vision"

$ SADD superpowers "reflexes"

$ SISMEMBER superpowers "flight" => true

$ SMEMBERS superpowers => ["reflexes","flight","x-ray vision"]