Redis and Cache
Redis and Cache can be combined to use the Redis service very conveniently. The Redis object obtains the Cache object through the use() method. The Cache object provides a rich API for using the Redis service. The following are specific usage examples. :
public void redisDemo() {
// Get the Redis Cache object named bbs Cache bbsCache = Redis.use("bbs"); bbsCache.set("key", " value"); bbsCache.get("key");
// Get the Redis Cache object named news Cache newsCache = Redis.use("news"); newsCache.set("k", " v"); newsCache.get("k");
// The first created Cache will become the main Cache, so you can omit the cacheName parameter to obtain bbsCache = Redis.use(); // Main The cache can omit the cacheName parameter bbsCache.set("jfinal", "awesome");
}
// Get the Redis Cache object named bbs Cache bbsCache = Redis.use("bbs"); bbsCache.set("key", " value"); bbsCache.get("key");
// Get the Redis Cache object named news Cache newsCache = Redis.use("news"); newsCache.set("k", " v"); newsCache.get("k");
// The first created Cache will become the main Cache, so you can omit the cacheName parameter to obtain bbsCache = Redis.use(); // Main The cache can omit the cacheName parameter bbsCache.set("jfinal", "awesome");
}
In the above code, "bbs" and "news" are used as parameters of the use method respectively. Two Cache objects are obtained, and you can use these two objects to operate their corresponding Redis servers.
Normally, only one RedisPlugin will be created to connect to a redis server, just use Redis.use().set(key, value).