GithubHelp home page GithubHelp logo

shengyf2 / jedisql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from csnight/jedisql

0.0 0.0 0.0 233 KB

基于jedis源码扩展的redisql模块JavaAPI,使redis+redisql能够实现jedis 在redis中执行sql

License: Other

Java 100.00%

jedisql's Introduction

JediSQL

Support SQL on redis with redisql module,this library extend redisql api on jedis source code,add all redisql command as java method

This library provides all the features of jedis and redisql, and supports the use of redisql in cluster and pipeline environments

Based on Jedis, jedis-sql and JRediSQL

package com.supermap.context;

import com.csnight.jedisql.JediSQL;
import com.csnight.jedisql.Pipeline;
import com.csnight.jedisql.Response;
import com.supermap.redis.MultiRedisConnPoolST;
import com.supermap.utils.GUID;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class test {
    public static void main(String[] args) {
        MultiRedisConnPoolST st = MultiRedisConnPoolST.getInstance();
        st.setSt_pool_type("sin");
        st.setPort(6379);
        st.setServerIp("140.1.25.30");
        st.BuildJedisPool();
        for (int i = 0; i < 10; i++) {
            tests();
        }
    }

    public static void tests() {
        //Get a Redis connection from pool
        MultiRedisConnPoolST st = MultiRedisConnPoolST.getInstance();
        String guid = GUID.getUUID();
        JediSQL jediSQL = st.getJedis(guid);
        //clear db
        jediSQL.flushAll();
        String table1 = "TRAINS";
        //use pipeline
        Pipeline pipe = jediSQL.pipelined();
        //create a db by redisql
        Response<String> rs1 = pipe.create_db("DB");
        pipe.sync();
        System.out.println(rs1.get());
        //create a table by redisql
        Response<List<Object>> rs2 = pipe.exec("DB", "CREATE TABLE " + table1 + "(key TEXT, DSDS TEXT)");
        pipe.sync();
        System.out.println(rs2.get());
        long start = System.currentTimeMillis();
        pipe.create_statement_now("DB", "st", "INSERT INTO " + table1 + " VALUES(?1,?2)");
        pipe.sync();
        // insert 1000000 records into redis table name such as "cats:132131"
        for (int i = 0; i < 1000000; i++) {
            pipe.exec_statement_now("DB", "st", "cats:" + i, "AAA");
        }
        pipe.sync();
        pipe.delete_statement("DB", "st");
        pipe.sync();
        long sync_insert = System.currentTimeMillis();
        System.out.println("Use insert command:" + (sync_insert - start) + "ms");
        start = System.currentTimeMillis();
        pipe.create_statement_now("DB", "std", "SELECT * FROM " + table1);
        pipe.sync();
        // select all records from redis table

        Response<List<Object>> res = pipe.exec_statement_now("DB", "std");

        pipe.sync();
        pipe.delete_statement("DB", "std");
        pipe.sync();
        List<Object> ss=res.get();
        sync_insert = System.currentTimeMillis();
        System.out.println("Use select command:" + (sync_insert - start) + "ms");
        st.close(guid);
    }
}

//the print result may like blow
OK
[DONE]
Use insert command:4923ms
Use select command:856ms
OK
[DONE]
Use insert command:4918ms
Use select command:901ms
OK
[DONE]
Use insert command:4891ms
Use select command:714ms
...

It takes short time than not use pipeline to insert when you insert a lot of records

jedisql's People

Contributors

csnight avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.