Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to store key value with LFS file system

Shulou Source: shulou.com Published: 2022-05-31 17:12:13 09月28日 Update

This article introduces you how to use the LFS file system to store key value, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Some people ask LFS if it is possible to store key value.

It is possible to write with single thread, and it is possible to read with multiple threads. (well, you can consider adding concurrent writing in the future. Now it has been supported and written. )

So how do you do it? In fact, key value is a hash structure. As it happens, hash indexes are supported in LFS.

Support for key value means that you can also read and write files through the file name (there is no concept of a folder, but the file name can still be a pathname that contains the folder).

Note: the following method can be encapsulated into a more general interface to be used, and this is done here to let you know how to do it.

/ / set (key, value) Socket con = LFSConnection.getConnection (); LFSByteArray lb = new LFSByteArray (); / / everyone is used to the encapsulated set (key, value) form, but it is possible to encapsulate this code (the script here is just to provide better transparency and learn more details) lb.setStatement ("+" local r = data_open (vars [0])) "+" if (r = = 1) then; "+" local key = vars [1]; "+" local value = vars [2]; "/ / this is a tool for writing a unique index +" local iw = vars.indexWrite; "/ / sets what to write +" iw.buffer = value; "/ / sets key +" iw:setIndex (key) "/ / if the key already exists, it will not be written again, only the file pointing to the content ID +" local id = iw:write (); "+" putLong (id) "; +" end; "+"); lb.putString (FILE_NAME); lb.putString ("key"); lb.putString ("value"); lb.writeTo (con); long id = lb.getLong (0) will be returned. Lb.clear ()

Get (key)

/ / get (key) Socket con = LFSConnection.getConnection (); LFSByteArray lb = new LFSByteArray (); lb.setStatement ("+" local r = data_open (vars [0]); "+" if (r = = 1) then; "+" local key = vars [1]; "+" local id = data_read_index (key,-1); "+" if (id > = 0) then "+" data_read (id); "+" putBytes (vars.dataData,-1); "+" else; "+" putNull (); "+" end; "+" end; "+"); lb.putString (FILE_NAME); lb.putString (" key "); lb.writeTo (con) Byte [] value = lb.get (0); lb.clear (); this is all about how to use the LFS file system to store key value. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: File content storage encapsulation support system just file name folder more index thread hash help good code representative interest again function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information vpn Linux Apple