BeetleX.Redis and Basic Operation Object Format

Decr

Is a bond key stored digital value minus one.

Key if the key is not present, then the key value of the key will first be initialized to 0, and then perform operations DECR.

If the key value stored in the key can not be interpreted as a number, it returns an error command DECR.

This operation is limited to the value of 64-bit (bit) within the signed digital representation.

var set = await DB.Set("mykey", "10");
var decr = await DB.Decr("mykey");

Decrby

The integer value by subtracting the decrement key stored in key decrement.

If the key key is not present, then the value of the key key will first be initialized to 0, and then execute DECRBY command.

If the key value stored in the key can not be interpreted as a number, then DECRBY command will return an error.

This operation is limited to the value of 64-bit (bit) within the signed digital representation.

var set = await DB.Set("mykey", "10");
var decrby = await DB.Decrby("mykey", 5);

Of the

Delete given one or more key.

Non-existent key will be ignored.

var add = await DB.Set("test", "henryfan");
var del = await DB.Del("test");

Dump

Sequence of a given key, and return the serialized value using the RESTORE command value may be deserialize Redis key.

Generating a sequence of values ​​has the following characteristics:

It has 64-bit checksum for error detection, will first checksum and before performing the RESTORE deserialized.

RDB file encoding formats and values ​​consistent.

RDB version will be encoded in the sequence of values ​​which, if Redis because different versions cause RDB format is not compatible, then this value will be rejected Redis deserialized operation.

Serialization does not include the value of any survival time information.

var add = await DB.Set("test", "henryfan");
var result = await DB.Dump("test");

Exists

Checks if the given key exists.

var add = await DB.Set("aa", "sfsdfsd");
var count = await DB.Exists("aa");
count = await DB.Exists("sdfsdf", "aa");
count = await DB.Exists("sdfsdf", "sdfsdfdsaa");

Expire

For a given key settings survival time (survival time is 0), it will be automatically deleted when the key expires.

In the Redis, key with survival time was called "volatile" (volatile).

Survival time can be removed by using the DEL command to delete the entire key, or by SET and GETSET command overwrites (overwrite), which means that if a command just modify (alter) a key lifetime value rather than with a new key value to replace (replace) it, then the survival time will not be changed.

var add = await DB.Set("mykey", "hello");
var expire = await DB.Expire("mykey", 10);
var ttl = await DB.Ttl("mykey");
add = await DB.Set("mykey", "hello world");
ttl = await DB.Ttl("mykey");

Expireat

And the role of EXPIREAT EXPIRE similar, are used to set the survival time is key.

Except that the time parameter EXPIREAT accepted command is a UNIX timestamp (unix timestamp).

var set = await DB.Set("mykey", "hello");
var extist = await DB.Exists("mykey");
var expireat = await DB.Expireat("mykey", 1293840000);
extist = await DB.Exists("mykey");

Flushall

Empty Redis data for the entire server (all remove all key database).

This command never fails.

 await DB.Flushall();

Get

Returns the key associated with the key character or object (when not specified serialized form to be used for the case)

var get = await DB.Get<string>("nonexisting");
var set = await DB.Set("mykey", "hello");
get = await DB.Get<string>("mykey");

GetBit

Key string stored value, obtaining bits (bit) on the specified offset.

When the offset value is larger than the length of the string, or the key is not present, it returns 0

var set = await DB.SetBit("mykey", 7, true);
var get = await DB.GetBit("mykey", 0);
get = await DB.GetBit("mykey", 7);
get = await DB.GetBit("mykey", 100);

GetRange

Designated portion of the return key string stored key values, character strings taken of start and end is determined by the two offsets (including start and end included).

Negative offset indicates counted from the end of the string, -1 is the last character, -2 is the penultimate character, and so on.

var set = await DB.Set("mykey", "This is a string");
var region = await DB.GetRange("mykey", 0, 3);
region = await DB.GetRange("mykey", -3, -1);
region = await DB.GetRange("mykey", 0, -1);
region = await DB.GetRange("mykey", 10, 100);

