openresty / openresty/lua-nginx-module

SHDICT enhancement proposal

Open
#97 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

Hi,

the current shdict implementation is nice and fast but lacks some important features.

Here a proposal for a shm-dict storage enhancement which would bring openresty's shdict implementation directly into the top-range of shm-caching due to its versatility, APIs or other custom enhancements should not be needed anymore:

sd:set(123456, 'bla');
sd:setchild(123456, 'age', 15);
sd:setchild(123456, 'name', 'John');
sd:set_alias_key(123456, 'Employee Level 4');
sd:commit(); --to do all accumulated tasks in one blocked transaction (simply means all above happens while your shdict-mutex is continuously closed for others)

ret=sd:get(123456);
pkey=ret['pkey']; --123456
akey=ret['akey']; --Employee Level 4
val=ret['val']; --bla
age=ret['age']; --15
name=ret['name']; --John

also works by alias key:

ret2=sd:get('Employee Level 4');
pkey=ret2['pkey']; --123456
akey=ret2['akey']; --Employee Level 4
val=ret2['val']; --bla
age=ret2['age']; --15
name=ret2['name']; --John

The indices pkey, akey and val are "reserved".

sd:del(123456); --automatically deletes all childs, and the alias key "Employee Level 4"

or

sd:del('Employee Level 4'); --automatically deletes all childs, and main key 123456

param='>=';
ret=sd:get(123455, param);

param can be '<=', '>=', '=' (default '=') to find the exact key or the next bigger one or the next smaller one until the best matching key is finally found, if no matching key exists, nil is returned.

Easily iterate over all keys, even over key-series with gaps in it as the next-best is found:

next_key=0;
while ret=sd:get(next_key, '>=') do
if(ret==nil or next_key>100) then break; end;
ngx.say('Found key: '..ret['pkey']..'\n');
next_key=ret['pkey']+1;
end;

What do you think?

Thomas

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named in the proposal. Start by reviewing the current shdict implementation and its existing APIs, then define the scope for child values, alias keys, batched commits, deletion, and range lookup. Done should include an agreed design and tests covering the requested behaviors.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua, nginx
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
18/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.