Comments (5)
Hi @vishytk
You can add service providers for RedisJson. See the example for phpredis: https://gist.github.com/mkorkmaz/d1a6c5f9fdf021c609acd6486c7deef9. May be i should add this providers to the library, but you can use them directly.
Then you can use RedisJson in your contollers using RedisJsonInterface type hint.
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Redislabs\Module\RedisJson\RedisJsonInterface;
use function response;
class MyController extends Controller
{
public function __invoke(Request $request, RedisJsonInterface $redisJson): JsonResponse
{
$redisJson->set('my-data', '.', ['name'=>'my name', 'age' => 33, 'items' =>['item-1', 'item-2']]);
$data = $redisJson->get('my-data', '$.items');
return response()->json($data);
}
}
from redislabs-rejson.
got it, I had made mistake in registering the service providers properly.
Thanks for the help.
from redislabs-rejson.
@vishytk I am glad you resolved your issue. Have fun.
from redislabs-rejson.
Hi @vishytk
You can add service providers for RedisJson. See the example for phpredis: https://gist.github.com/mkorkmaz/d1a6c5f9fdf021c609acd6486c7deef9. May be i should add this providers to the library, but you can use them directly.
Then you can use RedisJson in your contollers using RedisJsonInterface type hint.
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Redislabs\Module\RedisJson\RedisJsonInterface; use function response; class MyController extends Controller { public function __invoke(Request $request, RedisJsonInterface $redisJson): JsonResponse { $redisJson->set('my-data', '.', ['name'=>'my name', 'age' => 33, 'items' =>['item-1', 'item-2']]); $data = $redisJson->get('my-data', '$.items'); return response()->json($data); } }
I will try this and update.
from redislabs-rejson.
Not working for me. Here's what I have done.
added the two services providers to my code (laravel package) and registered them
In the routes file
Route::get('/slots', function (RedisJsonInterface $redisJson) {
dump($redisJson->get('timeslots'));
});
Test file, RedisTest
<?php
it('tests redis', function () {
$response = $this->actingAs($this->user)
->get("/slots", $this->headers);
dump($response);
});
I am getting exception error:
"Target [Redislabs\Module\RedisJson\RedisJsonInterface] is not instantiable."
from redislabs-rejson.
Related Issues (13)
- Path format must be checked and validated. HOT 3
- Documentation is needed.
- Set is not working HOT 3
- Pull Request on MultipleGet Command Class HOT 1
- Calling mget only works as $reJson->mget(...$keys, ...['.']); HOT 2
- PHP 8 support HOT 1
- json_encode / json_decode should be optional HOT 2
- Set with expire HOT 2
- Add support for RedisJSON 2.0 full JSONPath syntax HOT 1
- MODULE command don't work HOT 4
- Not support OPT_PREFIX ? HOT 2
- RedisJson::createWithPhpRedis() must be an instance of Redis, instance of RedisCluster given HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redislabs-rejson.