Author: alien

  • Khóa học miễn phí Redis – Pipelining nhận dự án làm có lương

    Redis – Pipelining



    Redis is a TCP server and supports request/response protocol. In Redis, a request is accomplished with the following steps −

    • The client sends a query to the server, and reads from the socket, usually in a blocking way, for the server response.

    • The server processes the command and sends the response back to the client.

    Meaning of Pipelining

    The basic meaning of pipelining is, the client can send multiple requests to the server without waiting for the replies at all, and finally reads the replies in a single step.

    Example

    To check the Redis pipelining, just start the Redis instance and type the following command in the terminal.

    $(echo -en "PINGrn SET tutorial redisrnGET tutorialrnINCR
    visitorrnINCR visitorrnINCR visitorrn"; sleep 10) | nc localhost 6379
    +PONG
    +OK
    redis
    :1
    :2
    :3
    

    In the above example, we will check Redis connection by using PING command. We have set a string named tutorial with value redis. Later, we get that keys value and increment the visitor number three times. In the result, we can see that all commands are submitted to Redis once, and Redis provides the output of all commands in a single step.

    Benefits of Pipelining

    The benefit of this technique is a drastically improved protocol performance. The speedup gained by pipelining ranges from a factor of five for connections to localhost up to a factor of at least one hundred over slower internet connections.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Client Connection nhận dự án làm có lương

    Redis – Client Connection



    Redis accepts clients’ connections on the configured listening TCP port and on the Unix socket, if enabled. When a new client connection is accepted, the following operations are performed −

    • The client socket is put in non-blocking state since Redis uses multiplexing and non-blocking I/O.

    • The TCP_NODELAY option is set in order to ensure that we don”t have delays in our connection.

    • A readable file event is created so that Redis is able to collect the client queries as soon as new data is available to be read on the socket.

    Maximum Number of Clients

    In Redis config (redis.conf), there is a property called maxclients, which describes the maximum number of clients that can connect to Redis.

    Following is the basic syntax of command.

    config get maxclients
    
    1) "maxclients"
    2) "10000"
    

    By default, this property is set to 10000 (depending upon the maximum number of file descriptors limit of OS), although you can change this property.

    Example

    In the following example, we have set the maximum number of clients to 100000, while starting the server.

    redis-server --maxclients 100000
    

    Client Commands

    Sr.No Command Description
    1 CLIENT LIST Returns the list of clients connected to Redis server
    2 CLIENT SETNAME Assigns a name to the current connection
    3 CLIENT GETNAME Returns the name of the current connection as set by CLIENT SETNAME
    4 CLIENT PAUSE This is a connections control command able to suspend all the Redis clients for the specified amount of time (in milliseconds)
    5 CLIENT KILL This command closes a given client connection.

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Benchmarks nhận dự án làm có lương

    Redis – Benchmarks



    Redis benchmark is the utility to check the performance of Redis by running n commands simultaneously.

    Syntax

    Following is the basic syntax of Redis benchmark.

    redis-benchmark [option] [option value]
    

    Example

    Following example checks Redis by calling 100000 commands.

    redis-benchmark -n 100000
    
    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
    

    Following is a list of available options in Redis benchmark.

    Sr.No Option Description Default Value
    1 -h Specifies server host name 127.0.0.1
    2 -p Specifies server port 6379
    3 -s Specifies server socket
    4 -c Specifies the number of parallel connections 50
    5 -n Specifies the total number of requests 10000
    6 -d Specifies data size of SET/GET value in bytes 2
    7 -k 1=keep alive, 0=reconnect 1
    8 -r Use random keys for SET/GET/INCR, random values for SADD
    9 -p Pipeline <numreq> requests 1
    10 -h Specifies server host name
    11 -q Forces Quiet to Redis. Just shows query/sec values
    12 –csv Output in CSV format
    13 -l Generates loop, Run the tests forever
    14 -t Only runs the comma-separated list of tests
    15 -I Idle mode. Just opens N idle connections and wait

    Example

    Following example shows the multiple usage options in Redis benchmark utility.

    redis-benchmark -h 127.0.0.1 -p 6379 -t set,lpush -n 100000 -q
    
    SET: 146198.83 requests per second
    LPUSH: 145560.41 requests per second
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Server nhận dự án làm có lương

    Redis – Server



    Redis server commands are basically used to manage Redis server.

    Example

    Following example explains how we can get all statistics and information about the server.

    redis 127.0.0.1:6379> INFO
    
    # Server
    redis_version:2.8.13
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:c2238b38b1edb0e2
    redis_mode:standalone
    os:Linux 3.5.0-48-generic x86_64
    arch_bits:64
    multiplexing_api:epoll
    gcc_version:4.7.2
    process_id:3856
    run_id:0e61abd297771de3fe812a3c21027732ac9f41fe
    tcp_port:6379
    uptime_in_seconds:11554
    uptime_in_days:0 hz:10
    lru_clock:16651447
    config_file:
    
    # Clients
    connected_clients:1
    client_longest_output_list:0
    client_biggest_input_buf:0
    blocked_clients:0
    
    # Memory
    used_memory:589016
    used_memory_human:575.21K
    used_memory_rss:2461696
    used_memory_peak:667312
    used_memory_peak_human:651.67K
    used_memory_lua:33792
    mem_fragmentation_ratio:4.18
    mem_allocator:jemalloc-3.6.0
    
    # Persistence
    loading:0
    rdb_changes_since_last_save:3
    rdb_bgsave_in_progress:0
    rdb_last_save_time:1409158561
    rdb_last_bgsave_status:ok
    rdb_last_bgsave_time_sec:0
    rdb_current_bgsave_time_sec:-1
    aof_enabled:0
    aof_rewrite_in_progress:0
    aof_rewrite_scheduled:0
    aof_last_rewrite_time_sec:-1
    aof_current_rewrite_time_sec:-1
    aof_last_bgrewrite_status:ok
    aof_last_write_status:ok
    
    # Stats
    total_connections_received:24
    total_commands_processed:294
    instantaneous_ops_per_sec:0
    rejected_connections:0
    sync_full:0
    sync_partial_ok:0
    sync_partial_err:0
    expired_keys:0
    evicted_keys:0
    keyspace_hits:41
    keyspace_misses:82
    pubsub_channels:0
    pubsub_patterns:0
    latest_fork_usec:264
    
    # Replication
    role:master
    connected_slaves:0
    master_repl_offset:0
    repl_backlog_active:0
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:0
    repl_backlog_histlen:0
    
    # CPU
    used_cpu_sys:10.49
    used_cpu_user:4.96
    used_cpu_sys_children:0.00
    used_cpu_user_children:0.01
    
    # Keyspace
    db0:keys = 94,expires = 1,avg_ttl = 41638810
    db1:keys = 1,expires = 0,avg_ttl = 0
    db3:keys = 1,expires = 0,avg_ttl = 0
    

    Redis Server Commands

    Following table lists some basic commands related to Redis server.

    Sr.No Command & Description
    1

    Asynchronously rewrites the append-only file

    2

    Asynchronously saves the dataset to the disk

    3

    Kills the connection of a client

    4

    Gets the list of client connections to the server

    5

    Gets the name of the current connection

    6

    Stops processing commands from the clients for a specified time

    7

    Sets the current connection name

    8

    Gets an array of Cluster slot to node mappings

    9

    Gets an array of Redis command details

    10

    Gets total number of Redis commands

    11

    Extracts the keys given a full Redis command

    12

    Asynchronously saves the dataset to the disk

    13

    Gets an array of specific Redis command details

    14

    Gets the value of a configuration parameter

    15

    Rewrites the configuration file with the in-memory configuration

    16

    Sets a configuration parameter to the given value

    17

    Resets the stats returned by INFO

    18

    Returns the number of keys in the selected database

    19

    Gets debugging information about a key

    20

    Makes the server crash

    21

    Removes all the keys from all databases

    22

    Removes all the keys from the current database

    23

    Gets information and statistics about the server

    24

    Gets the UNIX time stamp of the last successful save to the disk

    25

    Listens for all the requests received by the server in real time

    26

    Returns the role of the instance in the context of replication

    27

    Synchronously saves the dataset to the disk

    28

    Synchronously saves the dataset to the disk and then shuts down the server

    29

    Makes the server a slave of another instance, or promotes it as a master

    30

    Manages the Redis slow queries log

    31

    Command used for replication

    32

    Returns the current server time


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Backup nhận dự án làm có lương

    Redis – Backup



    Redis SAVE command is used to create a backup of the current Redis database.

    Syntax

    Following is the basic syntax of redis SAVE command.

    127.0.0.1:6379> SAVE
    

    Example

    Following example creates a backup of the current database.

    127.0.0.1:6379> SAVE
    OK
    

    This command will create a dump.rdb file in your Redis directory.

    Restore Redis Data

    To restore Redis data, move Redis backup file (dump.rdb) into your Redis directory and start the server. To get your Redis directory, use CONFIG command of Redis as shown below.

    127.0.0.1:6379> CONFIG get dir
    1) "dir"
    2) "/user/tutorialspoint/redis-2.8.13/src"
    

    In the output of the above command /user/tutorialspoint/redis-2.8.13/src is the directory, where Redis server is installed.

    Bgsave

    To create Redis backup, an alternate command BGSAVE is also available. This command will start the backup process and run this in the background.

    Example

    127.0.0.1:6379> BGSAVE
    Background saving started
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Transactions nhận dự án làm có lương

    Redis – Transactions



    Redis transactions allow the execution of a group of commands in a single step. Following are the two properties of Transactions.

    • All commands in a transaction are sequentially executed as a single isolated operation. It is not possible that a request issued by another client is served in the middle of the execution of a Redis transaction.

    • Redis transaction is also atomic. Atomic means either all of the commands or none are processed.

    Sample

    Redis transaction is initiated by command MULTI and then you need to pass a list of commands that should be executed in the transaction, after which the entire transaction is executed by EXEC command.

    redis 127.0.0.1:6379> MULTI
    OK
    List of commands here
    redis 127.0.0.1:6379> EXEC
    

    Example

    Following example explains how Redis transaction can be initiated and executed.

    redis 127.0.0.1:6379> MULTI
    OK
    redis 127.0.0.1:6379> SET tutorial redis
    QUEUED
    redis 127.0.0.1:6379> GET tutorial
    QUEUED
    redis 127.0.0.1:6379> INCR visitors
    QUEUED
    redis 127.0.0.1:6379> EXEC
    1) OK
    2) "redis"
    3) (integer) 1
    

    Redis Transaction Commands

    Following table shows some basic commands related to Redis transactions.

    Sr.No Command & Description
    1

    Discards all commands issued after MULTI

    2

    Executes all commands issued after MULTI

    3

    Marks the start of a transaction block

    4

    Forgets about all watched keys

    5

    Watches the given keys to determine the execution of the MULTI/EXEC block


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Scripting nhận dự án làm có lương

    Redis – Scripting



    Redis scripting is used to evaluate scripts using the Lua interpreter. It is built into Redis starting from version 2.6.0. The command used for scripting is EVAL command.

    Syntax

    Following is the basic syntax of EVAL command.

    redis 127.0.0.1:6379> EVAL script numkeys key [key ...] arg [arg ...]
    

    Example

    Following example explains how Redis scripting works.

    redis 127.0.0.1:6379> EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1
    key2 first second
    1) "key1"
    2) "key2"
    3) "first"
    4) "second"
    

    Redis Scripting Commands

    Following table lists some basic commands related to Redis Scripting.

    Sr.No Command & Description
    1

    Executes a Lua script.

    2

    Executes a Lua script.

    3

    Checks the existence of scripts in the script cache.

    4

    Removes all the scripts from the script cache.

    5

    Kills the script currently in execution.

    6

    Loads the specified Lua script into the script cache.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Security nhận dự án làm có lương

    Redis – Security



    Redis database can be secured, such that any client making a connection needs to authenticate before executing a command. To secure Redis, you need to set the password in the config file.

    Example

    Following example shows the steps to secure your Redis instance.

    127.0.0.1:6379> CONFIG get requirepass
    1) "requirepass"
    2) ""
    

    By default, this property is blank, which means no password is set for this instance. You can change this property by executing the following command.

    127.0.0.1:6379> CONFIG set requirepass "tutorialspoint"
    OK
    127.0.0.1:6379> CONFIG get requirepass
    1) "requirepass"
    2) "tutorialspoint"
    

    After setting the password, if any client runs the command without authentication, then (error) NOAUTH Authentication required. error will return. Hence, the client needs to use AUTH command to authenticate himself.

    Syntax

    Following is the basic syntax of AUTH command.

    127.0.0.1:6379> AUTH password
    

    Example

    127.0.0.1:6379> AUTH "tutorialspoint"
    OK
    127.0.0.1:6379> SET mykey "Test value"
    OK
    127.0.0.1:6379> GET mykey
    "Test value"
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Connections nhận dự án làm có lương

    Redis – Connections



    Redis connection commands are basically used to manage client connections with Redis server.

    Example

    Following example explains how a client authenticates itself to Redis server and checks whether the server is running or not.

    redis 127.0.0.1:6379> AUTH "password"
    OK
    redis 127.0.0.1:6379> PING
    PONG
    

    Redis Connection Commands

    Following table lists some basic commands related to Redis connections.

    Sr.No Command & Description
    1

    Authenticates to the server with the given password

    2

    Prints the given string

    3

    Checks whether the server is running or not

    4

    Closes the current connection

    5

    Changes the selected database for the current connection


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Redis – Publish Subscribe nhận dự án làm có lương

    Redis – Publish Subscribe



    Redis Pub/Sub implements the messaging system where the senders (in redis terminology called publishers) sends the messages while the receivers (subscribers) receive them. The link by which the messages are transferred is called channel.

    In Redis, a client can subscribe any number of channels.

    Example

    Following example explains how publish subscriber concept works. In the following example, one client subscribes a channel named ‘redisChat’.

    redis 127.0.0.1:6379> SUBSCRIBE redisChat
    Reading messages... (press Ctrl-C to quit)
    1) "subscribe"
    2) "redisChat"
    3) (integer) 1
    

    Now, two clients are publishing the messages on the same channel named ‘redisChat’ and the above subscribed client is receiving messages.

    redis 127.0.0.1:6379> PUBLISH redisChat "Redis is a great caching technique"
    (integer) 1
    redis 127.0.0.1:6379> PUBLISH redisChat "Learn redis by tutorials point"
    (integer) 1
    1) "message"
    2) "redisChat"
    3) "Redis is a great caching technique"
    1) "message"
    2) "redisChat"
    3) "Learn redis by tutorials point"
    

    Redis PubSub Commands

    Following table lists some basic commands related to Redis Pub/Sub.

    Sr.No Command & Description
    1

    Subscribes to channels matching the given patterns.

    2

    Tells the state of Pub/Sub system. For example, which clients are active on the server.

    3

    Posts a message to a channel.

    4

    Stops listening for messages posted to channels matching the given patterns.

    5

    Listens for messages published to the given channels.

    6

    Stops listening for messages posted to the given channels.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc