Closed mugennsou closed 4 years ago
I struggled with the same, and I've come up with this little hack that seems to do the trick.
Add a DocBlock to the abstract class Illuminate\Redis\Connections\Connection:
/**
* @mixin \Predis\Client
*/
abstract class Connection
Rebuild the ide_helper file with$ php artisan ide-helper:generate
Now if you resolve a client instance with Redis::resolve()
PhpStorm will be able to autocomplete the methods.
@mortenscheel that seems too tricky, so I gonna need to edit vendor files to make ide-helper works :(
Any solution for this?
I DON'T THINK laravel-ide-helper
, this version, can autocomplete Redis
commands like Redis::set()
.
As a result, all commands such as get
,get
are php-docs in Predis\ClientInterface
There are some approaches:
Redis::set()
and disable IDE inspection warning for "Non-static method 'set' should not be called statically.Redis::connection()->set()
app('redis')->set()
redis()
which return Redis::connection()
, now you can use redis()->set()
_ide_helper_redis.php
and add all methods for commands of redis.Last option seems best as we don't have to change code in project. But it also much more works :( Could you write down some simple that the file 'd look like so I could follow ?
I just write a _ide_helper_redis.php
like @lokielse said, and change all function to static. It works :)
<?php
namespace Illuminate\Support\Facades;
class Redis
{
public static function psetex( ) {}
...
}
Could you share it with us @CloudyCity ?
Sure. I modified it with reference to @lokielse 's _ide_helper_redis.php. @tucq88
<?php
namespace Illuminate\Support\Facades;
/**
* @method static int del( array $keys )
* @method static string dump( $key )
* @method static int exists( $key )
* @method static int expire( $key, $seconds )
* @method static int expireat( $key, $timestamp )
* @method static array keys( $pattern )
* @method static int move( $key, $db )
* @method static mixed object( $subcommand, $key )
* @method static int persist( $key )
* @method static int pexpire( $key, $milliseconds )
* @method static int pexpireat( $key, $timestamp )
* @method static int pttl( $key )
* @method static string randomkey()
* @method static mixed rename( $key, $target )
* @method static int renamenx( $key, $target )
* @method static array scan( $cursor, array $options = null )
* @method static array sort( $key, array $options = null )
* @method static int ttl( $key )
* @method static mixed type( $key )
* @method static int append( $key, $value )
* @method static int bitcount( $key, $start = null, $end = null )
* @method static int bitop( $operation, $destkey, $key )
* @method static array bitfield( $key, $subcommand, ...$subcommandArg )
* @method static int decr( $key )
* @method static int decrby( $key, $decrement )
* @method static string get( $key )
* @method static int getbit( $key, $offset )
* @method static string getrange( $key, $start, $end )
* @method static string getset( $key, $value )
* @method static int incr( $key )
* @method static int incrby( $key, $increment )
* @method static string incrbyfloat( $key, $increment )
* @method static array mget( array $keys )
* @method static mixed mset( array $dictionary )
* @method static int msetnx( array $dictionary )
* @method static mixed psetex( $key, $milliseconds, $value )
* @method static mixed set( $key, $value, $expireResolution = null, $expireTTL = null, $flag = null )
* @method static int setbit( $key, $offset, $value )
* @method static int setex( $key, $seconds, $value )
* @method static int setnx( $key, $value )
* @method static int setrange( $key, $offset, $value )
* @method static int strlen( $key )
* @method static int hdel( $key, array $fields )
* @method static int hexists( $key, $field )
* @method static string hget( $key, $field )
* @method static array hgetall( $key )
* @method static int hincrby( $key, $field, $increment )
* @method static string hincrbyfloat( $key, $field, $increment )
* @method static array hkeys( $key )
* @method static int hlen( $key )
* @method static array hmget( $key, array $fields )
* @method static mixed hmset( $key, array $dictionary )
* @method static array hscan( $key, $cursor, array $options = null )
* @method static int hset( $key, $field, $value )
* @method static int hsetnx( $key, $field, $value )
* @method static array hvals( $key )
* @method static int hstrlen( $key, $field )
* @method static array blpop( array $keys, $timeout )
* @method static array brpop( array $keys, $timeout )
* @method static array brpoplpush( $source, $destination, $timeout )
* @method static string lindex( $key, $index )
* @method static int linsert( $key, $whence, $pivot, $value )
* @method static int llen( $key )
* @method static string lpop( $key )
* @method static int lpush( $key, array $values )
* @method static int lpushx( $key, $value )
* @method static array lrange( $key, $start, $stop )
* @method static int lrem( $key, $count, $value )
* @method static mixed lset( $key, $index, $value )
* @method static mixed ltrim( $key, $start, $stop )
* @method static string rpop( $key )
* @method static string rpoplpush( $source, $destination )
* @method static int rpush( $key, array $values )
* @method static int rpushx( $key, $value )
* @method static int sadd( $key, array $members )
* @method static int scard( $key )
* @method static array sdiff( array $keys )
* @method static int sdiffstore( $destination, array $keys )
* @method static array sinter( array $keys )
* @method static int sinterstore( $destination, array $keys )
* @method static int sismember( $key, $member )
* @method static array smembers( $key )
* @method static int smove( $source, $destination, $member )
* @method static string spop( $key, $count = null )
* @method static string srandmember( $key, $count = null )
* @method static int srem( $key, $member )
* @method static array sscan( $key, $cursor, array $options = null )
* @method static array sunion( array $keys )
* @method static int sunionstore( $destination, array $keys )
* @method static int zadd( $key, array $membersAndScoresDictionary )
* @method static int zcard( $key )
* @method static string zcount( $key, $min, $max )
* @method static string zincrby( $key, $increment, $member )
* @method static int zinterstore( $destination, array $keys, array $options = null )
* @method static array zrange( $key, $start, $stop, array $options = null )
* @method static array zrangebyscore( $key, $min, $max, array $options = null )
* @method static int zrank( $key, $member )
* @method static int zrem( $key, $member )
* @method static int zremrangebyrank( $key, $start, $stop )
* @method static int zremrangebyscore( $key, $min, $max )
* @method static array zrevrange( $key, $start, $stop, array $options = null )
* @method static array zrevrangebyscore( $key, $max, $min, array $options = null )
* @method static int zrevrank( $key, $member )
* @method static int zunionstore( $destination, array $keys, array $options = null )
* @method static string zscore( $key, $member )
* @method static array zscan( $key, $cursor, array $options = null )
* @method static array zrangebylex( $key, $start, $stop, array $options = null )
* @method static array zrevrangebylex( $key, $start, $stop, array $options = null )
* @method static int zremrangebylex( $key, $min, $max )
* @method static int zlexcount( $key, $min, $max )
* @method static int pfadd( $key, array $elements )
* @method static mixed pfmerge( $destinationKey, array $sourceKeys )
* @method static int pfcount( array $keys )
* @method static mixed pubsub( $subcommand, $argument )
* @method static int publish( $channel, $message )
* @method static mixed discard()
* @method static array exec()
* @method static mixed multi()
* @method static mixed unwatch()
* @method static mixed watch( $key )
* @method static mixed eval( $script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null )
* @method static mixed evalsha( $script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null )
* @method static mixed script( $subcommand, $argument = null )
* @method static mixed auth( $password )
* @method static string echo ( $message )
* @method static mixed ping( $message = null )
* @method static mixed select( $database )
* @method static mixed bgrewriteaof()
* @method static mixed bgsave()
* @method static mixed client( $subcommand, $argument = null )
* @method static mixed config( $subcommand, $argument = null )
* @method static int dbsize()
* @method static mixed flushall()
* @method static mixed flushdb()
* @method static array info( $section = null )
* @method static int lastsave()
* @method static mixed save()
* @method static mixed slaveof( $host, $port )
* @method static mixed slowlog( $subcommand, $argument = null )
* @method static array time()
* @method static array command()
* @method static int geoadd( $key, $longitude, $latitude, $member )
* @method static array geohash( $key, array $members )
* @method static array geopos( $key, array $members )
* @method static string geodist( $key, $member1, $member2, $unit = null )
* @method static array georadius( $key, $longitude, $latitude, $radius, $unit, array $options = null )
* @method static array georadiusbymember( $key, $member, $radius, $unit, array $options = null )
*/
class Redis
{
}
Any updates on this? Autocomplete is not working on my end.
The same problem! Redis::throttle()
don't suggested!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.
I found this as the best solution
Cache::store('redis')->set($cacheKey, $data, 3600);
@faridmovsumov
I tried your way and it doesn't work.
This is the best I think so far.
/**
* Get redis cache instance
*
* @return \Illuminate\Contracts\Cache\Repository
*/
function cache_redis(): \Illuminate\Contracts\Cache\Repository
{
return Cache::store('redis');
}
/**
* Get redis instance
*
* @return mixed|Redis
*/
function redis()
{
return \Illuminate\Support\Facades\Redis::connection()->client();
}
It's a new Laravel application and I'm required predis/predis.
But the generated _ide_helper.php only has two Redis method.
like this
Should I do other things to make it work? Thx