this might sound stupid but i have a javascript script in a html file. I want to store the values of the javascript variables using redis but redis is only compatible with node.js Is there a way i can access the script variables of the html file from the node.js and then store them in redis?
1 Answer
Directly you can't. You could make an ajax call(http://api.jquery.com/jquery.ajax/) to your node server, and then save the variables you like in redis (http://redis.io/commands/SET) .
The ajax call you could choose depends on what exactly you would like to do and if your application is RESTful or not. Assuming you want to add a variable to redis, a POST call is best suited. (https://api.jquery.com/jquery.post/ ).
As an example lets say you post two variables to your node.
$.post("save_to_redis",{var1 : "example_value_1", var2: "example_value_2"},function(result){
//do something with what is returned
}
then in node (using express):
app.post('/save_to_redis',function(req,res){
var variable1 = req.body.var1;
var variable2 = req.body.var2;
//call save to redis for var1 , var2
res.send("whatever you like");
});
Hope this helps