Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/my-mail-ru/swift-OctopusBox
Client for Octopus/box in-memory key/value storage
https://github.com/my-mail-ru/swift-OctopusBox
Last synced: 6 days ago
JSON representation
Client for Octopus/box in-memory key/value storage
- Host: GitHub
- URL: https://github.com/my-mail-ru/swift-OctopusBox
- Owner: my-mail-ru
- License: mit
- Created: 2016-09-13T17:48:58.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-08T16:39:42.000Z (almost 7 years ago)
- Last Synced: 2024-08-02T00:22:26.078Z (4 months ago)
- Language: Swift
- Size: 25.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- Awesome-Swift-Packages - swift-OctopusBox - Client for Octopus/box in-memory key/value storage. (Storage)
README
# OctopusBox
![Swift: 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg)
![OS: Linux](https://img.shields.io/badge/OS-Linux-brightgreen.svg)
![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)This package contains client for
[Octopus/box](https://github.com/delamonpansie/octopus/tree/mod_box)
in-memory key/value storage.
The client implements active record pattern and supports
automagical encoding/decoding of tuples into structs using
reflection.## Usage
```swift
import IProto
import OctopusBoxfinal class MyData : MutableRecord {
static let cluster = Cluster(shards: [Shard(masters: [Server(host: "127.0.0.1", port: 33700)])])
static let namespace = 42typealias PrimaryKey = Int32
static let primaryKey = Tuple.uniqIndex(0) { $0.id }struct Tuple : TupleProtocol {
var id: Int32 = 0
var one: UInt32 = 0
var two: UInt8 = 0
var name: String = ""
var raw = BinaryEncodedData()
var quad: UInt64 = 0
}var tuple: Tuple
var storageInfo: StorageInfo?init(tuple: Tuple, storageInfo: StorageInfo) {
self.tuple = tuple
self.storageInfo = storageInfo
}static func select(id: Int32) throws -> MyData? {
return try select(index: primaryKey, key: id)
}static func select(id: [Int32]) throws -> [MyData] {
return try select(index: primaryKey, keys: id)
}
}func test() throws {
var data = MyData(id: 100500, name: "Василий")
try data.insert()data = try MyData.select(id: 100500)
try data.update([data.tuple.field(&data.tuple.quad).set(10)])
try data.delete()
}
```See [tests](Tests/OctopusBoxTests/OctopusBoxTests.swift)
for more information about provided API.