Python LMDB 라이브러리 사용 예

2364 단어 PythonLMDB창고
linux에서 명령을 사용할 수 있습니다

pip install lmdb
lmdb 패키지를 설치합니다.
----
  • lmdb 데이터베이스 파일 생성
  • 증개삭제
  • 조사
  • 1. 비어있는lmdb 데이터베이스 파일 생성

    
    # -*- coding: utf-8 -*-
    import lmdb
    #  train data.mbd lock.mdb , , , 
    # map_size , kb, 1TB 
    env = lmdb.open("./train",map_size=1099511627776)
    env.close()

    2. LMDB 데이터 추가, 수정, 삭제

    
    # -*- coding: utf-8 -*-
    import lmdb
    # map_size , kb, 1TB 
    env = lmdb.open("./train", map_size=1099511627776)
    txn = env.begin(write=True)
    
    #  
    txn.put(key = '1', value = 'aaa')
    txn.put(key = '2', value = 'bbb')
    txn.put(key = '3', value = 'ccc')
     
    #  
    txn.delete(key = '1')
     
    #  
    txn.put(key = '3', value = 'ddd')
     
    #  commit() 
    txn.commit()
    env.close()

    3. LMDB 데이터베이스 조회

    
    # -*- coding: utf-8 -*-
    import lmdb
     
    env = lmdb.open("./train")
     
    #  write True 
    txn = env.begin(write=True)
    ############################################ 、 、 
     
    #  
    txn.put(key = '1', value = 'aaa')
    txn.put(key = '2', value = 'bbb')
    txn.put(key = '3', value = 'ccc')
     
    #  
    txn.delete(key = '1')
     
    #  
    txn.put(key = '3', value = 'ddd')
     
    #  commit() 
    txn.commit()
    ############################################ lmdb 
    txn = env.begin()
     
    # get 
    print txn.get(str(2))
     
    #  cursor() 
    for key, value in txn.cursor():
      print (key, value)
      
    ############################################
    env.close()

    4. 이미 읽었습니다.mdb 파일 내용

    
    # -*- coding: utf-8 -*-
    import lmdb
     
    env_db = lmdb.Environment('trainC')
    # env_db = lmdb.open("./trainC")
     
    txn = env_db.begin()
     
    # get , , None
    print txn.get(str(200))
     
    for key, value in txn.cursor(): # 
      print (key, value)
     
    env_db.close()
    이상은 Python LMDB 라이브러리의 사용 예시에 대한 상세한 내용입니다. Python LMDB 라이브러리에 대한 더 많은 자료는 저희 다른 관련 글을 주목해 주십시오!

    좋은 웹페이지 즐겨찾기