We can use below commands in laravel.
$user = Redis::get('user:profile:'.$id);
$values = Redis::lrange('names', 5, 10);
$values = Redis::command('lrange', ['name', 5, 10]);
but can't use memory usage keyname
command with laravel redis facade.
We can use below commands in laravel.
$user = Redis::get('user:profile:'.$id);
$values = Redis::lrange('names', 5, 10);
$values = Redis::command('lrange', ['name', 5, 10]);
but can't use memory usage keyname
command with laravel redis facade.
The command is not defined for that, but you can use eval:
Redis::connection('connection')->eval("return redis.call('memory', 'usage', 'keyname')", 0)
Or if you want to use the keyname as a paramater:
Redis::connection('connection')->eval("return redis.call('memory', 'usage', KEYS[1])", 1, 'keyname');
Redis LUA scripts are executed the same way in laravel
Short answer no you can't execute. Let me explain;
public function createCommand($commandID, array $arguments = array())
{
$commandID = strtoupper($commandID);
if (!isset($this->commands[$commandID])) {
throw new ClientException("Command '$commandID' is not a registered Redis command.");
}
$commandClass = $this->commands[$commandID];
$command = new $commandClass();
$command->setArguments($arguments);
if (isset($this->processor)) {
$this->processor->process($command);
}
return $command;
}
this method is used when you invoke methods and it uses this abstract method to decide whether you can invoke a method or not.
abstract protected function getSupportedCommands();
getSupportedCommands
method looks like this;
public function getSupportedCommands()
{
return array(
/* ---------------- Redis 1.2 ---------------- */
/* commands operating on the key space */
'EXISTS' => 'Predis\Command\KeyExists',
'DEL' => 'Predis\Command\KeyDelete',
'TYPE' => 'Predis\Command\KeyType',
'KEYS' => 'Predis\Command\KeyKeys',
'RANDOMKEY' => 'Predis\Command\KeyRandom',
'RENAME' => 'Predis\Command\KeyRename',
'RENAMENX' => 'Predis\Command\KeyRenamePreserve',
'EXPIRE' => 'Predis\Command\KeyExpire',
'EXPIREAT' => 'Predis\Command\KeyExpireAt',
'TTL' => 'Predis\Command\KeyTimeToLive',
'MOVE' => 'Predis\Command\KeyMove',
'SORT' => 'Predis\Command\KeySort',
'DUMP' => 'Predis\Command\KeyDump',
'RESTORE' => 'Predis\Command\KeyRestore',
....
...
..
memory usage
command is not available in this method. You may check /vendor/predis/predis/src/Profile/RedisVersion300.php
or any other class in Profile
folder - it is not defined in there.
The reason is memory usage
method is available since Redis version 4.0.0
. This package is supporting commands until Redis version 3.0.0
as it can be seen from class names such as RedisVersion240
, RedisVersion300
etc.