This project enables all the Redis Operations as Rest calls via Spring Boot
docker run --name redis-server -p 6379:6379 -d redis
docker pull gtskaushik/spring-rest-redis
docker run --name spring-rest-redis -v <path to application.properties>:/application.properties --network host gtskaushik/spring-rest-redis
URL | Description | Example |
---|---|---|
/get/<rediskey> | This is used to get value of the key, 'name' | /get/name |
/set/<rediskey>/<redisvalue> | This is used to set the value, 'kaushik' for the key, 'name' | /set/name/kaushik |
/has/<rediskey> | This is used to check if the given key is present in Redis | /has/name |
/keys | This is used to get all the keys in Redis | /keys |
/keys/<pattern> | This is used to get all the keys in Redis with the given pattern | /keys/na* |
/delete/<rediskey> | This is used to get all the keys in Redis with the given pattern | /delete/name |
/reactiveget/<rediskey>/<durationinsec> | This gives a SSE as response for every given duration | */reactiveget/name/2 |
/monitor | This is a sample page which notifies on a key change in Redis and updates it in a table | */monitor |
Note:- CONFIG SET notify-keyspace-events KEA
Run the above command in Redis before starting the jar. This will be added as default in future versions.
In this project websockets are craeted using SockJs and Stomp which are pretty much the standard
SockJs - https://cdnjs.com/libraries/sockjs-client
Stomp - https://cdnjs.com/libraries/stomp.js/
// Note:- Cross Origin is enabled by default
// The url mentioned below is the websocket server
var socket = new SockJS('http://localhost:8080/reactive-redis-websocket');
var stompClient = Stomp.over(socket);
// Note:- Subscription must be called first before init so that the client side of the
// socket does not miss the initial value for the subscribed key
stompClient.subscribe('/keySubscription/'+ <rediskey>, function (data) {
console.log(data.body)
});
stompClient.send("/sendToServer/initSubscription/" + <rediskey>, {}, JSON.stringify({}));
//Note:- For subscription and initialization, do not prefix the url with domain url
- Java 8 or above
- Gradle 4.8.1 or above
- npm
- angular cli (Installed globally)
gradle bootJar
Jar is present in spring-rest-redis/build/libs/
The above command will build angular project and make it as part of Spring Boot application.
Refer to springAngularMerge task in build.gradle file
https://hub.docker.com/r/gtskaushik/spring-rest-redis/
Note:- Requires Redis
- Delete with pattern
- List Operations
- get
- set
- find an element
- get timeseries list
- set timeseries list
- SSE on timeseries list
- Socket on timeseries list
- SSE enabled get on a key pattern
- Socket enabled get on a key pattern
- Programatically set keyspace notifications