欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java使用內(nèi)存數(shù)據(jù)庫ssdb的步驟

 更新時間:2020年12月03日 14:44:19   作者:柯廣  
這篇文章主要介紹了java使用內(nèi)存數(shù)據(jù)庫ssdb的步驟,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下

看這篇文章的同學(xué),redis相信你一定很熟悉了,ssdb是一個功能類似于redis,性能稍弱于redis的高性能數(shù)據(jù)庫,主要是可以使用磁盤代替內(nèi)存,使得小內(nèi)存可以勝任請求不高的大部分場景,從而節(jié)約資源。ssdb官方是這樣評價的 : 一個高性能的支持豐富數(shù)據(jù)結(jié)構(gòu)的 NoSQL 數(shù)據(jù)庫, 用于替代 Redis.

1. 特性

  • 替代 Redis 數(shù)據(jù)庫, Redis 的 100 倍容量
  • LevelDB 網(wǎng)絡(luò)支持, 使用 C/C++ 開發(fā)
  • Redis API 兼容, 支持 Redis 客戶端
  • 適合存儲集合數(shù)據(jù), 如 list, hash, zset...
  • 客戶端 API 支持的語言包括: C++, PHP, Python, Java, Go
  • 持久化的隊列服務(wù)
  • 主從復(fù)制, 負(fù)載均衡

支持多種api,比如php使用:

<?php
require_once('SSDB.php');
$ssdb = new SimpleSSDB('127.0.0.1', 8888);
$resp = $ssdb->set('key', '123');
$resp = $ssdb->get('key');
echo $resp; // output: 123

2. 安裝

wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip
unzip master
cd ssdb-master
make
# optional, install ssdb in /usr/local/ssdb
sudo make install

3. 啟動

# start master
./ssdb-server ssdb.conf

# or start as daemon
./ssdb-server -d ssdb.conf

4. 與redis性能對比

5. java 讀寫ssdb

java操作ssdb需要的maven依賴:

<dependency>
 <groupId>com.lovver</groupId>
 <artifactId>ssdbj</artifactId>
 <version>0.0.1</version>
</dependency>

java讀取ssdb,有兩種方式,分別是單連接和連接池的方式,親測以下方式都可以用:

SSDBConnection單連接方式

@Test
public void test(){
 SSDBDriver dd= new SSDBDriver();
 Properties info = new Properties();

 info.setProperty("SSDB_HOST", "192.168.1.1");
 info.setProperty("SSDB_PORT", "8888");
 // 密碼
 info.setProperty("password", "ssdb.test");
 info.setProperty("loginTimeout", "300");
 info.setProperty("tcpKeepAlive", "true");
 info.setProperty("protocolName", "ssdb");
 info.setProperty("protocolVersion", "1.0");

 SSDBConnection conn = null;
 try{
  conn = dd.connect(info);
  System.out.println(conn);

  // 寫入數(shù)據(jù)到ssdb
  ArrayList<byte[]> setParams=new ArrayList<byte[]>(){
   {
    add("joliny".getBytes());
    add("是的發(fā)生地發(fā)生1231sdfsfg23".getBytes());
   }
  };
  conn.execute("set",setParams);

  // 從ssdb讀取數(shù)據(jù)
  List params=new ArrayList();
  params.add("joliny".getBytes());
  BaseResultSet<byte[]> rs=conn.execute("get",params);
  System.out.println(new String(rs.getResult()));

 } catch (SSDBException e) {
  e.printStackTrace();
 }finally {
  if(conn != null){
   conn.close();
  }
 }

}

SSDBPoolConnection連接池方式
多線程通常需要用連接池的方式,提高效率。

import com.lovver.ssdbj.core.BaseResultSet;
import com.lovver.ssdbj.core.SSDBDriver;
import com.lovver.ssdbj.core.impl.SSDBConnection;
import com.lovver.ssdbj.exception.SSDBException;
import com.lovver.ssdbj.pool.SSDBDataSource;
import com.lovver.ssdbj.pool.SSDBPoolConnection;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @Author: keguang
 * @Date: 2020/2/17 16:23
 * @version: v1.0.0
 * @description:
 */
public class SSDBTest {