GetSet

The value of the key key to value, and return key old key value before being set.

var set = await DB.GetSet<string>("aaa", "aaa");
set = await DB.GetSet<string>("aaa", "bbb");
var incr = await DB.Incr("mycounter");
var getset = await DB.GetSet<string>("mycounter", 0);
var get = await DB.Get<string>("mycounter");

Incr

Is a bond digital value plus a key store.

If the key key is not present, then its value will first be initialized to 0, and then execute the command INCR.

If the key value stored in the key can not be interpreted as a number, it returns an error command INCR.

This operation is limited to the value of 64-bit (bit) within the signed digital representation.

var set = await DB.Set("mykey", 10000000);
var incr = await DB.Incr("mykey");
var get = await DB.Get<string>("mykey");

Incrby

Is a bond key stored digital value plus the increment increment.

If the key key is not present, then the value of the key key will first be initialized to 0, and then execute INCRBY command.

If the key value stored in the key can not be interpreted as a number, then INCRBY command will return an error.

This operation is limited to the value of 64-bit (bit) within the signed digital representation.

For more information about the increment (increment) / decrement (decrement) operation, see INCR command documentation.

var set = await DB.Set("mykey", 10000000);
var incr = await DB.Incrby("mykey", 10);
var get = await DB.Get<string>("mykey");

IncrbyFloat

Is a bond float key stored value plus the increment increment.

Key if the key is not present, then the key value of the key will first INCRBYFLOAT set to 0, and then performs an addition operation.

If the command is successful, then the value of the key key will be updated to the implementation of the new value after the addition calculation, and the new value is returned as a string to the caller.

var set = await DB.Set("mykey", "10.5");
var incr = await DB.IncrbyFloat("mykey", 0.1f);
set = await DB.Set("mykey", "5.0e3");
incr = await DB.IncrbyFloat("mykey", 200f);

Keys

Find all match a given pattern pattern of key, for example:

KEYS * matching database of all key.

KEYS h? Llo ​​match hello, hallo and hxllo and so on.

KEYS h * llo match hllo and heeeeello and so on.

KEYS h [ae] llo and matching hello hallo, but does not match hillo.

var mset = await DB.MSet(("one", 1), ("tow", 2), ("three", 2), ("four", 4));
var keys = await DB.Keys("*o*");
keys = await DB.Keys("t??");
keys = await DB.Keys("*");

MGet

Returns the value of a given string of one or more keys.

If the given string keys inside, there are some key does not exist, then the value of this key will represent special value nil.

await DB.Flushall();
var mset = await DB.MSet(
    ("key1", "value1"),
    ("key2", "value2"),
    ("key3", "value3"));
Write(mset);
var mget = await DB.MGet<string, string, string>("key1", "key2", "key3");

mset

Setting values ​​for multiple keys.

If a given key already exists, then the MSET will use the new value to overwrite the old value, if this is not the effect you want, consider using MSETNX command, which will in all cases given key does not exist in set.

MSET is an atomic (Atomic) operation, all keys will be given at the same time provided, certain keys will not be provided, but where other key is not set.

var result = await DB.MSet(("key1", "hello"), ("key2", "world"));
var get = await DB.Get<string>("key1");
get = await DB.Get<string>("key2");

MSetNX

If and only if all of a given key does not exist, the setting value for all the given key.

Even if only a given key already exists, MSETNX command also refused to carry out operations on the set of all keys.

MSETNX is an atomic (Atomic) operation, all or a given key are provided to all, or to none at all, impossible third state.

var msetnx = await DB.MSetNX(("key1", "hello"), ("key2", "there"));
msetnx = await DB.MSetNX(("key3", "world"), ("key2", "there"));
var mget = await DB.MGet<string, string, string>("key1", "key2", "key3");

Move

The key to move the current database for a given database db them.

