Skip to content

naren-jha/Redis-Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis-Demo

Courses and docs

Youtube videos

Redis runbook

https://redis.io/docs/getting-started/installation/install-redis-on-mac-os/

  • brew install redis

  • redis-server : to start redis in master slave mode

  • brew services start redis : same as above

  • brew services stop redis

  • brew services info redis : check status

Redis Cli

Once Redis is up and running, you can test things by running redis command line interface (CLI):

  • redis-cli
  • keys *
  • set mykey somevalue
  • get mykey
  • flushdb
  • info stats
  • info memory

Doc:

Jedis vs Lettuce

  • https://redis.com/blog/jedis-vs-lettuce-an-exploration/

  • Lettuce

    • Thread safe
    • supports cluster
    • capable of synchronous, asynchronous, and reactive interaction with the cluster
    • relatively difficult to use
  • Jedis

    • Not thread safe; Need to create connection pool
    • supports cluster
    • capable of only synchronous interaction
    • relatively easy to use

Clustering

Creating and running a redis cluster

port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
  • then copy the file to all other folders (7001 .. 7005) and change the port accordingly

  • image

  • copy /usr/local/Cellar/redis/6.2.6/bin/redis-server and paste it in cluster-test folder that we created in the first step

  • open 7 tabs in a separate command window

  • in 6 tabs go to folders (7000 .. 7005) and run ../redis-server ./redis.conf

  • image

  • in the 7th tab run redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1

  • type yes to confirm

  • your redis cluster should be up and running and it should look something like below -

  • image

  • Now run redis CLI redis-cli -c -p 7001 for different ports and then execute commands as usual

Testing

Curl

Add A User:

curl --location --request POST 'localhost:8081/user/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": 1,
    "firstName": "tall",
    "lastName": "guy",
    "email": "tall.guy@gmail.com",
    "age": 35
}'

image

Verify:

image

About

Redis demo application using Spring Data redis client (jedis)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages