Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

Why I am getting null pointer exception when using hashoperations in redis with java?

$
0
0
public class CacheLoadTester {    String c;    private int redisPort=6379;    private String redisHost="localhost";    private String redisDir="J:/resources";    private String redisSize="128M";    private String redisSnapshot="300 50";    private RedisServer redisServer;    private RedisTemplate<String, Object> template=new RedisTemplate<>();    private HashOperations<String, String, Object> hashOperations;    public static void main(String[] args) {    CacheLoadTester cacheLoadTester=new CacheLoadTester();      cacheLoadTester.template.setConnectionFactory(new LettuceConnectionFactory(cacheLoadTester.redisHost, cacheLoadTester.redisPort));    cacheLoadTester.template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());    cacheLoadTester.redisServer=RedisServer.builder().port(cacheLoadTester.redisPort)            .setting("save " + cacheLoadTester.redisSnapshot)            .setting("dbfilename redisdump.rdb")            .setting("dir " + cacheLoadTester.redisDir)            .setting("maxmemory " +cacheLoadTester.redisSize)            .setting("maxmemory-policy allkeys-lru")            .build();    cacheLoadTester.redisServer.start();    System.out.println("started");    try {    cacheLoadTester.hashOperations = cacheLoadTester.template.opsForHash();    cacheLoadTester.hashOperations.put(LOADTESTER_CACHE, "jk","jk");    }    catch(Exception e) {         e.printStackTrace();    }    enter code here    finally {        System.out.println(cacheLoadTester.c);    cacheLoadTester.redisServer.stop();    }    }

I am using this for testing purpose to put some keys and values in redis cache and retrieving them. But I am getting null pointer exception when I use this line- "cacheLoadTester.hashOperations.put(LOADTESTER_CACHE, "jk","jk");"


Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>