If the current database (source database) and a given database (the target database) with the same name given key, or key does not exist in the current database, then MOVE has no effect.

Therefore, you can take advantage of this feature, as the MOVE lock (locking) primitive (primitive).

var move = await DB.Move("one", 9);

PSetEX

This command and SETEX command similar, but it is set in milliseconds survival key is, rather than as SETEX command is set in seconds units.

var psetex = await DB.PSetEX("mykey", 1000, "hello");
var pttl = await DB.PTtl("mykey");
var get = await DB.Get<string>("mykey");

Persist

Removes the survival time of a given key, this key from the "volatile" (with a lifetime key) is converted to (time to live without a key, never expires) "durable."

var set = await DB.Set("mykey", "hello");
var expire = await DB.Expire("mykey", 10);
var ttl = await DB.Ttl("mykey");
var persist = await DB.Persist("mykey");
ttl = await DB.Ttl("mykey");

Pexpire

This effect is similar to the command and the command EXPIRE, but it is set in milliseconds key lifetime, unlike EXPIRE command as in seconds.

var set = await DB.Set("mykey", "hello");
var pexpire = await DB.Pexpire("mykey", 1500);
var ttl = await DB.Ttl("mykey");
ttl = await DB.PTtl("mykey");

Pexpireat

This command and expireat command but it is set in milliseconds key expiration timestamp unix, rather than expireat as in seconds.

var set = await DB.Set("mykey", "hello");
var pexpireat = await DB.Pexpireat("mykey", 1555555555005);
var ttl = await DB.Ttl("mykey");
var pttl = await DB.PTtl("mykey");

Ping

PING Redis server to send a client to use

var result = await DB.Ping();

Pttl

This command is similar to TTL commands, but it returned in milliseconds remaining lifetime of the key, rather than command as TTL, in seconds.

var set = await DB.Set("mykey", "hello");
var expire = await DB.Expire("mykey", 1);
var pttl = await DB.PTtl("mykey");

Publish

Send message to the specified channel channel

await DB.Publish("channel", DateTime.Now)

Randomkey

It returns a random key from the current database

await DB.Randomkey();

Rename

The key was renamed newkey.

When the newkey same key, or key does not exist, an error is returned.

var set = await DB.Set("mykey", "hello");
var ren = await DB.Rename("mykey", "myotherkey");
var get = await DB.Get<string>("myotherkey");

Renamenx

Newkey if and only if the absence of the key renamed newkey

var set = await DB.Set("mykey", "hello");
set = await DB.Set("myotherkey", "World");
var ren = await DB.Renamenx("mykey", "myotherkey");
var get = await DB.Get<string>("myotherkey");

Set

The value to the string value associated key.

If the key has been held by other values, SET will overwrite the old values, ignoring type.

When the command SET key with a time to live (TTL) is set, the TTL of the original key will be cleared.

var result = await DB.Set("test", "henryfan1");
var value = await DB.Get<string>("test");

SetBit

String stored key value, set or clear the bits (bit) on the specified offset.

Bit set or cleared depending on the parameter value may be 0 or may be one.

When the key is not present, automatically generates a new string value.

String stretching performed (grown) to ensure that it can be stored in the value specified offset. When the extended string value, empty space filled with 0.

offset must be greater than or equal to 0 and less than 2 ^ 32 (bit map is limited to the 512 MB).

var setbit = await DB.SetBit("mykey", 7, true);
var get = await DB.Get<string>("mykey");
setbit = await DB.SetBit("mykey", 7, false);
get = await DB.Get<string>("mykey");

SetEX

Set the value of the key key to value, and the key to survival key is set to seconds seconds.

If the key key already exists, SETEX command overwrites the previous value.

var setex = await DB.SetEX("mykey", 10, "hello");
var ttl = await DB.Ttl("mykey");
var get = await DB.Get<string>("mykey");

SetNX

In the case where only key does not exist in the key, the key value of the key is set to value.

If the key key already exists, SETNX command does nothing.

