Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis: Is it possible to get just one value of a Set by its key?

Tags:

redis

I have a Set named 'Projects' with many key-value pairs and I want to retrieve one of the values by providing its key. I checked the redis doc but I only found how to retrieve the entire Set. Is it possible to just retrieve one value by providing its key?

like image 457
Nerian Avatar asked May 16 '11 14:05

Nerian


People also ask

Can Redis key have multiple values?

Redis Lists In Redis you can also have lists as the value, which overcomes the problem of having more than one value for a key, as you can have an ordered list with multiple values (so “they'll none of 'em be missed”).

Is Redis key value?

redis is an in-memory, key/value store. Think of it as a dictionary with any number of keys, each of which has a value that can be set or retrieved. However, Redis goes beyond a simple key/value store as it is actually a data structures server, supporting different kinds of values.

How can I get sets in Redis?

The Redis “get set” (GETSET) command allows you to set a key to a specified value and return the old value that was stored at the key. The Redis GETSET command is often used in conjunction with the INCR command to handle counting.


1 Answers

Your concept of Set does not match Redis'.

All members of a set in Redis are stored in a single key. Therefore you can't access members individually by a key.

You should use hashes: http://www.redis.io/commands#hash

HSET key field value does what you are looking for.

like image 101
Niloct Avatar answered Sep 22 '22 13:09

Niloct