我能有一组与同名置盘?

问题描述 投票:0回答:1

是什么给定的代码的输出是什么?可以Jedis容纳不同类型的的数据库,但具有相同名称的两个数据集?如果不是,在印刷生产线,究竟会j.get回报?被j.set铸成j.hset?

我是新来的Redis数据库

public static void main(String[] args) {
    Jedis j = new Jedis("slc09sro");
    try {
        j.set("alex1", "1");
    }
    catch (Exception e){}
    try {
        j.set("alex1", "2");
    } 
    catch (Exception e){}
    try {
        j.hset("alex1", "3", "4");
    } 
    catch (Exception e){}
    System.out.println(j.get("alex1"));
    j.close;
}
java database redis jedis
1个回答
2
投票

同时试图使用hset方法你的榜样将失败。简单的例子,没有必要的Java:

$ redis-cli 
127.0.0.1:6379> set alex1 1
OK
127.0.0.1:6379> set alex1 2
OK
127.0.0.1:6379> hset alex1 3 4
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> get alex1
"2"
127.0.0.1:6379> 

这是因为关键alex1拥有一个字符串值,而不是一个哈希值。不成功的HSET呼叫后,项仍来自最后SET电话不变,因而包含字符串值"2"

Redis command reference

© www.soinside.com 2019 - 2024. All rights reserved.