SETNX is "SET if Not eXists" (If not, then SET) shorthand.

var setnx = await DB.SetNX("mykey", "hello");
setnx = await DB.SetNX("mykey", "World");
var get = await DB.Get<string>("mykey");

SetRange

Starting at offset offset, the string value of the key parameter value with the stored key overwriting (overwrite).

Key key does not exist as a blank string processing.

var set = await DB.Set("key1", "hello world");
var setrange = await DB.SetRange("key1", 6, "redis");
var get = await DB.Get<string>("key1");
setrange = await DB.SetRange("key2", 6, "redis");
get = await DB.Get<string>("key2");

Strlen

Returns the string length keys stored key value.

var set = await DB.Set("key1", "hello world");
var strlen = await DB.Strlen("key1");
strlen = await DB.Strlen("nonexisting");

Type

Type of return value of the stored key.

var set = await DB.Set("key1", "hello");
set = await DB.Set("key2", "word");
var type = await DB.Type("key1");
type = await DB.Type("key2");

Object Serialization configuration

Component Default provide support three types of data objects, respectively json, protobufandmessagepack

json

Redis.Default.DataFormater = new JsonFormater();
//or
DB = new RedisDB(0, new JsonFormater());

protobuf

Redis.Default.DataFormater = new ProtobufFormater();
//or
DB = new RedisDB(0, new ProtobufFormater());

messagepack

Redis.Default.DataFormater = new MessagePackFormater();
//or
DB = new RedisDB(0, new MessagePackFormater());

All base operation unchanged, but the content will be treated according to the sequence of the target sequence of configuration types.

Get

Write(await DB.Get<Employee>("nonexisting"));
Write(await DB.Set("emp3", GetEmployee(3)));
Write(await DB.Get<Employee>("emp3"));

GetSet

Write(await DB.GetSet<Employee>("emp1", GetEmployee(1)));
Write(await DB.Set("emp1", GetEmployee(2)));
Write(await DB.Get<Employee>("emp1"));
Write(await DB.GetSet<Employee>("emp1", GetEmployee(1)));
Write(await DB.Get<Employee>("emp1"));

MGet

Write(await DB.Set("emp1", GetEmployee(1)));
Write(await DB.Set("emp2", GetEmployee(2)));
Write(await DB.MGet<Employee, Employee>("emp2", "emp1"));

mset

await DB.Flushall();
Write(await DB.MSet(
("emp1", GetEmployee(1)),
("emp2", GetEmployee(2))
));
Write(await DB.Get<Employee>("emp1"));
Write(await DB.Get<Employee>("emp2"));

MSetNX

Write(await DB.MSetNX(("key1", GetEmployee(1)), ("key2", GetEmployee(2))));
Write(await DB.MSetNX(("key2", GetEmployee(2)), ("key3", GetEmployee(3))));
var items = await DB.MGet<Employee, Employee, Employee>("key1", "key2", "key3");
Write(items.Item1);
Write(items.Item2);
Write(items.Item3);

PSetEX

Write(await DB.PSetEX("key1", 1000, GetEmployee(1)));
Write(await DB.PTtl("key1"));
Write(await DB.Get<Employee>("key1"));

Publish

for (int i = 0; i < 5; i++)
{
    Write(await DB.Publish("test1", GetEmployee(i)));
}

Set

Write(await DB.Set("key1", GetEmployee(4)));
Write(await DB.Get<Employee>("key1"));

SetEX

Write(await DB.SetEX("key1", 10, GetEmployee(1)));
Write(await DB.Ttl("key1"));
Write(await DB.Get<Employee>("key1"));

SetNX

Write(await DB.SetNX("key1", GetEmployee(1)));
Write(await DB.SetNX("key1", GetEmployee(2)));
Write(await DB.Get<Employee>("key1"));
Released 1535 original articles · won praise 586 · Views 2.37 million +

Guess you like

Origin blog.csdn.net/sD7O95O/article/details/104057718