- What is Redis.
- Use Case
- Installation
- Backup
- Monitor
- Redis Sentinel
- Redis Auth
- Steps to run the application
- OpenAPI
- API Endpoint to access the app
- TO DO
- Redis is a powerful and extremely fast in memory db.
- Stores data in key-value.
- Persistence.
- Optionally you can save the data to disk.
- Master slave replication.
- Highly Available.
- Open source.
- Indexing (Still can create own indexing).
- No query language.
- User Session Management
- Caching.
- Pub/Sub (Queues & Notification)
- Leaderboards for gaming apps
- Geospatial
- Download and installed. (Please use Redis Download to see the steps to configure the redis in other OS)
- Using package manager like brew (mac). (I will be using this to configure redis)
-
Open the terminal and type
$ brew install redis
-
Once it done, type redis-server to start the redis server with default configuration provided by redis.
$ redis-server {path to the redis.conf}
-
Open another terminal and type redis-cli, to open the redis cli.
$ redis-cli -p 6379
You will see the output something like below:
$ redis-cli -p 6379 127.0.0.1:6379>
Checking redis status execute below
$ redis-cli ping PONG
killing redis server execute below
127.0.0.1:6379> shutdown
-
Some sample commands on redis-cli
127.0.0.1:6379> set color red #setting a value in color (as key) and red (as value) OK 127.0.0.1:6379> keys * # verifying total number of keys 1) "\xac\xed\x00\x05t\x00\x04Book" 2) "color" 127.0.0.1:6379> 127.0.0.1:6379> 127.0.0.1:6379> get color # getting the value assigned to the key - color "red" 127.0.0.1:6379>
Below command will create the dump/backup as per the path specified in redis.conf file.
$ save
Run the below command from terminal and you'll be abe to see everything happening on redis
$ redis-cli -p 6379
127.0.0.1:6379> Monitor
OK
- It is a system, designed to help managing Redis instances.
- It is there to provide HA by monitoring, notifying, and providing instances failover.
- It check whether master and slave are working properly or not.
- If Master goes down, it's the sentinel responsibility to make one of the slave to master.
- Redis auth help to secure database. We can do that either via redis.conf or via cli.
- Cli
$ config set requirepass ${auth-key} $ auth ${auth-key}
Extra links:
- Use RedisLabs to setup redis on cloud free.
- Redis GUI - Redis Desktop.
- Follow these steps to configure and run Redis locally.
- Execute below command to run the boot app from apps directory
$./gradlew bootRun
- Alternatively, first build the jar and then run java -jar command as below
$./gradlew build
$ java -jar {name of the generated jar}
- Execute the below command from redis directory
$ docker network create rmoff_services
$ docker build -t redis-server .
$ docker run -d -p 6379:6379 --network=rmoff_services \
--name redis \
-h redis redis-server
- Build an image of the app. Execute below command from apps directory.
$ docker build -t backend-service .
- Verify the image
$ docker image ls -a
- Run the app
$ docker run -d --name app -e "REDIS_HOST=redis" \
-p 8080:8080 --network=rmoff_services \
backend-service
$ docker-compose -f docker-compose-stack.yaml up -d
- Execute below command to deploy the application in k8s and expose the same via service using nodeport.
$ kubectl apply -f k8s-deployment.yaml
- http://localhost:8080/api/health
- http://localhost:8080/api/book/save
- http://localhost:8080/api/book/all
- http://localhost:8080/api/book/delete/{id}
- Add steps to run both container in K8s.