Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to store key value with LFS file system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report