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.
Related
I have a requirement to dynamically turn on appendonly setting after redis replayed all the data from backup file dump.rdb. So is there any redis-cli cmd to know that redis has loaded all the data from dump.rdb snapshot?#
When Redis is loading RDB files, it refuses most commands, e.g. PING. So you can send a PING command, i.e. redis-cli ping, to Redis. If it returns PONG, Redis has already loaded all data. If Redis is still loading, it returns an error reply.
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.
I have setup up Redis master slave configuration having one master (6379 port) and 3 slaves (6380,6381,6382) running in the same machine. Looks like cluster is setup properly as I can see the following output on running info command:
# Replication
role:master
connected_slaves:3
slave0:ip=127.0.0.1,port=6380,state=online,offset=29,lag=1
slave1:ip=127.0.0.1,port=6381,state=online,offset=29,lag=1
slave2:ip=127.0.0.1,port=6382,state=online,offset=29,lag=1
master_repl_offset:43
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:42
But wherever I try to add new key in master, I get the following error:
(error) CLUSTERDOWN Hash slot not served
Using redis-3.0.7 in Mac OS X Yosemite.
I had the same issue, turned out I forgot to run the create cluster:
cd /path/to/utils/create-cluster
./create-cluster create
http://redis.io/topics/cluster-tutorial#creating-a-redis-cluster-using-the-create-cluster-script
To fix slots issue while insertion:
redis-cli --cluster fix localhost:6379
You can use ruby script buddled with redis for creating clusters as mentioned below :
/usr/local/redis-3.2.11/src/redis-trib.rb create --replicas 1 192.168.142.128:7001 192.168.142.128:7002 192.168.142.128:7003 192.168.142.128:7004 192.168.142.128:7005 192.168.142.128:7006
There is a hash slot not allotted to any master. Check the hash slots by looking at the column 9 in the output of following command (column 9 will be empty if no hash slots for that node):
redis-cli -h masterIP -p masterPORT CLUSTER NODES
The hash slots can be allotted by using the following command.
redis-cli -h masterIP -p masterPORT CLUSTER ADDSLOTS SLOTNNUMBER
But this has to be done for every slot number individually without missing. Use a bat script to include it in for loop. something like,
for /L %a in (0,1,5400) Do redis-cli -h 127.0.0.1 -p 7001 cluster addslots %a
Also, this command works before assigning slaves to master. After this ADDSLOTS step and completing the setup, the SET and GET worked fine. Remember to use -c along with redis-cli before SET to enable cluster support.
The issue comes when one or more Redis nodes gets corrupted and can no longer serve its configured hash slots.
You will have to bootstrap the cluster again to make sure the nodes agree on the hash slots to serve.
If the Redis nodes contain data or a key in the database 0, you will have to clear this data before rerunning the bootstrap.
I have redis 3.0.2 running on CentOS 6 (64-bit) storing log entries for Logstash but every time it gets to about 1.85GB it zeros out the list. I had watch "redis-cli llen logstash | tee -a llen.log" running and captured this:
2823399
2827076
2831776
2836436
0
4470
8684
12531
17213
Any help understanding what is going on would be greatly appreciated.
Check your maxmemory and maxmemory-policy config to see if redis is performing eviction on logstash.
If it's not eviction, you might just have to use redis-cli monitor and bump your loglevel config up to verbose or debug to see what's actually happening.
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"