In redis, two of the eviction policies, allkeys-lru and volatile-lru, evict keys based on access time. So, this information must exist somewhere. Is it possible for me to query the access time of a key? Or, better yet, page through a sorted list of keys based on access time?
Look at Object IDLETIME it gives time for which the object was idle
as guided by #Itamar Haber the way they disable some command is by using redis.conf
# It is also possible to completely kill a command by renaming it into
# an empty string:
#
rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command DEBUG ""
As you are using Redis as a service on Heroku you have to have admin rights to do this
Hope this helps!
Related
Is there any way to schedule redis back-ups at a specific time of day (e.g. 3:00 AM GMT) - preferably via a setting in the accompanying conf file?
I already understand that one can set a backup rule in redis configuration (e.g. save every X hours if Y keys have changed).
But how does one schedule the said backup at a particular time of day? Would love to know something basic, but effective. In case it matters, my redis version is 5.0.3
So far I know it is currently not possible from inside redis. But its achievable using crontab. Here is a short example:
create a backup script file:
/tmp/backup.sh
echo save | redis-cli >> /tmp/redis-backup.log
If using sockets, the above would be:
echo save | redis-cli -s /var/run/redis.sock >> /tmp/redis-backup.log
The socket location in your system may vary.
Next, give execute permission to the script:
chmod +x /tmp/backup.sh
Finally, make an entry in crontab: crontab -e
0 3 * * * /tmp/backup.sh
This will run backup.sh in exactly 3AM.
In case you want to disable redis saving setup in the conf (without restarting the redis instance), the best way is to log into redis-cli and issue CONFIG SET save "". Double check that it worked via CONFIG GET save. Finally, don't forget to change the save settings in the relevant conf file as well. Lastly, it's wiser to use bgsave instead of save if tackling a redis instance in production.
For more, checkout these links:
How To Back Up and Restore Your Redis Data
Cron Scheduler
How To Start/Stop/Restart Cron Service In Linux
Is there any way to secure redis keys, even the person who knows redis-server password that can not access or see redis keys.
I need this security because i am storing session in redis keys.
For each user there is unique key which is stored in redis as key.
If user knows keys then he can access any account.
Any suggestions.
Thanks.
You can create a hash key, e.g. md5, for each session id, and take the hash key as Redis key.
// set
session_id_md5 = md5(session_id)
redis.set(session_id_md5, value);
When you want to get session info from Redis, re-create the hash key with session id, and search Redis with the hash key
// get
session_id_md5 = md5(session_id);
redis.get(session_id_md5);
Redis isn't designed to be used the way you are using it so this isn't possible, you should move your authentication up a level to your application.
Redis doesn't provide any ACLs, so restricting access to KEYS command for certain clients isn't possible without some additional middleware. But if you want to just disable KEYS command, add following line to your redis config:
rename-command KEYS ""
You probably should also disable MONITOR and CONFIG commands:
rename-command CONFIG ""
rename-command MONITOR ""
Thanks to all of you for your suggestions
I conclude with the following.
I want to provide security among developers not end users. we have a team of few person who has access of redis server to start and stop service and other configuration, I want to restrict those users from accessing keys.
As Redis doesn't have ACLs so i think we can't do such things. Still Anybody have any other idea then they are most welcome :)
I have my redis server in my local and when i copy those contents with dump.rdb bgsave and put it in my other machine .Every thing works fine but after some inactivity my keys keep getting deleted and I'm ending up with 433KB of dump file and my dump file being replaced.What am i doing wrong?I have 3.0.3 in local and 2.8.4 in my other machine.I am following steps from this [link][1]. I couldn't able to figure out this issue.I checked the server logs and there's no error there just only those bgsaves for every 900,300 seconds.Please Help me
Most commonly this is probably because
Your Redis instance is open to a public network and isn't using password authentication - crackers can do anything for deleting your keys to compromising the server.
All your keys are set to expire
You are using an eviction policy such as all-keys, your maxmemory is set and you've reached it.
You have a rogue piece of code that deletes them.
I am using Redis since last 12 months without any issue, But from last 30 days unknowingly the database getting empty and we couldn't find any logs regarding this. Even it is flushing all the data out randomly after restoration.
We tried following steps to resolve this but result was zero.
We have checked redis logs
Monitored the redis using MONITOR command
We are trying to renaming the critical commands through config but redis is dump after the config change below is example command
rename-command FLUSHDB e0cc96ad2eab73c2c347011806a76b73
We gone made without knowing anything. Helps are appreciated.
Redis Version : 2.8.17
Running under Debian Linux
Renaming the command through config file will work in this case.
Same rename command you have to place inside the config file.
rename-command FLUSHDB e0cc96ad2eab73c2c347011806a76b73
We have 3 apps on our server. They talk to each other via Redis. Redis is the bus for all communication.
Something on our server is incorrectly deleting keys from Redis. I am trying to track down the problem. For each app, I downloaded the code to my machine, and then tried:
grep -iR "flush" *
grep -iR "del" *
Two of the apps are free of "flush" and "del". Only one app has "del". So I found its PID and:
kill -9 2312
I also did "ps aux" to make sure that app was off.
The other 2 apps only have:
hset
hget
hmgetall
The disappearance of the keys in Redis is erratic. Some keys last several minutes, or even hours. Others disappear quickly.
As near as I can see, none of the developers have set timeouts on the keys in Redis. But maybe something sets a default timeout?
How do I debug this? Where do I look?
Do take a look at Redis configuration:
config get maxmemory*
Be sure that maxmemory is large enough for your dataset otherwise keys will be automatically dropped with the specified maxmemory-policy.