HVALS

HVALS key
Available since:
Redis Open Source 2.0.0
Time complexity:
O(N) where N is the size of the hash.
ACL categories:
@read, @hash, @slow,
Compatibility:
Redis Software and Redis Cloud compatibility

Returns all values in the hash stored at key.

Required arguments

key

The name of the key that holds the hash.

Examples

Foundational: Retrieve all values from a hash using HVALS (returns only values without field names, useful when you only need the data)
HSET myhash field1 "Hello" HSET myhash field2 "World" HVALS myhash
res10 = r.hset("myhash", mapping={"field1": "Hello", "field2": "World"})

res11 = r.hvals("myhash")
print(res11) # >>> [ "Hello", "World" ]

const res12 = await client.hSet(
  'myhash',
  {
    'field1': 'Hello',
    'field2': 'World'
  }
)

const res13 = await client.hVals('myhash')
console.log(res13) // [ 'Hello', 'World' ]

        Map<String, String> hValsExampleParams = new HashMap<>();
        hValsExampleParams.put("field1", "Hello");
        hValsExampleParams.put("field2", "World");

        long hValsResult1 = jedis.hset("myhash", hValsExampleParams);
        System.out.println(hValsResult1); // >>> 2

        List<String> hValsResult2 = jedis.hvals("myhash");
        Collections.sort(hValsResult2);
        System.out.println(hValsResult2);
        // >>> [Hello, World]
            Map<String, String> hValsFields = new HashMap<>();
            hValsFields.put("field1", "Hello");
            hValsFields.put("field2", "World");

            syncCommands.hset("myhash", hValsFields);

            // The order of the values isn't guaranteed, so sort them before
            // printing.
            List<String> res15 = syncCommands.hvals("myhash");
            List<String> sortedValues = new ArrayList<>(res15);
            Collections.sort(sortedValues);
            System.out.println(sortedValues); // >>> [Hello, World]
            Map<String, String> hValsExampleParams = new HashMap<>();
            hValsExampleParams.put("field1", "Hello");
            hValsExampleParams.put("field2", "World");

            CompletableFuture<Void> hValsExample = asyncCommands.hset("myhash", hValsExampleParams).thenCompose(res1 -> {
                return asyncCommands.hvals("myhash");
            }).thenAccept(res2 -> {
                List<String> sortedValues = new ArrayList<>(res2);
                Collections.sort(sortedValues);
                System.out.println(sortedValues);
                // >>> [Hello, World]
            }).toCompletableFuture();
            Map<String, String> hValsExampleParams = new HashMap<>();
            hValsExampleParams.put("field1", "Hello");
            hValsExampleParams.put("field2", "World");

            Mono<Long> hValsExample1 = reactiveCommands.hset("myhash", hValsExampleParams).doOnNext(result -> {
            });

            hValsExample1.block();

            Mono<List<String>> hValsExample2 = reactiveCommands.hvals("myhash").collectList().doOnNext(result -> {
                List<String> sortedValues = new ArrayList<>(result);
                Collections.sort(sortedValues);
                System.out.println(sortedValues);
                // >>> [Hello, World]
            });
	hValsResult1, err := rdb.HSet(ctx, "myhash",
		"field1", "Hello",
		"field2", "World",
	).Result()

	if err != nil {
		panic(err)
	}

	fmt.Println(hValsResult1) // >>> 2

	hValsResult2, err := rdb.HVals(ctx, "myhash").Result()

	if err != nil {
		panic(err)
	}

	sort.Strings(hValsResult2)

	fmt.Println(hValsResult2) // >>> [Hello World]
        db.HashSet("myhash",
            [
                new("field1", "Hello"),
                new("field2", "World")
            ]
        );

        RedisValue[] hValsResult = db.HashValues("myhash");
        Array.Sort(hValsResult);
        Console.WriteLine(string.Join(", ", hValsResult));
        // >>> Hello, World

        $hValsResult1 = $this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']);
        echo "HMSET myhash field1 Hello field2 World: " . ($hValsResult1 ? 'OK' : 'FAIL') . "\n"; // >>> OK

        $hValsResult2 = $this->redis->hvals('myhash');
        echo "HVALS myhash: " . json_encode($hValsResult2) . "\n"; // >>> ["Hello","World"]
r.hset('myhash', { 'field1' => 'Hello', 'field2' => 'World' })

res15 = r.hvals('myhash')
puts res15.inspect # >>> ["Hello", "World"]
        let hash_fields = [
            ("field1", "Hello"),
            ("field2", "World"),
        ];

        if let Ok(_) = r.hset_multiple::<&str, &str, &str, String>("myhash", &hash_fields) {
            // Fields set successfully
        }

        match r.hvals("myhash") {
            Ok(res11) => {
                let res11: Vec<String> = res11;
                println!("{res11:?}");    // >>> ["Hello", "World"]
            },
            Err(e) => {
                println!("Error getting hash values: {e}");
                return;
            }
        }

        let hash_fields = [
            ("field1", "Hello"),
            ("field2", "World"),
        ];

        if let Ok(_) = r.hset_multiple::<&str, &str, &str, String>("myhash", &hash_fields).await {
            // Fields set successfully
        }

        match r.hvals("myhash").await {
            Ok(res11) => {
                let res11: Vec<String> = res11;
                println!("{res11:?}");    // >>> ["Hello", "World"]
            },
            Err(e) => {
                println!("Error getting hash values: {e}");
                return;
            }
        }

Redis Software and Redis Cloud compatibility

Redis
Software
Redis
Cloud
Notes
✅ Standard
✅ Active-Active
✅ Standard
✅ Active-Active

Return information

Array reply: a list of values in the hash, or an empty list when the key does not exist
RATE THIS PAGE
Back to top ↑