Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can I instantiate Redis in CallbackqueryCommand.php... #61

Closed
XiaomiYe opened this issue Sep 16, 2022 · 6 comments
Closed

can I instantiate Redis in CallbackqueryCommand.php... #61

XiaomiYe opened this issue Sep 16, 2022 · 6 comments

Comments

@XiaomiYe
Copy link

I instantiate Redis in CallbackqueryCommand and want to write the data of CallbackqueryCommand into the list. But I don't know what went wrong

@noplanman
Copy link
Member

@XiaomiYe Please add some code and more context, otherwise nobody can help 😊

@XiaomiYe
Copy link
Author

XiaomiYe commented Sep 19, 2022

@noplanman

CallbackqueryCommand.php

    /**
     * Main command execution
     * @return ServerResponse
     * @throws \Exception
     */
    public function execute(): ServerResponse
    {
        $callback_query = $this->getCallbackQuery();
        $callback_data  = $callback_query->getData();
        $data['inline_message_id']    = $callback_query->getId();
        //$callback_query->getInlineMessageId();
        $data['keywords']    = $callback_data;
        TelegramLog::debug(json_encode($data));
        $redisobj = new Redis();
        TelegramLog::debug("instantiate Redis");
        try {
        	$connect = $redisobj->pconnect('127.0.0.1', 6379);
            TelegramLog::debug(json_encode($connect));
        } catch (Exception $e) {
            TelegramLog::error(json_encode($e->getMessage()));
        }
        $redisobj->lpush('bot-list', $data);
        return Request::emptyResponse();
    }

@noplanman
Copy link
Member

noplanman commented Sep 19, 2022

In your redis-cli you can use the monitor command if the value comes through properly:

$ redis-cli 
127.0.0.1:6379> monitor
OK
1663558774.728972 [0 127.0.0.1:37318] "LPUSH" "bot-list" "Array"

Your code should work, but you could try this:

  • ->connect instead of ->pconnect
  • ->lPush instead of ->lpush
  • log the redis response
$redisobj = new Redis();
TelegramLog::debug('instantiate Redis');
try {
    $connect = $redisobj->connect('127.0.0.1', 6379);
    TelegramLog::debug($connect);

    $result = $redisobj->lPush('bot-list', $data);
    TelegramLog::debug($result);
} catch (Exception $e) {
    TelegramLog::error($e->getMessage());
}

@XiaomiYe
Copy link
Author

Thank you. I have found the problem and solved it

@noplanman
Copy link
Member

Feel free to share the problem and your solution, so others (and me!) can learn, thanks 😃

@XiaomiYe
Copy link
Author

just Replace with $redisobj=new \Redis();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants