NutzCN Logo
问答 Redis 数据删除错误
发布于 3309天前 作者 Rekoe 4044 次浏览 复制 上一个帖子 下一个帖子
标签: redis

添加数据到redis

void putEntity(String cacheName, String key, T entity) {
		if (DBProxy.DEBUG) {
			log.debugf("putEntity CacheName=%s, KEY=%s", cacheName, key);
		}
		byte[] data = getSerializer().from(entity);
		try (Jedis jedis = jedisPool.getResource()) {
			jedis.hset(cacheName.getBytes(), key.getBytes(), data);
		} finally {
		}
	}

删除方法

	void deleteEntity(String cacheName, String key) {
		if (DBProxy.DEBUG) {
			log.debugf("deleteEntity CacheName=%s, KEY=%s", cacheName, key);
		}
		try (Jedis jedis = jedisPool.getResource()) {
			jedis.zrem(cacheName.getBytes(), key.getBytes());
		} finally {
		}
	}

错误

2015-12-01 14:44:33,056 [DEBUG][com.myapp.cache.dao.impl.provider.RedisDaoCacheProvider] - deleteEntity CacheName=1234567890:UserEntitycache:key:class:key2obj, KEY=bc7da432da3f46f2a3b887b276d24d31
2015-12-01 14:44:33,060 [ERROR][org.nutz.mvc.impl.NutLoading] - Error happend during start serivce!
redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
	at redis.clients.jedis.Protocol.processError(Protocol.java:117)
	at redis.clients.jedis.Protocol.process(Protocol.java:151)
	at redis.clients.jedis.Protocol.read(Protocol.java:205)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
	at redis.clients.jedis.Connection.getIntegerReply(Connection.java:222)
	at redis.clients.jedis.BinaryJedis.zrem(BinaryJedis.java:1489)
	at com.myapp.cache.dao.impl.provider.RedisDaoCacheProvider.deleteEntity(RedisDaoCacheProvider.java:46)
	at com.myapp.cache.dao.impl.provider.AbstractDaoCacheProvider.delete(AbstractDaoCacheProvider.java:65)
	at com.myapp.proxy.database.DBProxy.delete(DBProxy.java:154)
	at com.myapp.AppSetup.init(AppSetup.java:43)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:270)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:119)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
2015-12-01 14:44:33,075 [ERROR][org.nutz.mvc.impl.NutLoading] - try to depose ioc
十二月 01, 2015 2:44:33 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:988)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:164)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:133)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
	at redis.clients.jedis.Protocol.processError(Protocol.java:117)
	at redis.clients.jedis.Protocol.process(Protocol.java:151)
	at redis.clients.jedis.Protocol.read(Protocol.java:205)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
	at redis.clients.jedis.Connection.getIntegerReply(Connection.java:222)
	at redis.clients.jedis.BinaryJedis.zrem(BinaryJedis.java:1489)
	at com.myapp.cache.dao.impl.provider.RedisDaoCacheProvider.deleteEntity(RedisDaoCacheProvider.java:46)
	at com.myapp.cache.dao.impl.provider.AbstractDaoCacheProvider.delete(AbstractDaoCacheProvider.java:65)
	at com.myapp.proxy.database.DBProxy.delete(DBProxy.java:154)
	at com.myapp.AppSetup.init(AppSetup.java:43)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:270)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:119)
	... 15 more
3 回复
com.myapp.cache.dao.impl.provider.RedisDaoCacheProvider.deleteEntity(RedisDaoCacheProvider.java:46)

这是"面"的版本? 我在daocache里面没找到zrem调用, 而且daocache里面的redis实现是走hash set,而不是zset


改成hdel 方法后好了

添加回复
请先登陆
回到顶部