redis第一章

来源:互联网 发布:linux运维工程师是什么 编辑:程序博客网 时间:2024/05/20 09:25

1.首先从网站http://down.51cto.com/data/1004158  下载redis jar包,下载后,解压到某个目录下,点击redis-server.exe

2.

package com.xxx.redis;import redis.clients.jedis.Jedis;import java.util.HashMap;import java.util.List;import java.util.Map;/** * Created with IntelliJ IDEA. * Date: 14-3-2 * Time: 下午10:32 * To change this template use File | Settings | File Templates. */public class ResisDemo {    private void testRedisDemo() {        Jedis jedis = new Jedis("localhost", 6379, 3000);        jedis.hset("zhangshan", "server1", "湖南");        jedis.hset("zhangshan", "server2", "新疆");        jedis.hset("zhangshan", "server3", "北京");        List<String> list = jedis.hmget("zhangshan", "server1", "server2", "server3");        for (String str : list) {            System.out.println(str);        }        Map<String, String> map = new HashMap<String, String>();        map.put("username", "zhangsha");        map.put("password", "123446");        jedis.hmset("map", map);        System.out.println(jedis.hget("map", "username"));        Map<String,String> resultMap=jedis.hgetAll("map");        for(Map.Entry<String,String> entry:resultMap.entrySet()){             System.out.println(entry.getKey()+" "+entry.getValue());        }    }    public static void main(String[] args) {        ResisDemo resisDemo = new ResisDemo();        resisDemo.testRedisDemo();    }}


0 0
原创粉丝点击