Redis Command: MGET

Summary

Command NameMGET
UsageRetrieve multiple string value
Group string
ACL Category@read
@string
@fast
Time ComplexityO(N)
FlagREADONLY
FAST
Arity-2

Signature

MGET <key> [<key>…]

Usage

Get the string values of multiple keys. As we can pass multiple keys and get the values, so it is a very handy command when we work with lots of keys.

Notes

  • This operation always returns values without fail, as for the non-existing keys it returns nil.

Arguments

Here is the description of what each part of the MGET command means in the above signature-

ParameterDescriptionNameType
<key> [ <key> … ]List of multiple keyskeykey

Return Value

List of values is returned for the provided keys.

Return valueCase for the return valueType
DataList of string values(or nil) for the provided keysarray (of string or null)

Notes

  • If any of the keys does not exist then “nil” is returned for that key.
  • Values are returned in the same sequence as the keys provided.
  • If the same key is provided multiple times the value is returned multiple times.

Examples

Here are a few examples of the MGET command usage-

# Set some values
127.0.0.1:6379> set firstkey "my first value"
OK

127.0.0.1:6379> set secondkey "bigboxcode"
OK

127.0.0.1:6379> set user:100 "john"
OK

# Try to get values for 3 keys
127.0.0.1:6379> mget firstkey secondkey user:100
1) "my first value"
2) "bigboxcode"
3) "john"

# We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
127.0.0.1:6379> mget firstkey secondkey wrongkey
1) "my first value"
2) "bigboxcode"
3) (nil)

# Here we are provideing "firstkey" multiple times
127.0.0.1:6379> mget firstkey firstkey secondkey wrongkey user:100 firstkey
1) "my first value"
2) "my first value"
3) "bigboxcode"
4) (nil)
5) "john"
6) "my first value"

Notes

  • Values are returned in the same sequence, of the provided keys.
  • If a non-existing key is there in the provided key list, then a nil value is returned for that key. All the key values are returned as it is.
  • If the same is provided multiple times, then the value is returned multiple times.

Code Implementations

Here are the usage examples of the Redis MGET command in different programming languages.

// mget.go

// Redis MGET command example in Golang

package main

import (
	"context"
	"fmt"

	"github.com/redis/go-redis/v9"
)

var rdb *redis.Client
var ctx context.Context
var colorRed = "33[31m"
var styleReset = "33[0m"

func init() {
	rdb = redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Username: "default",
		Password: "",
		DB:       0,
	})

	ctx = context.Background()
}

func main() {

	// Set some values
	// Command: set firstkey "my first value"
	// Result: OK
	commandResult, err := rdb.Set(ctx, "firstkey", "my first value", 0).Result()

	if err != nil {
		fmt.Println(colorRed + "Can not set firstkey" + err.Error() + styleReset)
	}

	fmt.Println("Set value of 'firstkey' to 'some value' - Result: " + commandResult)

	// Command: set secondkey "bigboxcode"
	// Result: OK
	commandResult, err = rdb.Set(ctx, "secondkey", "bigboxcode", 0).Result()

	if err != nil {
		fmt.Println(colorRed + "Can not set secondkey - Error: " + err.Error() + styleReset)
	}

	fmt.Println("Set value of 'secondkey' to 'bigboxcode' - Result: " + commandResult)

	// Command: set user:100 "john"
	// Result: OK
	commandResult, err = rdb.Set(ctx, "user:100", "john", 0).Result()

	if err != nil {
		fmt.Println(colorRed + "Can not set user:100" + err.Error() + styleReset)
	}

	fmt.Println("Set value of 'user:100' to 'john' - Result: " + commandResult)

	// Try to get values for 3 keys
	// Command: mget firstkey secondkey user:100
	// Result:
	// 1) "my first value"
	// 2) "bigboxcode"
	// 3) "john"
	commandResults, err := rdb.MGet(ctx, "firstkey", "secondkey", "user:100").Result()

	if err != nil {
		fmt.Println(colorRed + "mget firstkey secondkey user:100 - Failed. Error: " + err.Error() + styleReset)
	}

	fmt.Println("Command: mget firstkey secondkey user:100 - Result:")

	for _, val := range commandResults {
		fmt.Println(val)
	}

	// We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
	// Command: mget firstkey secondkey wrongkey
	// Result:
	// 1) "my first value"
	// 2) "bigboxcode"
	// 3) (nil)
	commandResults, err = rdb.MGet(ctx, "firstkey", "secondkey", "wrongkey").Result()

	if err != nil {
		fmt.Println(colorRed + "mget firstkey secondkey wrongkey - Failed. Error: " + err.Error() + styleReset)
	}

	fmt.Println("Command: mget firstkey secondkey wrongkey - Result:")

	for _, val := range commandResults {
		fmt.Println(val)
	}

	// Here we are provideing "firstkey" multiple times
	// Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
	// Result:
	// 1) "my first value"
	// 2) "my first value"
	// 3) "bigboxcode"
	// 4) (nil)
	// 5) "john"
	// 6) "my first value"
	commandResults, err = rdb.MGet(ctx, "firstkey", "firstkey", "wrongkey", "user:100", "firstkey").Result()

	if err != nil {
		fmt.Println(colorRed + "mget firstkey firstkey secondkey wrongkey user:100 firstkey - Failed. Error: " + err.Error() + styleReset)
	}

	fmt.Println("Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey - Result:")

	for _, val := range commandResults {
		fmt.Println(val)
	}
}