 private static SSDBDataSource ds=null;
 static{
  Properties info = new Properties();
  info.setProperty("password", "ssdb.test");
  info.setProperty("loginTimeout", "300");
  info.setProperty("tcpKeepAlive", "true");
  info.setProperty("protocolName", "ssdb");
  info.setProperty("protocolVersion", "1.0");
  ds = new SSDBDataSource("192.168.1.1",8888,null,info);
 }

 @Test
 public void test2(){
  SSDBPoolConnection conn=null;
  try {
   conn = ds.getConnection();
   System.out.println(conn);

   ArrayList<byte[]> setParams=new ArrayList<byte[]>(){
    {
     add("language".getBytes());
     add("zh-CN".getBytes());
    }
   };
   conn.execute("set",setParams);

   ArrayList params=new ArrayList();
   params.add("language".getBytes());

   BaseResultSet<byte[]> rs= conn.execute("get",params);
   if(rs.getResult() == null){
    System.out.println("null");
   }
   System.out.println(new String(rs.getResult()));

  } catch (Exception e) {
   e.printStackTrace();
  }finally {
   if (conn != null){
    conn.close();
   }
  }
 }
}

以上就是java使用內(nèi)存數(shù)據(jù)庫ssdb的步驟的詳細(xì)內(nèi)容,更多關(guān)于java使用內(nèi)存數(shù)據(jù)庫ssdb的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • spring MVC cors跨域?qū)崿F(xiàn)源碼解析

    spring MVC cors跨域?qū)崿F(xiàn)源碼解析

    本文主要介紹了spring MVC cors跨域?qū)崿F(xiàn)源碼解析。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • @PathVariable 如何自動填充入實例對象中

    @PathVariable 如何自動填充入實例對象中

    這篇文章主要介紹了@PathVariable 實現(xiàn)自動填充入實例對象中的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • java中this關(guān)鍵字的詳細(xì)使用介紹

    java中this關(guān)鍵字的詳細(xì)使用介紹

    大家好,本篇文章主要講的是java中this關(guān)鍵字的詳細(xì)使用介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2022-01-01
  • 關(guān)于Openfire集群源碼的分析

    關(guān)于Openfire集群源碼的分析

    這篇文章主要介紹了關(guān)于Openfire集群源碼的分析,內(nèi)容比較詳細(xì),具有一定參考價值,需要的朋友可以了解下。
    2017-09-09
  • springboot websocket集群(stomp協(xié)議)連接時候傳遞參數(shù)

    springboot websocket集群(stomp協(xié)議)連接時候傳遞參數(shù)

    這篇文章主要介紹了springboot websocket集群(stomp協(xié)議)連接時候傳遞參數(shù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • Spring不能注入Static變量的原因及Spring注入靜態(tài)變量

    Spring不能注入Static變量的原因及Spring注入靜態(tài)變量

    這篇文章主要介紹了Spring不能注入Static變量的原因及Spring注入靜態(tài)變量,需要的朋友可以參考下
    2016-01-01
  • Mybatis批量更新數(shù)據(jù)庫錯誤問題

    Mybatis批量更新數(shù)據(jù)庫錯誤問題

    這篇文章主要介紹了Mybatis批量更新數(shù)據(jù)庫錯誤問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • SpringBoot中Dozer的使用小結(jié)

    SpringBoot中Dozer的使用小結(jié)

    dozer是用來兩個對象之間屬性轉(zhuǎn)換的工具,有了這個工具之后,我們將一個對象的所有屬性值轉(zhuǎn)給另一個對象時,就不需要再去寫重復(fù)的set和get方法了,下面介紹下SpringBoot中Dozer的使用,感興趣的朋友一起看看吧
    2022-03-03
  • Mybatis給數(shù)據(jù)庫敏感字段加解密詳解

    Mybatis給數(shù)據(jù)庫敏感字段加解密詳解

    這篇文章主要介紹了Mybatis給數(shù)據(jù)庫敏感字段加解密詳解,為了保護數(shù)據(jù)庫敏感字段數(shù)據(jù)安全,有時候我們需要將敏感數(shù)據(jù)加密入庫,查詢時再解密成明文,我們可以利用Mybatis自定義TypeHandler來處理,需要的朋友可以參考下
    2023-11-11
  • Java jdbc批量多線程讀取CVS文件入庫

    Java jdbc批量多線程讀取CVS文件入庫

    這篇文章主要為大家詳細(xì)介紹了Java jdbc批量多線程讀取CVS文件入庫,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08

最新評論