i sql developer , new redis, it's performance interesting. have problem think redis me in. have sql table familiar this:
| container <string><nounq> | process <string><nounq> | process_data <string><nounq> | timecreated <timestamp><nounq>|
this table when populated max has ~450,000,000 rows. running on aws. these rows select processes within container (~1,000,000 containers), have in sql (of course container indexed):
select * table container = '[container_name]';
i have cronjob script runs every hour , removes old processes containers this:
delete table timecreated <= [some_time];
so have processes not older ~4-5 hours. looking @ redis feel can engineer similar improve performance, having trouble convert sql design redis.
my first thought use hset, found out hset not allow expire command on fields not automatically remove old process. concerned performance , efficiency.
look's can (and should) use hset. , look's not need expire fields. need expire keys. key name based on container name
, expireat on key. if told table relation structure wrote above analogue 1 table row 1 key:
multi hmset <container name:rowid> process <value> process_data <value> expireat <container name:rowid> <timecreated> exec
also can use zset store time related list of rows:
zadd <container name> <timecreated> <rowid>
so may use zrange select
equivalent. may use lua scripting content of container 1 request. (i can make mistake somewhere in syntax of lua):
local result = {} local tmp = redis.call( 'zrange', keys[1], arg[1], arg[2], 'withscores' ) k, v in pairs(tmp) result[v] = redis.call('hgetall', keys[1] + ':' + k) end return result
where keys1 - container name, arg1 - , arg2- .
p.s. should understand how redis expire keys understand thats happens memory @ instance.