When using Redis in order to create a "record" you can create a hash with several fields. For example:
HMSET myhash field1 "Hello" field2 "World"
HMSET myhash2 field1 "Goodbye" field2 "World"
You can retrieve this by knowing the key values, however what I want to know is there any way to retrieve all hashes that have "World" in field2?
Redis HSET command is used to set field in the hash stored at the key to value. If the key does not exist, a new key holding a hash is created. If the field already exists in the hash, it is overwritten.
A Redis hash is a data type that represents a mapping between a string field and a string value. Hashes can hold many field-value pairs and are designed to not take up much space, making them ideal for representing data objects.
It is implemented as a Hash table and handles collisions by Chaining. A Redis Hash can store up to 4 billion key value pairs. If the value is Integer, Redis hash allows you to atomically increment or decrement the value.
NO, Redis hash doesn't maintain the order. Since it's a hash, it's unordered.
There are no indexes in redis, and it doesn't implement SQL. It's a key-value store. You provide a key, it gets you a value.
That said, you can implement this by maintaining secondary indexes yourself. For example:
create a record and an index entry
HMSET myhash field1 Hello field2 World
SADD field2_world myhash
update a record, delete old index entry, create new one
SREM field2_world myhash
HMSET myhash field2 Mundo
SADD field2_mundo myhash
find all records which have "World" in field2
SMEMBERS field2_world
I hope you get the idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With