This application contains spring boot, mongodb, redis cache.
Method URL
Description
GET
/api/v1/users
Get all users
GET
/api/v1/users/{id}
Get user by ID
POST
/api/v1/users/add
Add a new user
PUT
/api/v1/users/{id}
Update an existing user
DELETE
/api/v1/users/{id}
Delete user by ID
DELETE
/api/v1/users/all
Delete all users
POST
/api/v1/users/saveOrUpdate
Save or update a user
GET
/v1/universities/{country}
Get all universities by country
{
"id": "673776f73928c359d9492aec",
"firstName": "Laksh",
"lastName": "Kawali",
"age": 3,
"gender": "Male",
"role": "Admin"
}
Enable WSL (if not already enabled): Open PowerShell as Administrator and run the following command:
wsl --install
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis
sudo service redis-server start
redis-cli
You will see the Redis CLI: 127.0.0.1:6379>
127.0.0.1:6379>ping
You will get the following response: PONG
Sets a key with a value
SET name "Rajesh"
Description: This sets the keyname
with the valueRajesh
.
Retrieves the value of a key
GET name
Description: This retrieves the value of the keyname
, which will returnRajesh
.
Deletes a key
DEL name
Description: This deletes the keyname
from Redis.
Checks if a key exists
EXISTS name
Description: This checks if the keyname
exists. It will return1
if the key exists and0
if it doesn't.
Sets a key with an expiration time (in seconds)
SETEX session 300 "Rajesh"
Description: This sets the keysession
with the valueRajesh
that expires in 300 seconds.
Retrieves the TTL (time to live) of a key
TTL session
Description: This retrieves the TTL of the keysession
, which will return the number of seconds until it expires.
Adds an element to the head of a list
LPUSH friends "Rajesh"
Description: This adds the valueRajesh
to the head of the listfriends
.
Retrieves a range of elements from a list
LRANGE friends 0 -1
Description: This retrieves all elements from the listfriends
, includingRajesh
.
Sets a field in a hash
HSET user:1000 name "Rajesh"
Description: This sets the fieldname
in the hashuser:1000
toRajesh
.
Retrieves the value of a field in a hash
HGET user:1000 name
Description: This retrieves the value of thename
field from the hashuser:1000
, which will returnRajesh
.
Retrieves all fields and values of a hash
HGETALL user:1000
Description: This retrieves all fields and values of the hashuser:1000
, includingname: Rajesh
.
Retrieves all keys in the current database
KEYS *
Description: This retrieves all keys in the current database. It may return keys likename
,session
,friends
, etc.
Deletes all keys in all databases (use with caution)
FLUSHALL
Description: This deletes all keys in all Redis databases, including thename
,session
, andfriends
keys.