Redis security & performance & client connection

Redis security
We can set password parameters through the redis configuration file, so that the client needs password authentication to connect to the redis service, which can make your redis service more secure.
Example
We can check whether password authentication is set by the following command:
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) ""
By default the requirepass parameter is empty, which means that you do not need to pass password authentication Can connect to redis service.
You can modify this parameter with the following commands:
127.0.0.1:6379> CONFIG set requirepass "w3cschool.cc"
OK
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) After "w3cschool.cc"
sets the password, Password authentication is required for the client to connect to the redis service, otherwise the command cannot be executed.




Redis performance testing
Redis performance testing is achieved by executing multiple commands simultaneously.

Syntax
The basic commands for redis performance testing are as follows:
redis-benchmark [option] [option value]
Examples
The following
redis-benchmark -n 10000

PING_INLINE: 141043.72 requests per second
PING_BULK: 142857.14 requests per second
SET: 141442.72 requests per second
GET: 145348.83 requests per second
INCR: 137362.64 requests per second
LPUSH: 145348.83 requests per second
LPOP: 146198.83 requests per second
SADD: 146198.83 requests per second
SPOP: 149253.73 requests per second
LPUSH (needed to benchmark LRANGE): 148588.42 requests per second
LRANGE_100 (first 100 elements): 58411.21 requests per second
LRANGE_300 (first 300 elements): 21195.42 requests per second
LRANGE_500 (first 450 elements): 14539.11 requests per second
LRANGE_600 (first 600 elements): 10504.20 requests per second
MSET (10 keys): 93283.58 requests per second
The optional parameters of the redis performance test tool are as follows:
Sequence Number Option Description Default Value
1 -h Specify the server hostname 127.0.0.1
2 -p Specify the server port 6379
3 -s Specify the server socket
4 -c Specify the number of concurrent connections 50
5 -n Specify the number of requests 10000
6 -d Specify the data size of the SET/GET value in bytes 2
7 -k 1=keep alive 0 =reconnect 1
8 -r SET/GET/INCR use random key, SADD use random value
9 -P pipe <numreq> request 1
10 -q to force quit redis. Show only query/sec values
​​11 --csv Output in CSV format
12 -l Generate loop, execute tests forever
13 -t Run only comma-separated list of test commands.
14 -I Idle mode. Only open N idle connections and wait.
Example
The following example we used multiple parameters to test redis performance:
redis-benchmark -h 127.0.0.1 -p 6379 -t set,lpush -n 10000 -q

SET: 146198.83 requests per second
LPUSH: 145560.41 requests per second
In the above instance, the host is 127.0.0.1 and the port number is 6379. The command executed For set, lpush, the number of requests is 10000, and the result only displays the number of requests executed per second through the -q parameter.




Redis client connection
Redis receives connections from clients by listening to a TCP port or Unix socket. When a connection is established, Redis will perform the following operations:
First, the client socket will be set to non-blocking mode, because Redis uses a non-blocking multiplexing model for network event processing.
Then set the TCP_NODELAY attribute for the socket, disable the Nagle algorithm,
and then create a readable file event to monitor the data transmission of the client socket.
Maximum number of connections
In Redis2.4, the maximum number of connections is directly hardcoded in the code , while in version 2.6 this value became configurable.
The default value of maxclients is 10000, you can also modify this value in redis.conf.
config get maxclients

1) "maxclients"
2) "10000"
instance
In the following example, we set the maximum number of connections to 100000 when the service starts:
redis-server --maxclients 100000
client command
SN command description
1 CLIENT LIST Returns the list of clients connected to the redis service
2 CLIENT SETNAME sets the name of the current connection
3 CLIENT GETNAME Get the service name set by the CLIENT SETNAME command
4 CLIENT PAUSE Suspend the client connection, specify the suspension time in milliseconds
5 CLIENT KILL Close the client connection


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326723075&siteId=291194637