@Yano
2016-07-05T19:42:17.000000Z
字数 1520
阅读 2146
Redis
数据库
RE
mote DI
ctionary S
erver (Redis)内存
、亦可持久化
(磁盘)原子性
wget http://download.redis.io/releases/redis-2.8.17.tar.gz
tar xzf redis-2.8.17.tar.gz
cd redis-2.8.17
make
启动redis服务
cd src
./redis-server
启动redis客户端
cd src
./redis-cli
string是redis最基本的类型,你可以理解成与Memcached一模一样的类型,一个key对应一个value。
string类型是二进制安全
的。意思是redis的string可以包含任何数据。比如jpg图片或者序列化的对象 。
string类型是Redis最基本的数据类型,一个键最大能存储512MB。
127.0.0.1:6379> set name yano
OK
127.0.0.1:6379> get name
"yano"
127.0.0.1:6379> HMSET yano_hash name "redis" description "I like redis, it's cool~"
OK
127.0.0.1:6379> HGETALL yano_hash
1) "name"
2) "redis"
3) "description"
4) "I like redis, it's cool~"
127.0.0.1:6379> LPUSH yano_list redis
(integer) 1
127.0.0.1:6379> LPUSH yano_list mysql
(integer) 2
127.0.0.1:6379> LPUSH yano_list memcached
(integer) 3
127.0.0.1:6379> LRANGE yano_list 0 2
1) "memcached"
2) "mysql"
3) "redis"
127.0.0.1:6379> SADD yano_set redis
(integer) 1
127.0.0.1:6379> SADD yano_set mysql
(integer) 1
127.0.0.1:6379> SADD yano_set memcached
(integer) 1
127.0.0.1:6379> SMEMBERS yano_set
1) "mysql"
2) "memcached"
3) "redis"
127.0.0.1:6379> ZADD sorted_set 3 redis
(integer) 1
127.0.0.1:6379> ZADD sorted_set 2 mysql
(integer) 1
127.0.0.1:6379> ZADD sorted_set 1 memcached
(integer) 1
127.0.0.1:6379> ZRANGE sorted_set 0 10
1) "memcached"
2) "mysql"
3) "redis"
import redis.clients.jedis.Jedis;
public class RedisJava {
public static void main(String[] args) {
Jedis jedis = new Jedis("120.55.112.128", 6379);
jedis.auth("123456");
jedis.set("yano", "hello");
System.out.println(jedis.get("yano"));
}
}