Skip to content

redis

Redis

  • Ops

Redis

compare to memcached

  • support persistant volume
    • RDB
    • AOF
  • support multiple data types
  • pub/sub

commands

  • redis-cli: command line interface
  • redis-sentinel: cluster managing tool
  • redis-server: run server
  • redis-benchmark: stress testing
  • redis-check-aof: check AOF
  • redis-check-dump: check RDB

configuration

Use redis.conf. Docker official redis image not contain this file. Mount it yourself or through redis-server arguments.

types

  • String: get, set, mget, mset
  • Integer: incr, decr, setbit
  • List: lpush, lrange, lpop
  • Hash Map: hset, hget, hmset, hmget
  • Set: sadd, smember, sdiff, sinter, sunion

use docker

Before start

To connect a container, you need to know the name and the port, in the associated networks to be able to discover the service.

There is no DNS resolution in docker deault bridge network. In default network, you need to specify --link to connect the containers. The --link is a legacy feature.

Therefore, create a user-defined network is recommanded, it provide automatic DNS resolution.

Create a bridge newrok

Run a redis instance in user-defined network

Run a redis-cli connect to the redis instance

Transaction

all commands are executed as a single isolated operation, serialized and executed sequentially
atomic: all failed or all succeed

  • MULTI: open a transaction and always return OK
  • EXEC: execute commands in transaction
  • DISCARD: flush commands and exit transaction
  • WATCH: check and set, if watched key changes, not execute

Errors

  • before EXEC: e.g. syntax error
  • after EXEC: e.g. value error

The pipeline discarding the transaction automatically if there was an error during the command queueing

… To be continued