Code Monkey home page Code Monkey logo

Comments (5)

mkorkmaz avatar mkorkmaz commented on June 3, 2024 1

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.

vishytk avatar vishytk commented on June 3, 2024 1

got it, I had made mistake in registering the service providers properly.

Thanks for the help.

from redislabs-rejson.

mkorkmaz avatar mkorkmaz commented on June 3, 2024 1

@vishytk I am glad you resolved your issue. Have fun.

from redislabs-rejson.

vishytk avatar vishytk commented on June 3, 2024

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.

vishytk avatar vishytk commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.