![](/img/trans.png)
[英]Spring dependency injection not finding repository bean after adding spring-boot-starter-data-redis dependency
[英]How to get a Jedis instance in spring-boot-starter-data-redis?
這個例子正確嗎?
連接池是否自動關閉? 需要獲取Jedis實例才能運行GEO
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
@Service
public class RedisGeo {
@Autowired
private RedisConnectionFactory redisConnectionFactory;
private void test() {
RedisConnection redisConnection = redisConnectionFactory.getConnection();
Jedis jedis = (Jedis) redisConnection.getNativeConnection();
System.out.println(jedis);
jedis.geoadd("demo",
91.118970,
29.654210,
"dc");
}
}
您不需要本地Jedis實例即可進行地理操作。 RedisTemplate具有一個opsForGeo()
方法,該方法返回GeoOperations
接口。
所以你可以做
redistTemplate.opsForGeo().add("demo", new Point(91.118970,29.654210), "dc");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.