zoukankan      html  css  js  c++  java
  • redis简单测试用例(内存不足,可以使用redis)

    Redis本质上是一个Key-Value类型的内存数据库,很像memcached,听说他的性能远高于memcached,所以想自己搞个玩下。看到底有什么好处。

    在windows下使用redis首先要下载一个。非官方版 http://code.google.com/p/servicestack/wiki/RedisWindowsDownload

    下载完的Redis文件夹有以下几个文件 redis-server.exe:服务程序 指定redis的配置文件,如没有指定,则使用默认设置

    在控制台下运行,输入cmd再跳到你redis的目录下

    E:
    edis-2.0.2>redis-server.exe redis.conf

    或者在文件夹下面直接点击redis-server.exe

    自己上网下载redis-2.0.0.jar

    以下是自己写的一个简单测试程序:

    import java.util.HashMap; 
    import java.util.List; 
    import java.util.Map; 
    import redis.clients.jedis.Jedis; 
    public class JedisDemo {  
    
        @SuppressWarnings("unchecked") 
        public void testDeom(){  
            Jedis  redis = new Jedis ("localhost",6379);//连接redis 
    
            //hset key field value将哈希表key中的域field的值设为value。 
            redis.hset("yyweb", "music", "m.yy.com"); 
            redis.hset("yyweb", "mall", "mai.yy.com"); 
            redis.hset("yyweb", "duowan", "www.duowan.com"); 
            //返回哈希表key中,一个或多个给定域的值。 
            List list = redis.hmget("yyweb","music","mall","duowan"); 
            for(int i=0;i<list.size();i++){ 
                System.out.println(list.get(i)); 
            } 
    
            //同时将多个field - value(域-值)对设置到哈希表key中。 
            Map map = new HashMap(); 
            map.put("uid", "10000"); 
            map.put("username", "chenxu"); 
            redis.hmset("hash", map); 
            //得到map下面的username的值 
            System.out.println(redis.hget("hash", "username")); 
    
            //HGETALL key返回哈希表key中,所有的域和值。 
            Map<String,String> maps = redis.hgetAll("hash"); 
            for(Map.Entry entry: maps.entrySet()) { 
                 System.out.print(entry.getKey() + ":" + entry.getValue() + "	"); 
            } 
    
        public static void main(String[] args)  throws Exception{         
            JedisDemo jedis = new JedisDemo();  
            jedis.testDeom();  
        }  
    }  
  • 相关阅读:
    leetcode1161 Maximum Level Sum of a Binary Tree
    leetcode1162 As Far from Land as Possible
    leetcode107 Binary Tree Level Order Traversal II
    leetcode100 Same Tree
    spring常用注解的使用
    内部bean和级联属性的用法
    spring中ref标签的用法
    spring的依赖注入
    spring中的bean标签详解
    spring中BeanFactory和ApplicationContext的区别
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205453.html
Copyright © 2011-2022 走看看