Skip to content

Commit 846fa0a

Browse files
uglidejoshrotenbergsazzad16
authored
Mkdocs unify docs (#3999)
* basic mkdocs setup and workflow * rename workflow * copy lettuce * add index * integrate current wiki and docs content * integrate current wiki and docs content * add a few more links * fix branch in actions * remove redundant getting started and maven docs * Revert jedis-maven doc deletion * Exclude Dockerfile and css from spellcheck * Fix spelling * Remove assets from spellcheck-settings.yml * Add build for dev branch * Another attempt to fix spellcheck * Add some words to wordlist * Add more words to wordlist * Update .github/workflows/docs.yml Co-authored-by: M Sazzadul Hoque <[email protected]> --------- Co-authored-by: Josh Rotenberg <[email protected]> Co-authored-by: M Sazzadul Hoque <[email protected]>
1 parent e30dc29 commit 846fa0a

File tree

12 files changed

+287
-1
lines changed

12 files changed

+287
-1
lines changed

.github/spellcheck-settings.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ matrix:
2525
- img
2626
sources:
2727
- '*.md'
28-
- 'docs/**'
28+
- 'docs/*.md'
29+

.github/wordlist.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
!!!Spelling check failed!!!
22
APM
33
ARGV
4+
BaseObjectPoolConfig
45
BFCommands
56
BitOP
67
BitPosParams
@@ -16,6 +17,7 @@ ClusterPipeline
1617
ClusterPubSub
1718
ConnectionPool
1819
CoreCommands
20+
Dockerfile
1921
EVAL
2022
EVALSHA
2123
Failback
@@ -46,6 +48,7 @@ JedisCluster
4648
JedisConnectionException
4749
JedisPool
4850
JedisPooled
51+
JedisPubSub
4952
JedisShardInfo
5053
ListPosition
5154
Ludovico
@@ -174,6 +177,7 @@ incr
174177
incrBy
175178
incrByFloat
176179
ini
180+
io
177181
json
178182
keyslot
179183
keyspace
@@ -198,6 +202,9 @@ mget
198202
microservice
199203
microservices
200204
millisecondsTimestamp
205+
MkDocs
206+
mkdocs
207+
md
201208
mset
202209
msetnx
203210
multikey
@@ -224,6 +231,7 @@ pubsub
224231
punsubscribe
225232
py
226233
pypi
234+
PoolConfig
227235
quickstart
228236
readonly
229237
readwrite
@@ -234,10 +242,12 @@ reinitialization
234242
renamenx
235243
replicaof
236244
repo
245+
README
237246
rpush
238247
rpushx
239248
runtime
240249
sadd
250+
SafeEncoder
241251
scard
242252
scoreMembers
243253
sdiffstore
@@ -260,6 +270,7 @@ strlen
260270
stunnel
261271
subcommands
262272
sunionstore
273+
pipelining
263274
thevalueofmykey
264275
timeseries
265276
toctree
@@ -311,3 +322,4 @@ zrevrangeByScore
311322
zrevrangeByScoreWithScores
312323
zrevrangeWithScores
313324
zunionstore
325+
yml

.github/workflows/docs.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Publish Docs
2+
on:
3+
push:
4+
branches: ["master"]
5+
permissions:
6+
contents: read
7+
pages: write
8+
id-token: write
9+
concurrency:
10+
group: "pages"
11+
cancel-in-progress: false
12+
jobs:
13+
build-and-deploy:
14+
concurrency: ci-${{ github.ref }}
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: 3.9
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install mkdocs mkdocs-material pymdown-extensions mkdocs-macros-plugin
25+
- name: Build docs
26+
run: |
27+
mkdocs build -d docsbuild
28+
- name: Setup Pages
29+
uses: actions/configure-pages@v3
30+
- name: Upload artifact
31+
uses: actions/upload-pages-artifact@v1
32+
with:
33+
path: 'docsbuild'
34+
- name: Deploy to GitHub Pages
35+
id: deployment
36+
uses: actions/deploy-pages@v2

docs/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM squidfunk/mkdocs-material
2+
RUN pip install mkdocs-macros-plugin
3+
RUN pip install mkdocs-glightbox

docs/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Jedis Documentation
2+
3+
This documentation uses [MkDocs](https://www.mkdocs.org/) to generate the static site.
4+
5+
See [mkdocs.yml](../mkdocs.yml) for the configuration.
6+
7+
To develop the documentation locally, you can use the included [Dockerfile](Dockerfile) to build a container with all the
8+
dependencies, and run it to preview your changes:
9+
10+
```bash
11+
# in docs/
12+
docker build -t squidfunk/mkdocs-material .
13+
# cd ..
14+
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material
15+
```

docs/advanced-usage.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Advanced Usage
2+
3+
## Transactions
4+
5+
To do transactions in Jedis, you have to wrap operations in a transaction block, very similar to pipelining:
6+
7+
```java
8+
jedis.watch (key1, key2, ...);
9+
Transaction t = jedis.multi();
10+
t.set("foo", "bar");
11+
t.exec();
12+
```
13+
14+
Note: when you have any method that returns values, you have to do like this:
15+
16+
17+
```java
18+
Transaction t = jedis.multi();
19+
t.set("fool", "bar");
20+
Response<String> result1 = t.get("fool");
21+
22+
t.zadd("foo", 1, "barowitch"); t.zadd("foo", 0, "barinsky"); t.zadd("foo", 0, "barikoviev");
23+
Response<Set<String>> sose = t.zrange("foo", 0, -1); // get the entire sortedset
24+
t.exec(); // dont forget it
25+
26+
String foolbar = result1.get(); // use Response.get() to retrieve things from a Response
27+
int soseSize = sose.get().size(); // on sose.get() you can directly call Set methods!
28+
29+
// List<Object> allResults = t.exec(); // you could still get all results at once, as before
30+
```
31+
Note that a Response Object does not contain the result before t.exec() is called (it is a kind of a Future). Forgetting exec gives you exceptions. In the last lines, you see how transactions/pipelines were dealt with before version 2. You can still do it that way, but then you need to extract objects from a list, which contains also Redis status messages.
32+
33+
Note 2: Redis does not allow to use intermediate results of a transaction within that same transaction. This does not work:
34+
35+
```java
36+
// this does not work! Intra-transaction dependencies are not supported by Redis!
37+
jedis.watch(...);
38+
Transaction t = jedis.multi();
39+
if(t.get("key1").equals("something"))
40+
t.set("key2", "value2");
41+
else
42+
t.set("key", "value");
43+
```
44+
45+
However, there are some commands like setnx, that include such a conditional execution. Those are of course supported within transactions. You can build your own customized commands using EVAL / LUA scripting.
46+
47+
48+
## Pipelining
49+
50+
Sometimes you need to send a bunch of different commands. A very cool way to do that, and have better performance than doing it the naive way, is to use pipelining. This way you send commands without waiting for response, and you actually read the responses at the end, which is faster.
51+
52+
Here is how to do it:
53+
54+
```java
55+
Pipeline p = jedis.pipelined();
56+
p.set("fool", "bar");
57+
p.zadd("foo", 1, "barowitch"); p.zadd("foo", 0, "barinsky"); p.zadd("foo", 0, "barikoviev");
58+
Response<String> pipeString = p.get("fool");
59+
Response<Set<String>> sose = p.zrange("foo", 0, -1);
60+
p.sync();
61+
62+
int soseSize = sose.get().size();
63+
Set<String> setBack = sose.get();
64+
```
65+
For more explanations see code comments in the transaction section.
66+
67+
68+
## Publish/Subscribe
69+
70+
To subscribe to a channel in Redis, create an instance of JedisPubSub and call subscribe on the Jedis instance:
71+
72+
```java
73+
class MyListener extends JedisPubSub {
74+
public void onMessage(String channel, String message) {
75+
}
76+
77+
public void onSubscribe(String channel, int subscribedChannels) {
78+
}
79+
80+
public void onUnsubscribe(String channel, int subscribedChannels) {
81+
}
82+
83+
public void onPSubscribe(String pattern, int subscribedChannels) {
84+
}
85+
86+
public void onPUnsubscribe(String pattern, int subscribedChannels) {
87+
}
88+
89+
public void onPMessage(String pattern, String channel, String message) {
90+
}
91+
}
92+
93+
MyListener l = new MyListener();
94+
95+
jedis.subscribe(l, "foo");
96+
```
97+
Note that subscribe is a blocking operation because it will poll Redis for responses on the thread that calls subscribe. A single JedisPubSub instance can be used to subscribe to multiple channels. You can call subscribe or psubscribe on an existing JedisPubSub instance to change your subscriptions.
98+
99+
100+
### Monitoring
101+
102+
To use the monitor command you can do something like the following:
103+
104+
```java
105+
new Thread(new Runnable() {
106+
public void run() {
107+
Jedis j = new Jedis("localhost");
108+
for (int i = 0; i < 100; i++) {
109+
j.incr("foobared");
110+
try {
111+
Thread.sleep(200);
112+
} catch (InterruptedException e) {
113+
}
114+
}
115+
j.disconnect();
116+
}
117+
}).start();
118+
119+
jedis.monitor(new JedisMonitor() {
120+
public void onCommand(String command) {
121+
System.out.println(command);
122+
}
123+
});
124+
```
125+
126+
## Miscellaneous
127+
128+
### A note about String and Binary - what is native?
129+
130+
Redis/Jedis talks a lot about Strings. And here [[http://redis.io/topics/internals]] it says Strings are the basic building block of Redis. However, this stress on strings may be misleading. Redis' "String" refer to the C char type (8 bit), which is incompatible with Java Strings (16-bit). Redis sees only 8-bit blocks of data of predefined length, so normally it doesn't interpret the data (it's "binary safe"). Therefore in Java, byte[] data is "native", whereas Strings have to be encoded before being sent, and decoded after being retrieved by the SafeEncoder. This has some minor performance impact.
131+
In short: if you have binary data, don't encode it into String, but use the binary versions.
132+
133+
### A note on Redis' master/slave distribution
134+
135+
A Redis network consists of redis servers, which can be either masters or slaves. Slaves are synchronized to the master (master/slave replication). However, master and slaves look identical to a client, and slaves do accept write requests, but they will not be propagated "up-hill" and could eventually be overwritten by the master. It makes sense to route reads to slaves, and write demands to the master. Furthermore, being a slave doesn't prevent from being considered master by another slave.
381 Bytes
Loading

docs/assets/images/logo.png

43.3 KB
Loading

docs/css/extra.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* extra.css */
2+
.md-header {
3+
background-color: #FB2A2C;
4+
}

docs/faq.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Frequently Asked Questions
2+
3+
## If you get `java.net.SocketTimeoutException: Read timed out` exception
4+
5+
Try setting own `timeout` value when constructing `JedisPool` using the following constructor:
6+
```java
7+
JedisPool(GenericObjectPoolConfig poolConfig, String host, int port, int timeout)
8+
```
9+
where `timeout` is given as milliseconds.
10+
11+
Default `timeout` value is **2 seconds**.
12+
13+
## JedisPool blocks after getting 8 connections
14+
15+
JedisPool defaults to 8 connections, you can change this in the PoolConfig:
16+
17+
```java
18+
JedisPoolConfig poolConfig = new JedisPoolConfig();
19+
poolConfig.setMaxTotal(maxTotal); // maximum active connections
20+
poolConfig.setMaxIdle(maxIdle); // maximum idle connections
21+
```
22+
23+
Take into account that `JedisPool` inherits commons-pool [BaseObjectPoolConfig](https://commons.apache.org/proper/commons-pool/api-2.3/org/apache/commons/pool2/impl/BaseObjectPoolConfig.html) which has a lot of configuration parameters.
24+
We've set some defined ones which suit most of the cases. In case, you experience [issues](https://github.com/xetorthio/jedis/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+JedisPool) tuning these parameters may help.
25+
26+
## How to configure the buffer size of socket(s)
27+
28+
The buffer size of all Jedis sockets in an application can be configured through system property.
29+
30+
Buffer size of input stream can be configured by setting `jedis.bufferSize.input` or `jedis.bufferSize` system property.
31+
Buffer size of output stream can be configured by setting `jedis.bufferSize.output` or `jedis.bufferSize` system property.
32+
If you want to set the buffer size of both input and output stream to same value, you can just set `jedis.bufferSize`.
33+
34+
Note: This feature is available since Jedis 4.2.0.
35+
36+
## How to avoid cluster initialization error
37+
38+
As of Jedis 4.0.0, a `JedisClusterOperationException` is raised with the message `Could not initialize cluster slots cache.` when the cluster initialization process fails.
39+
40+
Should you would want to avoid this error (for example, creating `JedisConnectionFactory` to an unavailable cluster for a spring-data-redis `Bean`), set the system property `jedis.cluster.initNoError` to any value.
41+
In the console, add the option `-Djedis.cluster.initNoError`.
42+
In an application, `System.setProperty("jedis.cluster.initNoError", "");` can be set before creating any cluster object.
43+
44+
Note: This feature is available since Jedis 4.4.2.

0 commit comments

Comments
 (0)