CM.
CM.

Reputation: 680

Update/append redis values

I have recently started using redis. Currently it's simple key value storage. For example:

$this->redis->set('GET_ALL_DEVICES', json_encode($data)); 

Now if there is new entry into device table, I want to append new entry into same cached data I have. Don't want to flush cached object and create new one to reflect new entry. Is there any way to do this in redis?

Upvotes: 0

Views: 2270

Answers (1)

Pascal Le Merrer
Pascal Le Merrer

Reputation: 5981

There is no table in Redis. You must learn what Redis specific data types are.

In this case, a SET could be the right structure to be used, if you don't need the data to be ordered. So you should perform a SADD (adds a value to SET) instead of a SET instruction, which sets the value for a single string.

$this->redis->sadd('GET_ALL_DEVICES', json_encode($data));

According to your use case, a LIST or a SORTED set may be more appropriate than a SET to store your data.

Upvotes: 1

Related Questions