Output:

Set value of 'firstkey' to 'some value' - Result: OK
Set value of 'secondkey' to 'bigboxcode' - Result: OK
Set value of 'user:100' to 'john' - Result: OK

Command: mget firstkey secondkey user:100 - Result:
my first value
bigboxcode
john

Command: mget firstkey secondkey wrongkey - Result:
my first value
bigboxcode
<nil>

Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey - Result:
my first value
my first value
<nil>
john
my first value

Notes

  • The method for implementing the MGET command is “MGet“. We have to pass the key names as separate parameters of the method.
  • By calling the “Result()” on the “MGget” method we will get the values as an array.
// mget.js

// Redis MGET command example in JavaScript(NodeJS)

import { createClient } from 'redis';

// Create redis client
const redisClient = createClient({
    url: 'redis://default:@localhost:6379'
});

redisClient.on('error', err => console.log('Error while connecting to Redis', err));

// Connect Redis client
await redisClient.connect();


/**
 * Set some values
 * 
 * Command: set firstkey "my first value"
 * Result: OK
 */
let commandResult = await redisClient.SET('firstkey', 'my first value');

console.log(`key: 'firstkey', value: 'my first value' - set result: ${commandResult}`);


/**
 * Command: set secondkey "bigboxcode"
 * Result: OK
 */
commandResult = await redisClient.SET('secondkey', 'bigboxcode');

console.log(`key: 'secondkey', value: 'bigboxcode' - set result: ${commandResult}`);


/**
 * Command: set user:100 "john"
 * Result: OK
 */
commandResult = await redisClient.SET('user:100', 'john');

console.log(`key: 'user:100', value: 'john' - set result: ${commandResult}`);


/**
 * Try to get values for 3 keys
 * 
 * Command: mget firstkey secondkey user:100
 * Result:
 *  1) "my first value"
 *  2) "bigboxcode"
 *  3) "john"
 */
commandResult = await redisClient.MGET(['firstkey', 'secondkey', 'user:100']);

console.log(`Command: mget firstkey secondkey user:100 - result:`, commandResult);


/**
 * We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
 * 
 * Command: mget firstkey secondkey wrongkey
 * Result:
 *  1) "my first value"
 *  2) "bigboxcode"
 *  3) (nil)
 */
commandResult = await redisClient.MGET(['firstkey', 'secondkey', 'wrongkey']);

console.log(`Command: mget firstkey secondkey wrongkey - result:`, commandResult);


/**
 * Here we are provideing "firstkey" multiple times
 * 
 * Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
 * Result:
 *  1) "my first value"
 *  2) "my first value"
 *  3) "bigboxcode"
 *  4) (nil)
 *  5) "john"
 *  6) "my first value"
 */
