Tiny memo for my personal use of Redis. Be careful it's optimized only for me so the format probably doesn't make sense to you.
Redis provides 2 types of persistence setting: RDB and AOF.
- Redis Database File. Stored and compressed once in a while; it can loose some data after persistence and before unexpected shutdown.
- Append Only File. A file includes all info of appending operation. A file size and startup time will be big; it almost never loose data.
Use in Docker
- Data file will be:
/datain a container
- Config file
- We have to specify when to boot
docker run -it --name redis \ -p 6379:6379 \ -v "$PWD"/data:/data \ -v "$PWD"/redis.conf:/usr/local/etc/redis/redis.conf \ redis redis-server /usr/local/etc/redis/redis.conf
- LPUSH ... Insert value from left side
- RPUSH .. Insert from right side
- LLEN ... Get length
- LRANGE key_of_list from_index to_index # Specify -1 as to_index to get to the end
- SCARD ... Get length
- SMEMBERS key ... Get all
- ZADD key_of_sorted_set score value ... The score will be a key of being sorted
- ZRANK key value ... Returns an index (ranking order)
- HSET user:pig name "pig"
- HSET user:pig email "firstname.lastname@example.org" ... Now the "user:pig" contains a hash
- HGET user:pig name
- HGETALL user:pig