Skip to content

Latest commit

 

History

History
138 lines (105 loc) · 3.76 KB

redis.md

File metadata and controls

138 lines (105 loc) · 3.76 KB

redis

Introduction

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, and sorted sets.

So what can I do with Redis?

All of the following redis features are supported:

  • Sorting
  • Connection handling
  • Commands operating on any kind of values
  • Commands operating on string values
  • Commands operating on hashes
  • Commands operating on lists
  • Commands operating on sets
  • Commands operating on sorted sets
  • Transactions
  • Pipelining
  • Publish/Subscribe
  • Persistence control commands
  • Remote server control commands
  • Connection pooling
  • Sharding (MD5, MurmurHash)
  • Key-tags for sharding
  • Sharding with pipelining
  • Scripting with pipelining
  • Redis Cluster

Hunt framework Redis

Configuration

The Redis configuration for your application is located in the config/application.conf configuration file. Within this file, you will see a redis array containing the Redis servers utilized by your application:

# Redis
redis.enabled = true
redis.prefix = app:
redis.host = 127.0.0.1
redis.port = 6379
redis.database = 0
redis.password = 
redis.timeout = 0

# Redis pool
redis.pool.enabled = false
redis.pool.maxWait = 5000
redis.pool.maxIdle = 50
redis.pool.minIdle = 5

# Redis cluster
redis.cluster.enabled = false
redis.cluster.nodes = 127.0.0.1:6379, 127.0.0.1:6380, 127.0.0.1:6381

The default server configuration should suffice for development. However, you are free to modify this array based on your environment. Each Redis server defined in your configuration file is required to have a name, host, and port.

use example

hunt framework redis you can you use like example below:

import hunt.framework;
import hunt.redis.Redis;
void test()
{
    Redis redis = Application.instance().redis();
    scope(exit) redis.close();
    
    redis.set("name","john");
    string name = redis.get("name");
}

Custom using Hunt Redis

To use it just:

import hunt.redis;

void main()
{
    string password="123456";

    Redis redis = new Redis("localhost", "6379");

    redis.auth(password);  // if has password ,use auth() method

    redis.set("foo", "bar");
    string value = redis.get("foo");

    import std.stdio : writeln;

    writeln(value);
}

Redis Cluster

Redis cluster specification (still under development) is implemented

Set!(HostAndPort) redisClusterNodes = new HashSet!(HostAndPort)();
//Redis Cluster will attempt to discover cluster nodes automatically
redisClusterNodes.add(new HostAndPort("127.0.0.1", 7379));
RedisCluster rc = new RedisCluster(redisClusterNodes);
rc.set("foo", "bar");
string value = rc.get("foo");

Hunt-redis functions

All redis functions you can see :

Hunt-redis functions