Redis初探

6 篇文章 0 订阅
6 篇文章 0 订阅
 
Redis初探
 
 
Redis is an advanced key-value store. It is similar to memcached but the dataset is not volatile, and values can be strings, exactly like in memcached, but also lists, sets, and ordered sets. All this data types can be manipulated with atomic operations to push/pop elements, add/remove elements, perform server side union, intersection, difference between sets, and so forth. Redis supports different kind of sorting abilities.
 
 
1. 启动server
eg: ./redis-server redis.conf
帮助可以为(因为没有--help):

2. 使用client
eg: ./redis-cli -h 127.0.0.1 -p 6379 -n 0
帮助可以为(因为没有--help):./redis-cli -h
 
3. redis.conf (redis-server 需要的配置文件)  

daemonize no    // 是否w为daemon进程,如果是将把pid写pidfile(为shutdown保存pid),

port 6379      // 端口不设置, 默认为6379
 
bind 127.0.0.1  // ip不设置, 默认为0.0.0.0  

timeout 300

loglevel debug

logfile stdout

databases 16    // 分成16个库,dbid为0到16-1
 
################################ SNAPSHOTTING  #################################
save <seconds> <changes>    // 多个save的维度: seconds,changes是与的关系, 多个save是或的关系

rdbcompression yes

dbfilename dump.rdb    // rdb文件名  

dir ./                 // rdb文件工作路径
 
################################# REPLICATION #################################
 
slaveof <masterip> <masterport>     //  复制来源端ip port  
 
masterauth <master-password>
 
################################## SECURITY ###################################
 
requirepass foobared
 
################################### LIMITS ####################################
 
maxclients 128
 
maxmemory <bytes>        //  最大内存,超出后将不能增加数据  
 
// ...




4. java client libraries projects example:

/**
 *
 */
package redis;

import org.jredis.ClientRuntimeException;
import org.jredis.JRedis;
import org.jredis.ProviderException;
import org.jredis.RedisException;
import org.jredis.ri.alphazero.JRedisClient;

/**
 * Redis First example
 *
 * @author yangwm Nov 17, 2010 3:21:36 PM
 */
public class RedisFirst {
    public static final String host = "127.0.0.1";
    public static final int port = 6379;

    public static void main(String[] args) {
        try {
            // key in your DB 0.
            JRedis  jredis = new JRedisClient(host, port, "password", 0);
            jredis.ping();
           
            jredis.set("yangwmTest", "yangwTestValue123456");
            System.out.println(new String(jredis.get("yangwmTest")));
           
            jredis.quit();
        } catch (RedisException error) {
            error.printStackTrace();
        } catch (ProviderException bug) {
            System.out.format("Oh no, an 'un-documented feature':  %s/nKindly report it.", bug.getMessage());
        } catch (ClientRuntimeException problem) {
            System.out.format("%s/n", problem.getMessage());
        }
    }
   
}


 
学习参考资料: 
https://github.com/xetorthio/jedis

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值