commandResult = await redisClient.MGET(['firstkey', 'firstkey', 'secondkey', 'wrongkey', 'user:100', 'firstkey']);

console.log(`Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey - result:`, commandResult);


process.exit(0);

Output:

key: 'firstkey', value: 'my first value' - set result: OK

key: 'secondkey', value: 'bigboxcode' - set result: OK

key: 'user:100', value: 'john' - set result: OK

Command: mget firstkey secondkey user:100 - result: [ 'my first value', 'bigboxcode', 'john' ]

Command: mget firstkey secondkey wrongkey - result: [ 'my first value', 'bigboxcode', null ]

Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey - result: [
  'my first value',
  'my first value',
  'bigboxcode',
  null,
  'john',
  'my first value'
]

Notes

  • Call the method MGET (or mGet) for executing the Redis MGET command.
  • We can pass the list of key names to the MGET method as an array.
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;

import java.util.List;

public class Mget {
    public static void main(String[] args) {
        // Create connection pool
        JedisPool jedisPool = new JedisPool("localhost", 6379);

        try (Jedis jedis = jedisPool.getResource()) {
            /**
             * Set some values
             *
             * Command: set firstkey "my first value"
             * Result: OK
             */
            String commandResult = jedis.set("firstkey", "my first value");

            System.out.println("Command: set firstkey "my first value" | Result: " + commandResult);


            /**
             * Command: set secondkey "bigboxcode"
             * Result: OK
             */
            commandResult = jedis.set("secondkey", "bigboxcode");

            System.out.println("Command: set secondkey "bigboxcode" | Result: " + commandResult);


            /**
             * Command: set user:100 "john"
             * Result: OK
             */
            commandResult = jedis.set("user:100", "john");

            System.out.println("Command: set user:100 "john" | Result: " + commandResult);


            /**
             * Try to get values for 3 keys
             *
             * Command: mget firstkey secondkey user:100
             * Result:
             *  1) "my first value"
             *  2) "bigboxcode"
             *  3) "john"
             */
            List<String> resultList = jedis.mget("firstkey", "secondkey", "user:100");

            System.out.println("Command: mget firstkey secondkey user:100 | Result: ");

            for (String item: resultList) {
                System.out.println(item);
            }


            /**
             * We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
             *
             * Command: mget firstkey secondkey wrongkey
             * Result:
             *  1) "my first value"
             *  2) "bigboxcode"
             *  3) (nil)
             */
            resultList = jedis.mget("firstkey", "secondkey", "wrongkey");

            System.out.println("Command: mget firstkey secondkey wrongkey | Result: ");

            for (String item: resultList) {
                System.out.println(item);
            }


            /**
             * Here we are provideing "firstkey" multiple times
             *
             * Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
             * Result:
             *  1) "my first value"
             *  2) "my first value"
             *  3) "bigboxcode"
             *  4) (nil)
             *  5) "john"
             *  6) "my first value"
             */
            resultList = jedis.mget("firstkey", "firstkey", "secondkey", "wrongkey", "user:100", "firstkey");

            System.out.println("Command: mget firstkey firstkey secondkey wrongkey user:100 firstkeymget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: ");

            for (String item: resultList) {
                System.out.println(item);
            }

        }

        jedisPool.close();
    }
}

Output:

Command: set firstkey "my first value" | Result: OK
Command: set secondkey "bigboxcode" | Result: OK
Command: set user:100 "john" | Result: OK

Command: mget firstkey secondkey user:100 | Result: 
my first value
bigboxcode
john

Command: mget firstkey secondkey wrongkey | Result: 
my first value
bigboxcode
null

Command: mget firstkey firstkey secondkey wrongkey user:100 firstkeymget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: 
my first value
my first value
bigboxcode
null
john
my first value

Notes

  • From Jedis package we have to use the method “mget” for using the Redis MGET command.
  • Signature of the “mget” method is public List<String> mget(final String… keys).
  • Pass the list of key names to the “mget” method as comma-separated params.
  • This method returns a List of strings.
