TestRedis.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Redis;
  5. use Illuminate\Support\Facades\Cache;
  6. class TestRedis extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'test:redis';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'testing redis';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $this->info("test redis");
  37. Redis::set("test-redis",'this is a test');
  38. $this->info("redis get:".Redis::get("test-redis"));
  39. Redis::hSet("test-redis-hash",'hash','this is a test hash');
  40. $this->info("redis hash get:".Redis::hGet("test-redis-hash",'hash'));
  41. $this->info("test cache");
  42. Cache::put('cache-key','cache value',10);
  43. $this->info('catche test: ',Cache::get('cache-key'));
  44. cache(["cache-key-2"=>'cache value 2']);
  45. $this->info('cache() test',cache("cache-key-2"));
  46. $value = Cache::get('cache-key-3',function(){
  47. return 'cache-value-3';
  48. });
  49. if(Cache::has('cache-key-3')){
  50. $this->info("cache-key-3 exist");
  51. }else{
  52. $this->info("cache-key-3 no");
  53. }
  54. return 0;
  55. }
  56. }