skip to Main Content

My doubt is,

I have the same instance of Redis, with multiple databases (one for each service).

If more than one service used the same database, would the prefix search be slower? (having the data of all the services in one place and having to go through all of them, as opposed to only going through the selected base)

4

Answers


  1. Partitioning in Redis serves two main goals:

    • It allows for much larger databases, using the sum of the memory of
      many computers. Without partitioning you are limited to the amount of
      memory a single computer can support.
    • It allows scaling the computational power to multiple cores and multiple computers, and the network bandwidth to multiple computers and network adapters.

    Ref

    Login or Signup to reply.
  2. If you run multiple databases on a single instance, they all will try to use and acquire the same resource and memory plus they will also run their core process which will not help you.
    you can think like this, 2 OS running on the same machine will never match the performance of a single OS utilizing all resources of the machine.
    What you can do to increase the performance is make more tables or use the partition concept. This will not put too much data in a single table and the search will work faster.

    Login or Signup to reply.
  3. Integration through database should be avoided, read more here: https://martinfowler.com/bliki/IntegrationDatabase.html

    If you use KEYS command for it, then read this from documentation:

    Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.
    

    Redis doesn’t support prefix index, but you can use sorted set to do prefix search to some degree.

    Redis is in-memory store, so all reads are pretty fast as long as you model it the right way.

    Better query multiple times than doing integration through db…

    Btw if you have multiple services owning the same data, then you should probably model your services differently…

    Login or Signup to reply.
  4. In general, I would avoid key prefix searching. REDIS isn’t a standard database and key searches are slow.

    Since REDIS is a key/value store, it’s optimized as such.
    To take advantage of REDIS you want to hit the desired key directly.

    I expect key search time increases with the total amount of keys, so splitting the database would potentially reduce the key search time.

    However, if your doing key searches, I would put the desired keys into a key list and just do a direct look up there.

    desired_prefix = ["desired_prefix-a", "desired_prefix-b", ...]
    
    lpush "prefix_x_keys" "x-a"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search