Bas Bas - 1 month ago 7x
JSON Question

How can I update or delete a record from the JSON output using Laravel and Predis

I started a few months ago with Laravel and I want to implement Redis.

How and what is the best way to update or delete 1 or more records from


$allarticles = Article::all();
$client = Redis::connection();
$client->set('articles', $allarticles->toJson() );
$test = $client->set('articles');




$allarticles = Article::all()->keyBy('id'); $client = Redis::connection();
$newarray = array();
foreach ( $allarticles->toArray() as $key => $value ){
$newarray[$key] = json_encode($value); } $client->hmset('testtest', $newarray);
$qwerty = $client->HGETALL('testtest');


Instead of storing the whole json as a string, store them in a hashmap using hmset command, id is the member and rest of the json is the value.

To set the json:

hmset articles 1 {"title":"xQeMKGefAW","content":"","created_at":null,"updated_at":null} 2 {"title":"xQeMKGefAW","content":"","created_at":null,"updated_at":null} and so on

To retrieve the whole json:

hgetall articles

To update one or more values use HMSET

To delete one or more values use HDEL

Hope this helps.