Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a feature like Redis hget hset #226

Open
morteza102030 opened this issue Apr 30, 2023 · 5 comments
Open

add a feature like Redis hget hset #226

morteza102030 opened this issue Apr 30, 2023 · 5 comments

Comments

@morteza102030
Copy link

It would be great if you could add a feature like Redis hget hset to lmdb

@kriszyp
Copy link
Owner

kriszyp commented Apr 30, 2023

Like this?

function hget(db, id, property) {
  return db.get(id)?.[property];
}
function hset(db, id, property, value) {
  let record = db.get(id);
  if (record && typeof record === 'object') record[property] = value;
  else record = { [property]: value };
  db.put(id, record);
}

@morteza102030
Copy link
Author

thank you for your answer

i store something like this in redis

r.hset('chat1', 'sararh', 5436)
r.hset('chat1', 'jack', 7396)
r.hset('chat1', 'bill', 5551)
...

chat1 have over 100000 users

r.hset('chat2', 'bill', 5456)
....
chat2 have over 100000 users
and the more

I think your example almost that i want

But I think this method is not suitable when our data has a large number of values (users)

I need and in Redis I can update thousands of users every second
It doesn't seem logical to load and save several hundred thousand users for each update
It is probably better if this process is done by C+ in the background

@kriszyp
Copy link
Owner

kriszyp commented May 1, 2023

Ah, I see. I think you would probably want to use sub-databases for that:

chat1 = db.openDB('chat1')
chat1.put('sararh', 5436)

(and you should be able do many thousands of puts per second).

@morteza102030
Copy link
Author

morteza102030 commented May 1, 2023

Because I have thousands of chats i don't know it's not problem i openDB all of them or not

Now when we use


let db = db.openDB('my-index', {
	dupSort: true,
	encoding: 'ordered-binary',
});

With this feature, we can easily and quickly have similar features redis sadd, srem, scard, sismember, smembers
This is a great options

If we had an option like this to create a simple nested keys like redis hset on one db it would be very interesting

@kriszyp
Copy link
Owner

kriszyp commented May 1, 2023

Ah, ok, you can also use multi-value keys like this:

db.put(['chat1', 'sararh'], 5436);
db.put(['chat1', 'jack'], 7396)
db.get(['chat1', 'sararh']);

Each of these will be separate entries in the database (so db.get('chat1') won't return everything in chat1, but you can do db.getRange({start: 'chat1', end: ['chat1', orderedBinary.MAXIMUM_KEY]}) to iterate through all the entries in chat1).
This works as long as you are doing the default key encoding (ordered-binary), and you don't need dupSort for this, nor any special (value) encoding..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants