1

I used the laravel's default Redis::set() function to store items, but I have 13k records and the memory usage is around 400mb. Now I'm looking for ways to reduce it. I noticed laravel stores data as string not as hash which is wasting resources. How can I use Redis with hash through laravel?

1 Answer 1

3

In the official Laravel Redis Facade, it's said that

The Redis facade supports dynamic methods, meaning you may call any Redis command on the facade and the command will be passed directly to Redis

So I guess you can use

Redis::hSet('h', 'key1', 'hello');
$value = Redis::hGet('h', 'key1');

But I really doubt that you will reduce drastically your memory usage, unless you have very long key name. Instead you can :

  • If it's possible think about executing EXPIRE on your keys
  • You can also compress your key value : for example, if it's encoded in json, you can use msgpack which claims to be 1/3 smaller and faster to encode/decode, otherwise you can gz compress your content like explains in this post
  • You can use a Redis memory profiler like this one to search for a potential problem

If you test, let us know your results, it can be interesting.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks it works this way. I'll update this post with results
Ahh sorry, I solved the problem another way. I stored the data instead in DB, and used nodeJs workers to compile and cache the results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.