// Redis MGET command examples in C#

using StackExchange.Redis;

namespace Mget
{
    internal class Program
    {
        static void Main(string[] args)
        {

            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
            IDatabase rdb = redis.GetDatabase();


            /**
             * Set some values
             *
             * Command: set firstkey "my first value"
             * Result: OK
             */
            var setCommandResult = rdb.StringSet("firstkey", "my first value");

            Console.WriteLine("Command: set firstkey "my first value" | Result: " + setCommandResult);


            /**
             * Command: set secondkey "bigboxcode"
             * Result: OK
             */
            setCommandResult = rdb.StringSet("secondkey", "bigboxcode");

            Console.WriteLine("Command: set secondkey "bigboxcode" | Result: " + setCommandResult);


            /**
             * Command: set user:100 "john"
             * Result: OK
             */
            setCommandResult = rdb.StringSet("user:100", "john");

            Console.WriteLine("Command: set user:100 "john" | Result: " + setCommandResult);


            /**
             * Try to get values for 3 keys
             *
             * Command: mget firstkey secondkey user:100
             * Result:
             *  1) "my first value"
             *  2) "bigboxcode"
             *  3) "john"
             */
            var resultList = rdb.StringGet(new RedisKey[] { "firstkey", "secondkey", "user:100" });

            Console.WriteLine("Command: mget firstkey secondkey user:100 | Result: ");

            foreach (var item in resultList)
            {
                Console.WriteLine(item);
            }


            /**
             * We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
             *
             * Command: mget firstkey secondkey wrongkey
             * Result:
             *  1) "my first value"
             *  2) "bigboxcode"
             *  3) (nil)
             */
            resultList = rdb.StringGet(new RedisKey[] { "firstkey", "secondkey", "wrongkey" });

            Console.WriteLine("Command: mget firstkey secondkey wrongkey | Result: ");

            foreach (var item in resultList)
            {
                Console.WriteLine(item);
            }


            /**
             * Here we are provideing "firstkey" multiple times
             *
             * Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
             * Result:
             *  1) "my first value"
             *  2) "my first value"
             *  3) "bigboxcode"
             *  4) (nil)
             *  5) "john"
             *  6) "my first value"
             */
            resultList = rdb.StringGet(new RedisKey[] { "firstkey", "firstkey", "secondkey", "wrongkey", "user:100", "firstkey" });

            Console.WriteLine("Command: mget firstkey firstkey secondkey wrongkey user:100 firstkeymget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: ");

            foreach (var item in resultList)
            {
                Console.WriteLine(item);
            }

        }
    }
}

Output:

Command: set firstkey "my first value" | Result: True
Command: set secondkey "bigboxcode" | Result: True
Command: set user:100 "john" | Result: True


Command: mget firstkey secondkey user:100 | Result:
my first value
bigboxcode
john


Command: mget firstkey secondkey wrongkey | Result:
my first value
bigboxcode
<empty result here>


Command: mget firstkey firstkey secondkey wrongkey user:100 firstkeymget firstkey firstkey secondkey wrongkey user:100 firstkey | Result:
my first value
my first value
bigboxcode
<empty result here>
john
my first value

Notes

  • We need to use the “StringGet” method from StackExchange.Redis package for using the Redis MGET command.
  • “StringGet” is the same method that we use to get a single string value.
  • For getting multiple values we need to use the following signature of “StringGet” method – RedisValue[] StringGet(RedisKey[] keys, CommandFlags flags = CommandFlags.None).
  • To get multiple values for MGET we need to pass an array of keys like- rdb.StringGet(new RedisKey[] { “firstkey”, “secondkey”, “user:100” }).
<?php
// mget.php

// Redis MGET command example in PHP

require 'vendor/autoload.php';

// Connect to Redis
$redisClient = new PredisClient([
    'scheme' => 'tcp',
    'host' => 'localhost',
    'port' => 6379,
]);


/**
 * Set some values
 * 
 * Command: set firstkey "my first value"
 * Result: OK
 */
