hmset redis with result from mysqlDB

201 Views Asked by At

Im very new to Redis, and after have seeing the redis FAQ i have a question regarding hmset.

It seems like hmset is the best way for me to store user rows from my mysql DB. So if i had an array returned from mysql like this:

        array(
'userid' => 1,
    'username' => 'test',
    'password' => 'example2222',
    'health' => 120
    );

how could i easily insert this to the redis hmset or make an funciton that would take the result and make a hmset from the array?

etg:

user:1 username test password example2222 health 120

I was thinking something like.

If userid not exist in redis -> get the row from MYsqlDB and do redis hmset with the result.

1

There are 1 best solutions below

6
On BEST ANSWER

I'm using Predis to store your array, code tested

    $data = array(
        'userid' => 1,
        'username' => 'test',
        'password' => 'example2222',
        'health' => 120
    );

    Predis::instance()->hmset('uid-' . $data['userid'], $data);
    die();

enter image description here