Answer the question
In order to leave comments, you need to log in
How to properly pull data in redis?
Hello.
who knows how to properly pull data into nosql redis.
So
I create a user key in it with a guid value that contains an array.
$this->hmset('users', Guid::getGuid(),
json_encode([
'name' => 'username',
'email' => 'useremail',
'password' => password_hash('userpassword', PASSWORD_DEFAULT)
])
);
$data = $this->hgetall('users');//Получаем все данные из ключа 'users'
foreach ($data as $key => $value) {
if(json_decode($value, true)['name']=='username'){//Проверяем на совпадение
print_r('Пользователь найден');
}
}
Answer the question
In order to leave comments, you need to log in
So, it's a little unclear (in fact, a lot of it is unclear), what is going on?
As a result, a key (?) users is created (not user at all), judging by the code. Though it is necessary to guess that there in general occurs in function.
I don’t know something, or the key-value assumes that by the name of user I will get 1 value (in this case, a jsencode string?), who is the "guid value"? what does the stored record look like in the end? Or do you have many?
It's a good idea to stick to the schema when constructing keys: "object-type:id:field". With it, your selection, firstly, will be fast, and secondly, it will not require sampling and parsing of EACH user, it is enough to know the id or name, for example.
You chose not the best option data type (hash) in essence, you make only one key / value pair. But, radish makes it possible to partially update it. I think it will be much easier to use the string type and write the keys
set('users:guid', JSON), that is, the key will be the string users + ":" + Guid::getGuid(), and the value is your json
get('users:guid '), respectively, to read the value.
full list of commands here
https://redis.io/commands/#string
ps your hash
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question