How do I store a JSON Value, with the rejson module in Redis using phpredis on Laravel

353 Views Asked by At

Normally when I json_encode and set a value in Redis it gets stored as a string. How do I store a value as JSON

I've tried the following :

$redisCon = Redis::connection('default');

$data = $redisCon->executeRaw(['JSON.new', 'someKeyValue', '{"math":0}']);

but the response keep saying false and the data does not get saved.

I've got RedisJSON support on my redis instance, I'm running the redis/redis-stack-server:latest docker container to check this.

1

There are 1 best solutions below

0
Abhishek On

I manged to solve it, I was using the wrong command JSON.NEW, use JSON.SET instead and also put the path with $.

$data = $redisCon->executeRaw(['JSON.set', 'someKeyValue', '$', '{"math":0}']);