Skip to content

Instantly share code, notes, and snippets.

@bluetoothfx
Last active May 29, 2023 07:04
Show Gist options
  • Save bluetoothfx/9a9bc13b6975e94505e163fec0bd86cb to your computer and use it in GitHub Desktop.
Save bluetoothfx/9a9bc13b6975e94505e163fec0bd86cb to your computer and use it in GitHub Desktop.
Start a Redis database using Docker
# To get & run redis on docker (6379 is default port)
> docker run -d -p 6379:6379 --name redis1 redis
# Run redis on docker & guaranteed backup (-create /home/redisDB directory 1st in your host machine)
> docker run -v /home/redisDB:/data -d -p 6379:6379 --name redis1 redis redis-server --appendonly yes
# to check if redis is functioning in docker (status checking)
> docker ps
# to view redis logs
> docker logs redis1
# start a new interactive session (-it) inside the running container
> docker exec -it redis1 sh
# run redis cli
> redis-cli
# combining previous 2 command
> docker exec -it redis1 redis-cli
# To set redis container visible outside
> set bind 0.0.0.0
> save
# redis inspection
> docker inspect redis1
-------------------------------------------------------------------------------
SOME REDIS-CLI COMMAND
-------------------------------------------------------------------------------
> ping //check redis cli
# setting a value
> set name mango // set <key> <value>
# getting a value
> get name // get <key>
# get all keys
> KEYS '*'
> --scan --pattern '*'
# get all redis configuration
> CONFIG GET *
# get redis configuration
> CONFIG GET <config_name>
# set redis configuration
> CONFIG SET <config_name>
# exit form cli & shell
> exit
------------------------------------------------------------------------------
LOGIN FROM REDIS-CLI TO REDIS SERVER
------------------------------------------------------------------------------
# To use redis cli without server follow following guideline then use below command
https://redislabs.com/blog/get-redis-cli-without-installing-redis-server/
# actually node index.js opening a redis-cli
https://github.com/lujiajing1126/redis-cli
# redis cli login from user pc
> node index.js -h <ip address/host address>
# redis cli login from user pc with pass
> node index.js -a <your password> -h <ip address/host address>
-------------------------------------------------------------------------------
SOME REDIS Help Line
-------------------------------------------------------------------------------
# Install redis CLI without server (Help for testing)
https://redislabs.com/blog/get-redis-cli-without-installing-redis-server/
# Make Radis container available outside of host machine
https://stackoverflow.com/questions/41371402/connecting-to-redis-running-in-docker-container-from-host-machine
# Redis Persistance
https://redis.io/topics/persistence
# Redis commands
https://redis.io/commands
# Redis basics at a glance
https://auth0.com/blog/introduction-to-redis-install-cli-commands-and-data-types/
# Redis troubleshooting & experience share
https://tech.trivago.com/2017/01/25/learn-redis-the-hard-way-in-production
https://www.slideshare.net/RedisLabs/redisconf18-2000-instances-and-beyond
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment