I'm trying to use redis as storage but it eats up my memory. I have data coming in a few times a second which I store in redis. This data is continuously changing and I assume that because it changes different values are stored instead of updating the current value in redis. What I'm trying to do is either find a way to remove the old values or update a values as data comes in. I cant use a flushall or a simple clear as I need the latest data information to stay in redis. This is what I have I tried implementing the client.expire within the function but because this function is called so often it gets stuck in a never-ending loop of flushing the system. Here's a snippet of the code im dealing with:
function in_redis(temp_streamName, temp_accelX, temp_accelY, temp_accelZ, temp_geoLat, temp_geoLon, temp_time)
{
var child_info = child.fork(__dirname + '/child_proccessors/child_db'); // Acces the sub process in the folder specified
// console.log(jsonResult);
// console.log("in-redis-streamName: "+ temp_streamName);
// console.log("in-redis-temp_accelX: "+ temp_accelX);
// console.log("in-redis-temp_accelY: "+ temp_accelY);
// console.log("in-redis-temp_accelZ: "+ temp_accelZ);
// console.log("in-redis-temp_geoLat: "+ temp_geoLat);
// console.log("in-redis-temp_geoLon: "+ temp_geoLon);
// console.log("in-redis-timestamp: "+ temp_time);
client.hmset(temp_streamName,"streamName",temp_streamName,"AccelX",temp_accelX,"AccelY",temp_accelY,"AccelZ",temp_accelZ,"GeoLat", temp_geoLat, "GeoLon", temp_geoLon, "Timestamp",temp_time, redis.print);
client.hget(temp_streamName, "streamName", redis.print); //printing redis data
client.hget(temp_streamName, "AccelX", redis.print); //printing redis data
client.hget(temp_streamName, "AccelY", redis.print); //printing redis data
client.hget(temp_streamName, "AccelZ", redis.print); //printing redis data
client.hget(temp_streamName, "GeoLat", redis.print); //printing redis data
client.hget(temp_streamName, "GeoLon", redis.print); //printing redis data
client.hget(temp_streamName, "Timestamp", redis.print); //printing redis data
//send the data to the client server using the sockets
io.sockets.emit('Sensor', {"streamName": temp_streamName, "AccelX": temp_accelX, "AccelY": temp_accelY, "AccelZ": temp_accelZ, "GeoLat":temp_geoLat, "GeoLon":temp_geoLon, "Timestamp":temp_time});
//send the data to the child process so it can be stored in mongo
child_info.send({"streamName": temp_streamName, "AccelX": temp_accelX, "AccelY": temp_accelY, "AccelZ": temp_accelZ, "GeoLat":temp_geoLat, "GeoLon":temp_geoLon, "Timestamp":temp_time});
}
Any help would be great
If you want to update the values, simply use the same name for your hash, rather than generating a different temp_streamName every time.
If you prefer to create new values in any case, you can always use the expire command and set an expiration to the temp_streamName hash (after you issue the hmset command). The value will expire after the time you set.
A third alternative is just let redis to use up memory and free the least used values when the memory gets full. You need to change the configuration in your redis config file. If you want to use redis both for storing transient and permanent data, this last option is not really a good idea.