Skip to content

Instantly share code, notes, and snippets.

Last active July 8, 2022 12:57
Show Gist options
  • Save badboy/5958039 to your computer and use it in GitHub Desktop.
Save badboy/5958039 to your computer and use it in GitHub Desktop.

Redis FAQ or: what you learn when idling in #redis

First: this here is the unofficial FAQ, only containing things that come up by users in the IRC channel #redis on Freenode. There's also a more official FAQ. This document is also available on my site.

X is weird in my instance. Can you help?

Maybe. To better help please give the following info:

  • Output of redis-cli INFO
  • Output of redis-cli CONFIG GET '*'

Don't spam the channel, upload it to pastebin, as a gist or similar.

I want to use SELECT to seperate my data. Is this a good idea?

Antirez decided select was an anti-pattern a loooong time ago. He won't fully deprecate it, but it doesn't get support in new features such as cluster. (via brycebaril)

Just use seperate instances or use namespacing (often used: namespace:real-key-name)

I have some data and need to retrieve it by date. How to to that?

Sorted Sets can be useful here. Store some value and use the timestamp as the score. Then use ZRANGEBYSCORE to get it back.

I installed a new version, but redis-cli info server still shows the old one

  • Make sure the old instance is already stopped. pidof redis-server or ps aux | grep [r]edis-server should only list one PID.
  • Make sure you're starting redis from the right path (if installed manually it might be different than when installed from your package manager)
  • Make sure you're connecting to the right port. It is possible to run multiple instances on different ports (default port is 6379)

I have a background in SQL. Now I'm looking into how I can use Redis. Anything I need to consider?

If you're used to SQL, storing data in Redis is more like creating the indexes for your SQL schema (from: brycebaril)

INFO keyspace shows a different number of keys on the slave than on the master

First: check that master and slave are in sync. Do this by checking INFO replication of both master and slave and compare master_repl_offset and slave_repl_offset. Next: Do you have a lot of expires? On initial sync the slave will drop all already expired keys, while they may still be in the master instance (but are gone as soon as you try to fetch them). (by: Moe, also sync not copying all keys)

I want a new version on my Ubuntu machine

You have multiple possibilities to do this.

  1. Take what the Ubuntu repository provides: apt-get install redis-server (this may be a little bit old)
  2. Compile it yourself, see Download, Section "Installation"
  3. Use a PPA (Personal Package Archive), such as the one by chris-lea or rwky

Where do I find the config?

Redis does not have a default path to put the config in. Instead you always have to specify it as a argument on the command line (or in your init script). Most distributions put the config into /etc/redis.conf, /etc/redis/redis.conf, /var/lib/redis/redis.conf or something similar. So look there first if you uncertain.

I can't compile Redis. It fails with something like "error: no such file or directory: '../deps/hiredis/libhiredis.a'"

Try a make distclean first, then again a make. The compile step tries to be smart by only building dependencies once and use the old compile configuration. But it one of the dependencies fails it does not try to compile them again and thus fails. make distclean removes all previous saved state.

Redis' PUBSUB is awesome. Can I use it for X?

Yes, Redis' pubsub mechanism is quite good. People get excited about it. But it might not be the best option for your use case. Pub/Sub is fire-and-forget. If you publish to a channel and no one is subscribed, that message is lost. It's not persisted, saved for later or held back. Just lost. This might or might not be what you want. For more read section 1.1 of matt's Pub/Sub intro

Ok, I understand Pub/Sub, I really want to use it. Does it work with hundred or thousands of subscriptions/clients?

The mechanism to subscribe to a channel is quite cheap, consider it an constant-time operation. Publish is more expensive, it needs to send to all subscribed clients. For a much more details info read the mailing list thread

My Cluster is unavailable when a Master goes down. How to fix?

If there is no suitable Replica to failover to, the whole Redis Cluster will go into a fail state and won't serve any more queries. It will become available when all slots are covered again (either by resharding or bringing the old Master back). You can change this behaviour and always serve queries by setting cluster-require-full-coverage to no. See the default config for more.

Copy link

hey, i am getting this error during redis cluster setup
~/redis-3.0.1/src# ./redis-trib.rb create

Creating cluster
Connecting to node OK
Connecting to node OK
Connecting to node OK
Performing hash slots allocation on 3 nodes...
Using 3 masters:
M: a8cb04eb6e3a4d6142f3a4fba98ff0059a2db85b
slots:0-5460 (5461 slots) master
M: a8cb04eb6e3a4d6142f3a4fba98ff0059a2db85b
slots:5461-10922 (5462 slots) master
M: a8cb04eb6e3a4d6142f3a4fba98ff0059a2db85b
slots:10923-16383 (5461 slots) master
Can I set the above configuration? (type 'yes' to accept): yes
/var/lib/gems/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:113:in call': ERR Slot 0 is already busy (Redis::CommandError) from /var/lib/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:2556:inblock in method_missing'
from /var/lib/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:37:in block in synchronize' from /usr/lib/ruby/2.1.0/monitor.rb:211:inmon_synchronize'
from /var/lib/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:37:in synchronize' from /var/lib/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:2555:inmethod_missing'
from ./redis-trib.rb:205:in flush_node_config' from ./redis-trib.rb:657:inblock in flush_nodes_config'
from ./redis-trib.rb:656:in each' from ./redis-trib.rb:656:inflush_nodes_config'
from ./redis-trib.rb:997:in create_cluster_cmd' from ./redis-trib.rb:1373:in


can you help me on this?

Copy link

I am having a peculiar issue with my Redis cluster. The nodes in the cluster were all confirgured to run 1 master and 1 slave each. Recently one of the nodes just switched to running 2 slaves and the other is running 2 masters. Is this normal ? There is no indication on what caused it but it seems risk to be running 2 masters on 1 node. There does not seem to be any app impact yet. Please let me know if anybody has an idea.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment