BurningBright

  • Home

  • Tags

  • Categories

  • Archives

  • Search

探索redis 键散列过程源码

Posted on 2020-06-10 | Edited on 2020-06-20 | In db

在lua方案里碰到了在redis集群中执行多键操作,Key要在同一slot的限制。

经查资料,说是要避免 Max redirect exception,节点会因为某些场景发生阻塞(阻塞时间大于 clutser-node-timeout),被判断下线。
想来在多键命令执行时,节点是阻塞的,如果不做单slot限制,键槽所分布的节点都会受到阻塞的影响。

Read more »

基于Redis-Lua脚本的抢购方案

Posted on 2020-06-02 | Edited on 2020-06-20 | In db

Lua 脚本功能是 Reids的一大亮点, 通过内嵌对 Lua 环境的支持,
Redis 解决了长久以来不能高效地处理 CAS (check-and-set) 命令的缺点。
并且可以通过组合使用多个命令, 轻松实现以前很难实现或者不能高效实现的模式。

该抢购方案基于Lua脚本,实际项目中可根据需要扩展命令。

Read more »

观察redis集群握手造成的带宽损耗

Posted on 2020-05-21 | Edited on 2020-06-20 | In db

被槽吸引

why redis-cluster use 16384 slots? #2576
【原创】为什么Redis集群有16384个槽
看到这位博主的文章,感觉redis作者的考量很有意思。

打开集群的头文件,看了一下数据结构,不出所料是16384个槽
https://github.com/antirez/redis/blob/6.0.0/src/cluster.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*-----------------------------------------------------------------------------
* Redis cluster data structures, defines, exported API.
*----------------------------------------------------------------------------*/

#define CLUSTER_SLOTS 16384

line:248
typedef struct {
...
uint16_t type; /* Message type */
...
unsigned char myslots[CLUSTER_SLOTS/8];
...
union clusterMsgData data;
} clusterMsg;
Read more »

Search content in files under folder

Posted on 2020-04-10 | Edited on 2020-05-31 | In linux

regular expression

1
/\bsys_.*?\b/

match words begin with sys_, as short as possible.

definite scope

1
find --name "*.xml" .

If you search directly under a folder
grep -r —recursive may more suitable.

turn lower to upper letter

1
tr "[:lower:]" "[:upper:]"

duplicate removal

1
awk '!a[$0]++{print}'

when current line not show in below, print it.

integration

1
find -name "*.xml" | xargs grep -iohP '\bsys_.*?\b' | tr "[:lower:]" "[:upper:]" | awk '!a[$0]++{print}'
  1. find target files
  2. grep string in files, —ignore-case —only-matching —no-filename —perl-regexp
  3. turn capitalization
  4. duplicate removal

Segment level locking in Oracle

Posted on 2020-04-10 | Edited on 2020-06-20 | In linux

Simple demonstration of segment-level locking caused by concurrency in an Oracle database

reprint:简单演示 Oracle 数据库并发导致段级锁(表级锁)
https://www.cnblogs.com/liuning8023/archive/2013/03/20/2971946.html

content

  • environment
  • demonstration

本文简单演示并发导致的行级锁。并发是两个以上的用户对同样的数据进行修改(包括插入、删除和修改)。锁的产生是因为并发。没有并发,就没有锁。并发的产生是因为系统需要,系统需要是因为用户需要。

This article briefly demonstrates row-level locking caused by concurrency. Concurrency is when two or more users make changes (including inserts, deletes, and modifications) to the same data. Locks occur because of concurrency. No concurrency, no locking. Concurrency occurs because the system needs it, and the system needs it because the user needs it.

Read more »

Monitor jar by prometheus

Posted on 2020-02-27 | Edited on 2020-06-20 | In linux

Install software first

Env/Componet Description Description
System CentOS 7.3 http://archive.kernel.org/centos-vault/7.3.1611/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso
Go 1.11.4 https://prometheus.io/download/#prometheus
Prometheus 2.6.0 https://golang.org/dl/
Grafana 5.4.2 https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
Read more »

Switch python version in centos

Posted on 2020-02-07 | In linux

install dependencies first

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

this pack may not necessary
yum install libffi-devel -y

download & compile

1
2
3
4
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
cd Python-3.7.6
./configure
make&&make install

modify default setting

python3.7 locate in /usr/local/bin in default
we need to change default python2.7 to python3.7

1
2
3
4
# backup
mv /usr/bin/python /usr/bin/python.bak
# soft link
ln -s /usr/local/bin/python3 /usr/bin/python

modify pip