$commandResult = $redisClient->set('firstkey', 'my first value');

echo "key: 'firstkey', value: 'my first value' - set result: " . $commandResult . "n";


/**
 * Command: set secondkey "bigboxcode"
 * Result: OK
 */
$commandResult = $redisClient->set('secondkey', 'bigboxcode');

echo "key: 'secondkey', value: 'bigboxcode' - set result: " . $commandResult . "n";


/**
 * Command: set user:100 "john"
 * Result: OK
 */
$commandResult = $redisClient->set('user:100', 'john');

echo "key: 'user:100', value: 'john' - set result: " . $commandResult . "n";


/**
 * Try to get values for 3 keys
 * 
 * Command: mget firstkey secondkey user:100
 * Result:
 *  1) "my first value"
 *  2) "bigboxcode"
 *  3) "john"
 */

$commandResult = $redisClient->mget(['firstkey', 'secondkey', 'user:100']);

echo "Command: mget firstkey secondkey user:100 - result:n";
print_r($commandResult);


/**
 * We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
 * 
 * Command: mget firstkey secondkey wrongkey
 * Result:
 *  1) "my first value"
 *  2) "bigboxcode"
 *  3) (nil)
 */
$commandResult = $redisClient->mget('firstkey', 'secondkey', 'wrongkey');

echo "Command: mget firstkey secondkey wrongkey - result:n";
print_r($commandResult);


/**
 * Here we are provideing "firstkey" multiple times
 * 
 * Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
 * Result:
 *  1) "my first value"
 *  2) "my first value"
 *  3) "bigboxcode"
 *  4) (nil)
 *  5) "john"
 *  6) "my first value"
 */
$commandResult = $redisClient->mget('firstkey', 'firstkey', 'secondkey', 'wrongkey', 'user:100', 'firstkey');

echo "Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey - result:n";
print_r($commandResult);

Output:

key: 'firstkey', value: 'my first value' - set result: OK

key: 'secondkey', value: 'bigboxcode' - set result: OK

key: 'user:100', value: 'john' - set result: OK


Command: mget firstkey secondkey user:100 - result:
Array
(
    [0] => my first value
    [1] => bigboxcode
    [2] => john
)


Command: mget firstkey secondkey wrongkey - result:
Array
(
    [0] => my first value
    [1] => bigboxcode
    [2] =>
)


Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey - result:
Array
(
    [0] => my first value
    [1] => my first value
    [2] => bigboxcode
    [3] =>
    [4] => john
    [5] => my first value
)

Notes

  • To implement the MGET command use the “mget” method from “predis”.
  • Pass the list of key names to the “mget” method as an array, or separate parameters. Both will work.
# mget.py

# Redis GET command example in Python

import redis

# Create Redis client
redisClient = redis.Redis(host='localhost', port=6379, username='default', password='', decode_responses=True)


# Set some values
# Command: set firstkey "my first value"
# Result: OK
commandResult = redisClient.set('firstkey', 'my first value')

print("key: 'firstkey', value: 'my first value' - set result: {}".format(commandResult))


# Command: set secondkey "bigboxcode"
# Result: OK
commandResult = redisClient.set('secondkey', 'bigboxcode')

print("key: 'secondkey', value: 'bigboxcode' - set result: {}".format(commandResult))


# Command: set user:100 "john"
# Result: OK
commandResult = redisClient.set('user:100', 'john')

print("key: 'user:100', value: 'john' - set result: {}".format(commandResult))


# Try to get values for 3 keys
# Command: mget firstkey secondkey user:100
# Result:
# 1) "my first value"
# 2) "bigboxcode"
# 3) "john"
commandResult = redisClient.mget(['firstkey', 'secondkey', 'user:100'])

print("Command: mget firstkey secondkey user:100 | Result: {}".format(commandResult))


# We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
# Command: mget firstkey secondkey wrongkey
# Result:
# 1) "my first value"
# 2) "bigboxcode"
# 3) (nil)
commandResult = redisClient.mget(['firstkey', 'secondkey', 'wrongkey'])

