GithubHelp home page GithubHelp logo

ssdb-erlang's Introduction

ssdb-client

Erlang SSDB Client.

#How To Use

make sure ssdb-server is opening.

compile code use make

$ make

$ erl -pa ebin -pa deps/goldrush/ebin/ -pa deps/lager/ebin

1> ssdb:start("localhost",8888).

{ok,<0.36.0>}

2> ssdb:query([set,a,<<"this is a test">>]).

{ok,1}

3> ssdb:query([get,a]).

{ok,<<"this is a test">>}

4> ssdb:query([hset,h,k,<<"test hset">>]).

{ok,1}

5> ssdb:query([hget,h,k]).

{ok,<<"test hset">>}

more detail see src/ssdb_demo.erl

#Api You can start ssdb client by ssdb:start/0,ssdb:start/2,ssdb:start/3,ssdb:start/4 or ssdb:start/5

ssdb:start(Host,Port,PoolSize,Password,IsReconnect)

	Host = list() default:"localhsot"
	
	Port = integer() default:8888
	
	PoolSize = integer() default:5
	
	Password = list() default:undefined
	
	IsReconned = 0/1 default 0 is auto reconnect to server when socket closed

use client api ssdb:query(Cmd),pass args by list

Cmd = atom | ssdb_cmd()

ssdb_cmd = list() eg. [get,a],[set,a,<<"abc">>],[hget,h,test] ...

ssdb-erlang's People

Contributors

kqqsysu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ssdb-erlang's Issues

parse receiving data exception

ssdb_conn.erl
parse_recv fun,when step =:= ?SSDB_STEP_DATA
the last message can match <<BlockData:Size/binary-unit:8, $\n:8, $\n:8, Res/binary>> or <<BlockData:Size/binary-unit:8, $\n:8, Res/binary>>
If the match <<BlockData:Size/binary-unit:8, $\n:8, Res/binary>>,step state = ?SSDB_STEP_SIZE,but it was the last message.
solution:
parse_recv(#ssdb_conn{step = ?SSDB_STEP_SIZE, data = Data} = State, InData) ->
NewData = <<Data/binary, InData/binary>>,
case binary:split(NewData, <<"\n">>) of
[<<>>, <<>>] -> %% repair
Reply = State#ssdb_conn.reply,
State#ssdb_conn{step = ?SSDB_STEP_FINISH, size = 0, data = <<>>, reply = lists:reverse(Reply)};
[BinSize, BlockData] ->
Size = erlang:binary_to_integer(BinSize),
NewState = State#ssdb_conn{data = BlockData, size = Size, step = ?SSDB_STEP_DATA},
parse_recv(NewState, <<>>); %% parse data
_ ->
%% wait for get size
State#ssdb_conn{data = NewData}
end;

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.