1 Star 0 Fork 0

siddontang / tlock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

TLock

A simple tiny centralized lock service, still in development.

Although there are some existing key lock service, like Zookeeper, Etcd, or even Redis, they don't fit my need. E.g, I want to lock multi keys at same time, not one by one. And I want to support hierachical path lock.

If you have some good recommendations, please tell me!

Key Lock

We can lock multi keys using tlock at same time, a simple example:

// shell1

// lock key a, b and c at same time, lock timeout is 30s
// if lock ok, return a lockid for later unlock
// you must do query escape in the real scenario,:-)
POST http://localhost/lock?names=a,b,c&type=key&timeout=30

// do something then unlock
DELETE http://localhost/lock?id=lockid

// shell2
POST http://localhost/lock?names=a,b,c&type=key&timeout=30

return lockid 

DELETE http://localhost/lock?id=lockid

Path Lock

A path lock is for hierachical lock, like a file system lock.

E.g, if we lock path "a/b/c", other can not operate its ancestor like ("a", "a/b") or descendant like ("a/b/c/d", "a/b/c/e"), but can operate its brother like ("a/b/d").

A simple example:

// shell1

// lock path a/b/c, a/b/d at same time, lock timeout is 30s
// if lock ok, return a lockid for later unlock
// you must do query escape in the real scenario,:-)
POST http://localhost/lock?names=a/b/c,a/b/d&type=path&timeout=30

// do something then unlock
DELETE http://localhost/lock?id=lockid

// shell2
POST http://localhost/lock?names=a/b/c,a/b/d&type=path&timeout=30
DELETE http://localhost/lock?id=lockid

RESP Support

tlock supports Redis Serialiazation Protocol(RESP), so you can use any redis client to communicate with tlock, a simple example:

# shell1 redis-cli
redis>LOCK abc TYPE key TIMEOUT 10
redis>lockid
// do something
redis>UNLOCK lockid
redis>OK

# shell2 redis-cli 
redis>LOCK abc TYPE key TIMEOUT 10
// will hang up until shell1 unlock 
redis>lockid
// do something
redis>UNLOCK lockid
redis>OK

You can also use a RESP client for tlock:

import "github.com/siddontang/tlock"

client := NewRESPClient(addr)
locker, _ := client.GetLocker("key", "abc")
locker.Lock()
locker.Unlock()
The MIT License (MIT) Copyright (c) 2015 siddontang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Tiny lock service 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/siddontang/tlock.git
git@gitee.com:siddontang/tlock.git
siddontang
tlock
tlock
master

搜索帮助