1
2
3
4
# backup
mv /usr/bin/pip /usr/bin/pip.bak
# soft link
ln -s /usr/local/bin/pip3 /usr/bin/pip

modify yum setting

yum not support python3, so we need point to python2 manually.

vi /usr/libexec/urlgrabber-ext-down
20200207174547.jpg

vi /usr/bin/yum
20200207175001.jpg

modify the first line to #! /usr/bin/python2.7

https://blog.csdn.net/u013214212/article/details/81540840

Switch python/ node in mac

Posted on 2020-02-06 | In linux

node switch

when npm install error happen
check whether the web problem or the node version problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
node --version
npm cache clean -f
npm install -g n

# switch
n
# delete
n rm

# node version
n latest
n stable
n lts

https://stackoverflow.com/questions/32791657/node-gyp-rebuild-build-error-make-failed-npm-install
https://segmentfault.com/q/1010000009734734
https://blog.csdn.net/weixin_38190050/article/details/99644735

install python3

brew install python3

path in different way

origin path
default(2.7) /System/Library/Frameworks/Python.framework/Versions/2.7
brew(2.7/3.x) /usr/local/Cellar/python
pkg(3.x) /Library/Frameworks/Python.framework/Versions/3.x

enviroment setting

vi ~/.bash_profile

1
2
3
4
5
6
7
# Setting PATH for Python 2.7
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

# Setting PATH for Python 3.7.6
PATH="/usr/local/Cellar/python/3.7.6_1/bin:${PATH}"

export PATH

vi ~/.bashrc

1
2
3
alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
alias python3='/usr/local/Cellar/python/3.7.6_1/bin/python3.7'
alias python=python3

source ~/.bash_profile
source ~/.bashrc

https://blog.csdn.net/u014259820/article/details/81023224

Hello RediSearch

Posted on 2020-01-21 | Edited on 2020-09-17 | In search

install

1
2
docker pull redislabs/redisearch:latest
docker run --name redisearch -d -p 6379:6379 redislabs/redisearch:latest

dependency

1
2
3
4
5
6
7
<dependencies>
<dependency>
<groupId>com.redislabs</groupId>
<artifactId>jredisearch</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>

create client

Initializing the client with JedisPool:

1
Client client = new Client("testing", "localhost", 6379);

Initializing the client with JedisSentinelPool:

1
2
3
4
5
6
7
8
9
10
private static final String MASTER_NAME = "mymaster";
private static final Set<String> sentinels;
static {
sentinels = new HashSet();
sentinels.add("localhost:7000");
sentinels.add("localhost:7001");
sentinels.add("localhost:7002");
}
...
Client client = new Client("testung", MASTER_NAME, sentinels);

create schema

1
2
3
4
5
6
7
8
// Create schema
Schema sc = new Schema().addTextField("name", 1.0)
.addNumericField("age")
.addTagField("job", ",")
.addSortableTextField("welfare", 1.0)
.addSortableNumericField("income")
.addSortableTagField("dream", ",");
client.createIndex(sc, Client.IndexOptions.Default());

adding documents

1
2
3
4
5
6
7
8
9
// Create document
Map<String, Object> fields = new HashMap<>();
fields.put("name", "hello world");
fields.put("age", 45);
fields.put("job", "programmer");
fields.put("welfare", "996");
fields.put("income", "3000");
fields.put("dream", "handsome, rich");
client.addDocument("doc1", fields);

search

1
2
3
4
5
// actual search
Query q = new Query("hello world")
.addFilter(new Query.NumericFilter("age", 0, 1000))
.limit(0,5);
SearchResult res = client.search(q);
1
2
3
4
5
6
7
// aggregation query
AggregationBuilder r = new AggregationBuilder("hello")
.apply("@income", "k")
.groupBy("@job", Reducers.avg("@k").as("avgIncome"))
.filter("@avgIncome>=2")
.sortBy(10, SortedField.asc("@dream"));
AggregationResult res = client.aggregate(r);

https://github.com/RediSearch/RediSearch
https://github.com/RediSearch/JRediSearch

Deploy php in docker

Posted on 2019-12-15 | Edited on 2020-06-20 | In linux

Clone project

git clone https://github.com/BurningBright/minishowcase
https://github.com/BurningBright/minishowcase

Read more »
1…789…29

Leon

282 posts
20 categories
58 tags
GitHub
Links
  • clock
  • typing-cn
  • mathjax
  • katex
  • cron
  • dos
  • keyboard
  • regex
  • sql
  • toy
© 2017 – 2024 Leon
Powered by Hexo v3.9.0
|
Theme – NexT.Muse v7.1.2