database - Store a 2D array in redis -


i have 2d array store in redis , see 2 solutions: storing json string or storing 1 hash per line. way better?

i faced same question when designing application. opted on side of simplicity. i'm going assume 2d array of data represents database row. json encode , store using set. allows me use mget , mset when want handle multiple objects using 1 redis command. if data gets updated in database, del key. me easier trying update redis hash.

hashes in redis has advantages. take less memory because of "ziplist" encoding redis uses. can avoid serialization well, pretty significant apps.

here's sample use case hash me. let's want username given user id. hget user.usernames 1234. give me username user id 1234. if there miss, query db , set , since data never changes, never expire hash. allows quick common piece of data rather pulling entire user, unserialize, , return needed field.

for prospective massive lookup table, use algorithm purposed here: http://redis.io/topics/memory-optimization uses multiple hashes if there 1 , utilizes ziplist encoding save memory.

whichever method choose, stay consistent.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -