When does Redis pipelining become more efficient? - redis

I was wondering, when does pipelining become more efficient? E.g. if I have to query the server once, a pipeline would be less efficient that just using the redis instance.
If I have to query the server twice, e.g. check something exists, if it does, grab it, is pipeline more efficient or is using the redis instance?
If I have to query something three times.. etc.
When does pipelining become more efficient than using the redis instance?~
Thank you

If you only operation once , it's the same .
The pipelining like batch process mechanism . If you have three commands to execute at the normal way , the client need send three tcp packets and receive three tcp packets (every command need send one and receive one ) ; but when use pipelining , the client package 3 command to server , just send one tcp packet and receive one .
You can see the official document : Using pipelining to speedup Redis queries

Related

Should I always use pipelining when there are more than 1 command in Redis?

I am new to Redis, and a little bit confused when I should use pipelining or should I use it all the time when there are more than 1 command to be sent?
For example, if I want to send 10 SET commands to Redis server at a time, should I simply run the 10 commands one by one or should I pipeline them?
Are there any disadvantage to pipeline 10 SET commands instead of sending them one by one?
when I should use pipelining
Pipeline is used to reduce RTT, so that you can improve the performance, when you need to send many commands to Redis.
should I use it all the time when there are more than 1 command to be sent?
It depends. You should discuss it case by case.
if I want to send 10 SET commands to redis server at a time, should I simply run the 10 commands one by one or should I pipeline them?
Pipline these commands will be much faster than sending 10 commands. However, in this particular case, the best choice is using the MSET command.
Are there any disadvantage to pipeline 10 SET commands instead of sending them one by one?
With pipeline, Redis needs to consume more memory to hold the result of all these piped commands before sending them to client. So if you pipe too many commands, that's might be a problem.

Is there any advantage of Redis connection pool over single connection?

I am trying to use Redis for my application. In my application multiple user at the same time want to get the data which is stored in redis cache . As Redis is Single-threaded & we can't run operation concurrently against a single server, by using connection pool can we execute multiple commands at a single time to achieve the high throughput ?
I have read some of the articles in open forum & they said it would be helpful using connection pooling only when we know we are going to use redis blocking operation some time like BLPOP. But, if we are sure that we are never going to use blocking operations & use only normal operation like SET,MSET, GET & MGET then using connection pooling having any advantage over single connection ?
Also can anybody have any idea/recommendation about the maximum no of keys we will need to provide in MGET command in order to get the maximum values of all specified keys ?
It will be very helpful if I get answers to this. Thanks in advance.

How to SET on specific redis server with StackExchange.Redis client?

I have 3 redis servers running in docker containers. From redis-cli I can SET on specific server.
SET myValue 100
How can I do this with StackExchange.Redis client?
I don't see anything in server api that allows to do that. Bear in mind that I don't know much about Redis at all.
var connection = ConnectionMultiplexer.Connect("localhost:6379,localhost:6380,localhost:6381");
var server = connection.GetServer("localhost", 6381);
server.???
SE.Redis expects to be managing a single logical keyspace; the support for multiple nodes is intended either for master/replica setups, or for redis-cluster (although, in the case of cluster, node discovery is achieved via the redis API, so a single node would be fine if it is reachable). With that in place: the selection of servers is implicit from the operation (i.e. writes need to go to a master, and in the case of "cluster", the keyspace shard mapping should be applied).
If you want to write to separate servers as though they are separate databases, you should use a connection per server; not a single connection that spans them all. Right now, SE.Redis is probably detecting 3 master nodes and electing to use one of them arbitrarily. You can see what it thinks by passing a TextWriter to the Connect/ConnectAsync method.

Maximum number of queries in a Redis multi/exec request

Is there a limit to how many queries one could send when using multi/exec from a node-redis application or is it only a question of available memory on the client and server to buffer requests and replies?
It's only a question of available memory.
Firstly on the client side as node-redis will queue up the queries you do on the multi and not send any of them to Redis before the exec is executed.
And secondly on the Redis server as it needs to be able to hold all the queries and answers at once as it is an atomic operation.

How to build a simplified redis cluster (support data sharding and load balance)?

Since the redis cluster is still a work in progress, I want to build a simplied one by myselfin the current stage. The system should support data sharding,load balance and master-slave backup. A preliminary plan is as follows:
Master-slave: use multiple master-slave pairs in different locations to enhance the data security. Matsters are responsible for the write operation, while both masters and slaves can provide the read service. Datas are sent to all the masters during one write operation. Use Keepalived between the master and the slave to detect failures and switch master-slave automatically.
Data sharding: write a consistant hash on the client side to support data sharding during write/read in case the memory is not enougth in single machine.
Load balance: use LVS to redirect the read request to the corresponding server for the load balance.
My question is how to combine the LVS and the data sharding together?
For example, because of data sharding, all keys are splited and stored in server A,B and C without overlap. Considering the slave backup and other master-slave pairs, the system will contain 1(A,B,C), 2(A,B,C) , 3(A,B,C) and so on, where each one has three servers. How to configure the LVS to support the redirection in such a situation when a read request comes? Or is there other approachs in redis to achieve the same goal?
Thanks:)
You can get really close to what you need by using:
twemproxy shard data across multiple redis nodes (it also supports node ejection and connection pooling)
redis slave master/slave replication
redis sentinel to handle master failover
depending on your needs you probably need some script listening to fail overs (see sentinel docs) and clean things up when a master goes down