GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

get(ExecutionIdentifier)   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
package io.mcarle.sciurus.cache.redis;
0 ignored issues
show
Code Smell introduced by
It is a best practice to supply a copyright/licence header in your code. Your organisation probably has a template for that.
Loading history...
2
3
import io.lettuce.core.RedisClient;
4
import io.lettuce.core.SetArgs;
5
import io.lettuce.core.api.StatefulRedisConnection;
6
import io.lettuce.core.api.sync.RedisCommands;
7
import io.mcarle.sciurus.ExecutionIdentifier;
8
import io.mcarle.sciurus.cache.CustomCache;
9
10
import java.io.Serializable;
11
import java.time.Duration;
12
13
public class RedisCache implements CustomCache {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
14
15
    private RedisClient redisClient;
0 ignored issues
show
Coding Style introduced by
Make this line start at column 3.
Loading history...
16
    private StatefulRedisConnection<String, RedisData> connection;
17
    private RedisCommands<String, RedisData> syncCommands;
18
19 1
    public RedisCache(RedisClient redisClient) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
20 1
        this.redisClient = redisClient;
0 ignored issues
show
Coding Style introduced by
Make this line start at column 5.
Loading history...
21 1
        this.connection = redisClient.connect(new RedisJsonCodec());
22 1
        this.syncCommands = connection.sync();
23 1
    }
24
25
    @Override
26
    public Object get(ExecutionIdentifier executionIdentifier) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
27 1
        RedisData redisData = syncCommands.get(getKey(executionIdentifier));
0 ignored issues
show
Coding Style introduced by
Make this line start at column 5.
Loading history...
28 1
        if (redisData == null) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
29 1
            return CustomCache.EMPTY;
0 ignored issues
show
Coding Style introduced by
Make this line start at column 7.
Loading history...
30
        } else {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
Coding Style introduced by
Move this "else" keyword to a new dedicated line.
Loading history...
31 1
            return redisData.getCachedValue();
0 ignored issues
show
Coding Style introduced by
Make this line start at column 7.
Loading history...
32
        }
33
    }
34
35
    @Override
36
    public void put(ExecutionIdentifier executionIdentifier, Serializable result, Duration duration) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
37 1
        syncCommands.set(getKey(executionIdentifier), new RedisData(result), SetArgs.Builder.px(duration.toMillis()));
0 ignored issues
show
Coding Style introduced by
Make this line start at column 5.
Loading history...
38 1
    }
39
40
    @Override
41
    public void postDeregister() {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
42 1
        connection.close();
0 ignored issues
show
Coding Style introduced by
Make this line start at column 5.
Loading history...
43 1
        redisClient.shutdown();
44 1
    }
45
46
    private String getKey(ExecutionIdentifier executionIdentifier) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
Comprehensibility introduced by
Private methods that do not access instance data should be made static. This makes the code more readable and may enable the compiler to optimize your code. Consider making getKeystatic.
Loading history...
47 1
        return executionIdentifier.toString() + executionIdentifier.hashCode();
0 ignored issues
show
Coding Style introduced by
Make this line start at column 5.
Loading history...
48
    }
49
}
50