print("Command: mget firstkey secondkey wrongkey | Result: {}".format(commandResult))


# Here we are provideing "firstkey" multiple times
# Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
# Result:
# 1) "my first value"
# 2) "my first value"
# 3) "bigboxcode"
# 4) (nil)
# 5) "john"
# 6) "my first value"
commandResult = redisClient.mget(['firstkey', 'firstkey', 'secondkey', 'wrongkey', 'user:100', 'firstkey'])

print("Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: {}".format(commandResult))

Output:

key: 'firstkey', value: 'my first value' - set result: True

key: 'secondkey', value: 'bigboxcode' - set result: True

key: 'user:100', value: 'john' - set result: True

Command: mget firstkey secondkey user:100 | Result: ['my first value', 'bigboxcode', 'john']

Command: mget firstkey secondkey wrongkey | Result: ['my first value', 'bigboxcode', None]

Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: ['my first value', 'my first value', 'bigboxcode', None, 'john', 'my first value']

Notes

  • Use the “mget” method from the “redis” python library for using the Redis MGET command.
  • Pass the list of key names to the “mget” method as a list.
# Redis MGET command example in Ruby

require 'redis'

redis = Redis.new(host: "localhost", port: 6379)


# Set some values
# Command: set firstkey "my first value"
# Result: OK
commandResult = redis.set('firstkey', 'my first value')

print("key: 'firstkey', value: 'my first value' - set result: ", commandResult, "n")


# Command: set secondkey "bigboxcode"
# Result: OK
commandResult = redis.set('secondkey', 'bigboxcode')

print("key: 'secondkey', value: 'bigboxcode' - set result: ", commandResult, "n")


# Command: set user:100 "john"
# Result: OK
commandResult = redis.set('user:100', 'john')

print("key: 'user:100', value: 'john' - set result: ", commandResult, "n")


# Try to get values for 3 keys
# Command: mget firstkey secondkey user:100
# Result:
# 1) "my first value"
# 2) "bigboxcode"
# 3) "john"
commandResult = redis.mget('firstkey', 'secondkey', 'user:100')

print("Command: mget firstkey secondkey user:100 | Result: ", commandResult, "n")


# We get "nil" if the key deos not exist. Here the "wrongkey" does not exist
# Command: mget firstkey secondkey wrongkey
# Result:
# 1) "my first value"
# 2) "bigboxcode"
# 3) (nil)
commandResult = redis.mget('firstkey', 'secondkey', 'wrongkey')

print("Command: mget firstkey secondkey wrongkey | Result: ", commandResult, "n")


# Here we are provideing "firstkey" multiple times
# Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey
# Result:
# 1) "my first value"
# 2) "my first value"
# 3) "bigboxcode"
# 4) (nil)
# 5) "john"
# 6) "my first value"
commandResult = redis.mapped_mget('firstkey', 'firstkey', 'secondkey', 'wrongkey', 'user:100', 'firstkey')

print("Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: ", commandResult, "n")

Output:

Command: mget firstkey secondkey user:100 | Result: 
[
    "my first value", 
    "bigboxcode", 
    "john"
]


Command: mget firstkey secondkey wrongkey | Result: 
[
    "my first value", 
    "bigboxcode", 
    nil
]


Command: mget firstkey firstkey secondkey wrongkey user:100 firstkey | Result: 
{
    "firstkey"=>"my first value", 
    "secondkey"=>"bigboxcode", 
    "wrongkey"=>nil, 
    "user:100"=>"john"
}

Notes

  • Use the “mget” method from “redis-rb” package for getting the values of multiple key values at the same time. Signagure of the method is – def mget(*keys, &blk) . We can use it like – mget(“firstkey”, “secondkey” “thirdkey”).
  • Another method we can use is “mapped_mget“, which returns the result as a key/value map. this method has a similar signature as mget – def mapped_mget(*keys).

Source Code

Use the following links to get the source code used in this article-

Related Commands

CommandDetails
GET Command Details
GETEX Command Details
GETDEL Command Details
MSET Command Details

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.