Git Product home page Git Product logo

nginx-mysql-hsock-module's Introduction

--------------------------------
NGINX MySQL Handlersocket module
--------------------------------

Provides MySQL InnoDB access via Handlersocket protocol

Implemented as non-blocking upstream module

(c) 2011 Roman Arutyunyan, [email protected]



Build:
======

Add this when configuring NGNIX:

./configure --add-module=$PATH_TO_MODULE




Usage:
=========

Suppose you have an InnoDB table in database "mydbname" named "mytable"
with 4 fields (of any type):

  * "key" (this is primary key field as the name says :) )
  * "field1"
  * "field2"
  * "field3"

These are settings you should add to nginx.conf file
to work with the table directly from NGINX.

# first create upstreams (read & write) with keepalive enabled

upstream hsock_rsrv {
	server 127.0.0.1:9998;
	keepalive 1024;
}

upstream hsock_wsrv {
	server 127.0.0.1:9999;
	keepalive 1024;
}

# then create operation locations within server block.
# 4 operations are supported: select, update, insert, delete
# Note there should be different upstreams for each of them
# (the module performs index initialization based on particular 
# location data)

location ~ /select.* {

	hsock_pass   hsock_rsrv;
	hsock_db     mydbname;
	hsock_table  mytable;

	# Yes, you should copy variables like this
	# if you need to use arg_, http_ etc variables.
	# They are not accessed directly so far.

	set $key $arg_key; 

	hsock_select field1 field2 field3;
	hsock_key    $key;
}

location ~ /insert.* {

	hsock_pass   hsock_wsrv;
	hsock_db     mydbname;
	hsock_table  mytable;

	set $key $arg_key;
	set $field1 $arg_field1;
	set $field2 $arg_field2;
	set $field3 $arg_field3;

	hsock_insert key $key
		field1 $field1
		field2 $field2
		field3 $field3;
}

location ~ /update.* {

	hsock_pass   hsock_wsrv;
	hsock_db     mydbname;
	hsock_table  mytable;

	set $key $arg_key;
	set $field1 $arg_field1;
	set $field2 $arg_field2;
	set $field3 $arg_field3;

	hsock_update
		field1 $field1
		field2 $field2
		field3 $field3;

	hsock_key $key;
}

location ~ /delete.* {

	hsock_pass   hsock_wsrv;
	hsock_db     mydbname;
	hsock_table  mytable;

	set $key $arg_key;

	hsock_delete;
	hsock_key $key;
}


Data is returned line-by-line
1 line - errorcode (0=OK, >0=error)
2 line - number of data lines
3 ...  - data lines; data fields are returned on a field-per-line basis. 
         Multiple rows are returned the same way as a single row.

nginx-mysql-hsock-module's People

Contributors

arut avatar

Watchers

 avatar  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.