# 8.4 Using RedisPlugin in a Non-Web Environment
RedisPlugin can also be used in non-web environments. You just need to include jfinal.jar
and call the redisPlugin.start()
method once. Below is a code example:
public class RedisTest {
public static void main(String[] args) {
RedisPlugin rp = new RedisPlugin("myRedis", "localhost");
// The only difference from web usage is that you need to call the start() method here
rp.start();
Redis.use().set("key", "value");
Redis.use().get("key");
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
In this example, the RedisPlugin
is initialized with the name "myRedis" and is configured to connect to a Redis server running on localhost
. The start()
method is explicitly called to initiate the plugin, which is the only step not typically necessary in a web environment. After that, you can use Redis.use()
to interact with the Redis server as you would in a web application.