The Tarantool driver for Crystal.
Thanks to all my patrons, I can continue working on beautiful Open Source Software! 🙏
Lauri Jutila, Alexander Maslov, Dainel Vera
You can become a patron too in exchange of prioritized support and other perks
Tarantool is a super-fast NoSQL* in-memory database. Crystal is a super-fast compiled language. Take both.
* It is planned to fully support SQL in version 2, which is currently in alpha
Recent benchmarking of 100k select
requests on a single 0.90Ghz CPU core with Tarantool running on the same machine via Docker:
$ crystal bench/select.cr --release
1.530000 1.070000 2.600000 ( 2.597737)
Resulting performance is 38.4k RPS, averaging in 26μs per request.
Add this to your application's shard.yml
:
dependencies:
tarantool:
github: vladfaust/tarantool.cr
version: ~> 0.2.2
This shard follows Semantic Versioning 2.0.0, so see releases and change the version
accordingly.
After you installed and run Tarantool and setup your schema, do:
require "tarantool"
db = Tarantool::Connection.new("localhost", 3301) # Initiate the connection
db.parse_schema # Save current box schema to db instance
db.insert(:examples, {1, "hello"}) # Insert "hello" tuple
db.update(:examples, :primary, {1}, {"=", 1, "hello world"}) # Replace "hello" with "hello world"
db.select(:examples, :name, {"hello world"}).body.data # => [[1, "hello world"]]
All Tarantool::Connection#*
requests are synchronous, they will be waiting until the response is received. However, a single Tarantool instance itself is capable of handling lots of simultaneous connections, so for the best perfomance consider running requests in multiple fibers:
32.times do
spawn do
db.ping # All 32 pings are executed concurrently
end
end
- Run
docker run --name mytarantool -d -p 3301:3301 -v /var/lib/docker/volumes/tarantool:/var/lib/tarantool tarantool/tarantool:1
- Connect to tarantool via console (
docker exec -i -t mytarantool console
) and apply schema found in/spec/helpers.lua
crystal spec
- Fork it ( https://github.com/vladfaust/tarantool.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- @vladfaust Vlad Faust - creator, maintainer