Redis - Using CONFIG SET on the fly in a master slave relationship - redis

I'm looking to change the maxmemory amount and the maxmemory-policy to allkeys-lru while the server is running based on this. I'm going to do this first via:
$ redis-cli
> SET CONFIG maxmemory xxxxxxxxx
> SET CONFIG maxmemory-policy allkeys-lru
Then after seeing that it works in an expected way, i.e. evicts keys until it's size drops to xxxxxxxxx bytes, I will change the config file. When we are running this in a master slave configuration, is there any issues that can occur based on the order I change this config in the master and the slave?

Ouch. Perhaps rdb-tools works with that version... You can identify the keys that you don't need and script a deletion. Regardless, you really need to upgrade your Redis version and do some data housekeeping.

Related

Redis Sentinel Rename-Command Ignored

I am trying to limit the allowed privileges for external redis sentinel users by renaming critical commands as follow:
sentinel rename-command mymaster FAILOVER failover-secret
However, the configurations are being ignored, and I still can trigger the renamed command using the original name:
127.0.0.1:26379> sentinel failover mymaster
OK
Redis Version:
Redis server v=6.0.9 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=e874f7259751a389
The best option would be to put this in your Redis server's config file as opposed to setting it via CLI. It sounds like setting it this way either only applies to that connection (so other connections won't have that config change) or it only persists until the server restarts. Putting it in the config file would persist for all connections, and across restarts.
Another option if you're using Redis v6 (or can upgrade to v6) is to create separate users and specify the available commands per user. This option is discussed in this answer.

redis removes key before expire time and memory limit

I've installed redis in CentOS7 with
yum install redis
I used redis-cli to check current memory, but redis was using only 0.1% of allocated memory.
# Memory
used_memory:1068640
used_memory_human:1.02M
maxmemory:1000000000
maxmemory_human:953.67M
maxmemory_policy:noeviction
Keys are inserted every 1 minute, about 3kb.
And I'm inserting data in python redis module.
redis_connection.set(key, value, timedelta(days=2))
The keys/values are inserted well, but redis removes key before 2 days.
ttl <key> command shows me 172797(about 2 days)
What configuration do I have to change to prevent removing keys before expire time?
After monitoring in redis-cli monitor, I've found that someone is sending "FLUSHALL" commands.
So, I changed my redis port(default 6379 -> other) and added rename-command FLUSHALL <rename_flushall> and it worked.

How to configure Redis to persist data after reboot on Linux?

I installed Redis on Ubuntu 16.04. I couldn't find Redis directory nor redis.conf file (tried with: sudo find redis.conf).
My application depends on some data pulled from third party APIs. I store the (processed) data in Redis. My problem is, after reboot I lose the data. I guess I need to specify in config file that the data should be persisted on reboot, but I couldn't find the config file. Do I need to create the config file? Are there some templates to use? My goal is just to have the data persisted after reboot.
Thank you!
Use dpkg -L redis-server | grep redis.conf to find config file path. It should be located at /etc/redis/redis.conf as I know.
Redis has 2 methods for persistense: Snapshotting and Append-only file:
Snapshotting will be enabled by adding (or uncommenting) save X Y in config file. It means Redis will automatically dump the dataset to disk every X seconds if at least Y keys changed. There could be more than one save options in config file.
Append-only file will be enabled by adding (or uncommenting) appendonly yes in config file
you should turn on the rdb or aof.
see https://redis.io/topics/persistence
Add this to the config file.
appendonly yes
This will append data as you store new data. This enables durability.

Redis.conf for slave with sentinel

Should I use exact mirror of redis.conf on slave, if it would be promoted as master when failover activates.
For example should I appendonly yes to slave ?
The slaves configuration are different than the master one, so you will need to have 1 config file per server, plus one sentinel config file. Here you have a nice tutorial to make it work (basically) https://seanmcgary.com/posts/how-to-build-a-fault-tolerant-redis-cluster-with-sentinel

Redis master/slave replication - single point of failure?

How does one upgrade to a newer version of Redis with zero downtime? Redis slaves are read-only, so it seems like you'd have to take down the master and your site would be read-only for 45 seconds or more while you waited for it to reload the DB.
Is there a way around this?
Redis Team has very good documentation on this
Core Steps:
Setup your new Redis instance as a slave for your current Redis instance. In order to do so you need a different server, or a server that has enough RAM to keep two instances of Redis running at the same time.
If you use a single server, make sure that the slave is started in a different port than the master instance, otherwise the slave will not be able to start at all.
Wait for the replication initial synchronization to complete (check the slave log file).
Make sure using INFO that there are the same number of keys in the master and in the slave. Check with redis-cli that the slave is working as you wish and is replying to your commands.
Configure all your clients in order to use the new instance (that is, the slave).
Once you are sure that the master is no longer receiving any query (you can check this with the MONITOR command), elect the slave to master using the SLAVEOF NO ONE command, and shut down your master.
Full Documentation:
Upgrading or restarting a Redis instance without downtime
When taking the node offline, promote the slave to master using the SLAVEOF command, then when you bring it back online you set it up as a slave and it will copy all data from the online node.
You may also need to make sure your client can handle changed/missing master nodes appropriately.
If you want to get really fancy, you can set up your client to promote a slave if it detects an error writing to the master.
You can use Redis Sentinel for doing this, the sentinel will automatically promote a slave as new master.
you can find more info here http://redis.io/topics/sentinel.
Sentinel is a system used to manage redis servers , it monitors the redis master and slaves continuously, and whenever a master goes down it will automatically promote a slave in to master. and when the old master is UP it will be made as slave of the new master.
Here there will be no downtime or manual configuration of config file is needed.
You can visit above link to find out how to configure sentinel for your redis servers.
Note, you may have to check and set the following config to write to your slave.
("Since Redis 2.6 by default slaves are read-only")
redis-cli config set slave-read-only no
-- Example
-bash-4.1$ redis-cli info
Server
redis_version:2.6.9
-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK
-bash-4.1$ redis-cli set temp 42
(error) READONLY You can't write against a read only slave.
-bash-4.1$ redis-cli slaveof no one
OK
-bash-4.1$ redis-cli set temp 42
OK
-bash-4.1$ redis-cli get temp
"42"
-bash-4.1$ redis-cli config set slave-read-only no
OK
-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK
-bash-4.1$ redis-cli set temp 42
OK
-bash-4.1$ redis-cli get temp
"42"