skip to Main Content

I have a question about Redis caching.
I wrote some code to cache some information and it works fine, but is there a way to check what’s being stored inside of it through redis-cli? I just want to make sure that the value gets deleted after 10 minutes.

how I store stuff:

Cache::store('redis')->put('inventory_' . $this->user->steamid64, $items, 15);

2

Answers


  1. Enter the redis-cli and use:

    • keys * to see list of all keys
    • TTL my_key_name to see remaining expire time of the key

    You can execute any of Redis commands inside of the redis-cli. It’s good tool for development.

    Login or Signup to reply.
  2. Since you are using laravel’s Cache class instead of Redis – then you need to check for the prefix. By default it ships like this in config/cache.php

    'prefix' => env('CACHE_PREFIX', 'laravel')
    

    If there is a prefix(and it is laravel) it is going to be like this (if there is no prefix then you may discard laravel: from the key names)

    127.0.0.1:6379> get laravel:inventory_1
    "somevalue"
    127.0.0.1:6379> ttl laravel:inventory_1
    (integer) 885
    127.0.0.1:6379>
    

    For the “development” purpose you may also use monitor command to see which commands are executed in redis. It is going to print like this;

    127.0.0.1:6379> monitor
    OK
    1591091085.487083 [0 127.0.0.1:51828] "set" "myinventory_1" "myvalue" "EX" "900"
    1591091091.143395 [0 127.0.0.1:51828] "get" "myinventory_1"
    1591091095.280724 [0 127.0.0.1:51828] "ttl" "myinventory_1"
    

    Side note: You don’t need to call store method if your default cache driver is already redis.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search