Category: redis

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

    Redis – Hashes



    Redis Hashes are maps between the string fields and the string values. Hence, they are the perfect data type to represent objects.

    In Redis, every hash can store up to more than 4 billion field-value pairs.

    Example

    redis 127.0.0.1:6379> HMSET tutorialspoint name "redis tutorial"
    description "redis basic commands for caching" likes 20 visitors 23000
    OK
    redis 127.0.0.1:6379> HGETALL tutorialspoint
    1) "name"
    2) "redis tutorial"
    3) "description"
    4) "redis basic commands for caching"
    5) "likes"
    6) "20"
    7) "visitors"
    8) "23000"
    

    In the above example, we have set Redis tutorials detail (name, description, likes, visitors) in hash named ‘tutorialspoint’.

    Redis Hash Commands

    Following table lists some basic commands related to hash.

    Sr.No Command & Description
    1

    Deletes one or more hash fields.

    2

    Determines whether a hash field exists or not.

    3

    Gets the value of a hash field stored at the specified key.

    4

    Gets all the fields and values stored in a hash at the specified key

    5

    Increments the integer value of a hash field by the given number

    6

    Increments the float value of a hash field by the given amount

    7

    Gets all the fields in a hash

    8

    Gets the number of fields in a hash

    9

    Gets the values of all the given hash fields

    10

    Sets multiple hash fields to multiple values

    11

    Sets the string value of a hash field

    12

    Sets the value of a hash field, only if the field does not exist

    13

    Gets all the values in a hash

    14

    Incrementally iterates hash fields and associated values


    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 – Sorted Sets nhận dự án làm có lương

    Redis – Sorted Sets



    Redis Sorted Sets are similar to Redis Sets with the unique feature of values stored in a set. The difference is, every member of a Sorted Set is associated with a score, that is used in order to take the sorted set ordered, from the smallest to the greatest score.

    In Redis sorted set, add, remove, and test for the existence of members in O(1) (constant time regardless of the number of elements contained inside the set). Maximum length of a list is 232 – 1 elements (4294967295, more than 4 billion of elements per set).

    Example

    redis 127.0.0.1:6379> ZADD tutorials 1 redis
    (integer) 1
    redis 127.0.0.1:6379> ZADD tutorials 2 mongodb
    (integer) 1
    redis 127.0.0.1:6379> ZADD tutorials 3 mysql
    (integer) 1
    redis 127.0.0.1:6379> ZADD tutorials 3 mysql
    (integer) 0
    redis 127.0.0.1:6379> ZADD tutorials 4 mysql
    (integer) 0
    redis 127.0.0.1:6379> ZRANGE tutorials 0 10 WITHSCORES
    1) "redis"
    2) "1"
    3) "mongodb"
    4) "2"
    5) "mysql"
    6) "4"
    

    In the above example, three values are inserted with its score in Redis sorted set named ‘tutorials’ by the command ZADD.

    Redis Sorted Sets Commands

    Following table lists some basic commands related to sorted sets.

    Sr.No Command & Description
    1

    Adds one or more members to a sorted set, or updates its score, if it already exists

    2

    Gets the number of members in a sorted set

    3

    Counts the members in a sorted set with scores within the given values

    4

    Increments the score of a member in a sorted set

    5

    Intersects multiple sorted sets and stores the resulting sorted set in a new key

    6

    Counts the number of members in a sorted set between a given lexicographical range

    7

    Returns a range of members in a sorted set, by index

    8

    Returns a range of members in a sorted set, by lexicographical range

    9

    Returns a range of members in a sorted set, by score

    10

    Determines the index of a member in a sorted set

    11

    Removes one or more members from a sorted set

    12

    Removes all members in a sorted set between the given lexicographical range

    13

    Removes all members in a sorted set within the given indexes

    14

    Removes all members in a sorted set within the given scores

    15

    Returns a range of members in a sorted set, by index, with scores ordered from high to low

    16

    Returns a range of members in a sorted set, by score, with scores ordered from high to low

    17

    Determines the index of a member in a sorted set, with scores ordered from high to low

    18

    Gets the score associated with the given member in a sorted set

    19

    Adds multiple sorted sets and stores the resulting sorted set in a new key

    20

    Incrementally iterates sorted sets elements and associated scores


    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 – Sets nhận dự án làm có lương

    Redis – Sets



    Redis Sets are an unordered collection of unique strings. Unique means sets does not allow repetition of data in a key.

    In Redis set add, remove, and test for the existence of members in O(1) (constant time regardless of the number of elements contained inside the Set). The maximum length of a list is 232 – 1 elements (4294967295, more than 4 billion of elements per set).

    Example

    redis 127.0.0.1:6379> SADD tutorials redis
    (integer) 1
    redis 127.0.0.1:6379> SADD tutorials mongodb
    (integer) 1
    redis 127.0.0.1:6379> SADD tutorials mysql
    (integer) 1
    redis 127.0.0.1:6379> SADD tutorials mysql
    (integer) 0
    redis 127.0.0.1:6379> SMEMBERS tutorials
    1) "mysql"
    2) "mongodb"
    3) "redis"
    

    In the above example, three values are inserted in Redis set named ‘tutorials’ by the command SADD.

    Redis Sets Commands

    Following table lists some basic commands related to sets.

    Sr.No Command & Description
    1

    Adds one or more members to a set

    2

    Gets the number of members in a set

    3

    Subtracts multiple sets

    4

    Subtracts multiple sets and stores the resulting set in a key

    5

    Intersects multiple sets

    6

    Intersects multiple sets and stores the resulting set in a key

    7

    Determines if a given value is a member of a set

    8

    Gets all the members in a set

    9

    Moves a member from one set to another

    10

    Removes and returns a random member from a set

    11

    Gets one or multiple random members from a set

    12

    Removes one or more members from a set

    13

    Adds multiple sets

    14

    Adds multiple sets and stores the resulting set in a key

    15

    Incrementally iterates set elements


    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 – HyperLogLog nhận dự án làm có lương

    Redis – HyperLogLog



    Redis HyperLogLog is an algorithm that uses randomization in order to provide an approximation of the number of unique elements in a set using just a constant, and small amount of memory.

    HyperLogLog provides a very good approximation of the cardinality of a set even using a very small amount of memory around 12 kbytes per key with a standard error of 0.81%. There is no limit to the number of items you can count, unless you approach 264 items.

    Example

    Following example explains how Redis HyperLogLog works.

    redis 127.0.0.1:6379> PFADD tutorials "redis"
    1) (integer) 1
    redis 127.0.0.1:6379> PFADD tutorials "mongodb"
    1) (integer) 1
    redis 127.0.0.1:6379> PFADD tutorials "mysql"
    1) (integer) 1
    redis 127.0.0.1:6379> PFCOUNT tutorials
    (integer) 3
    

    Redis HyperLogLog Commands

    Following table lists some basic commands related to Redis HyperLogLog.

    Sr.No Command & Description
    1

    Adds the specified elements to the specified HyperLogLog.

    2

    Returns the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).

    3

    Merges N different HyperLogLogs into a single one.


    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

  • 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 – 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 – Environment nhận dự án làm có lương

    Redis – Environment



    In this chapter, you will learn about the environmental setup for Redis.

    Install Redis on Ubuntu

    To install Redis on Ubuntu, go to the terminal and type the following commands −

    $sudo apt-get update
    $sudo apt-get install redis-server
    

    This will install Redis on your machine.

    Start Redis

    $redis-server
    

    Check If Redis is Working

    $redis-cli
    

    This will open a redis prompt.

    redis 127.0.0.1:6379>
    

    In the above prompt, 127.0.0.1 is your machine”s IP address and 6379 is the port on which Redis server is running. Now type the following PING command.

    redis 127.0.0.1:6379> ping
    PONG
    

    This shows that Redis is successfully installed on your machine.

    Install Redis Desktop Manager on Ubuntu

    To install Redis desktop manager on Ubuntu, just download the package from

    Open the downloaded package and install it.

    Redis desktop manager will give you UI to manage your Redis keys and data.


    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